Skip to content
Draft
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions res/gamedata/shaders/gl/deffer_detail_s_flat.vs
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
#include "common.h"
#include "iostructs\v_detail.h"

uniform float4 consts; // {1/quant,1/quant,diffusescale,ambient}
//uniform float4 array [200] : register(c12);
//tbuffer DetailsData
//{
uniform float4 array[61*4];
//}
layout(std140) uniform EnvironmentDetailUBO {
mat4 xform;
mat4 formView;
vec4 consts;
vec4 scale;
vec4 bias;
vec4 wind;
vec4 wave;
vec3 sun;
};

uniform float4 array[61*4];

v2p_flat _main (v_detail v)
{
v2p_flat O;
// index
int i = int(v.misc.w);
int i = gl_InstanceID*4;
float4 m0 = array[i+0];
float4 m1 = array[i+1];
float4 m2 = array[i+2];
Expand Down
24 changes: 14 additions & 10 deletions res/gamedata/shaders/gl/deffer_detail_w_flat.vs
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
#include "common.h"
#include "iostructs\v_detail.h"

uniform float4 consts; // {1/quant,1/quant,diffusescale,ambient}
uniform float4 wave; // cx,cy,cz,tm
uniform float4 dir2D;
//uniform float4 array [200] : register(c12);
//tbuffer DetailsData
//{
uniform float4 array[61*4];
//}
layout(std140) uniform EnvironmentDetailUBO {
mat4 xform;
mat4 formView;
vec4 consts;
vec4 scale;
vec4 bias;
vec4 wind;
vec4 wave;
vec3 sun;
};

uniform float4 array[61*4];

v2p_flat _main (v_detail v)
{
v2p_flat O;
// index
int i = int(v.misc.w);
int i = gl_InstanceID*4;
float4 m0 = array[i+0];
float4 m1 = array[i+1];
float4 m2 = array[i+2];
Expand All @@ -33,7 +37,7 @@ v2p_flat _main (v_detail v)
float H = pos.y - base; // height of vertex (scaled)
float frac = v.misc.z*consts.x; // fractional
float inten = H * dp;
float2 result = calc_xz_wave (dir2D.xz*inten,frac);
float2 result = calc_xz_wave (wind.xz*inten,frac);
pos = float4(pos.x+result.x, pos.y, pos.z+result.y, 1);

// Normal in world coords
Expand Down
39 changes: 36 additions & 3 deletions src/Layers/xrRender/DetailManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,38 @@ extern float dm_current_fade;// = float(2*dm_current_size)-.5f;
extern float ps_current_detail_density;
extern float ps_current_detail_height;

#ifdef USE_OGL
#pragma pack(push, 1)
struct EnvironmentDetailData
{
glm::mat4x4 xform;
glm::mat4x4 xformView;
glm::vec4 consts;
glm::vec4 scale;
glm::vec4 bias;
glm::vec4 wind;
glm::vec4 wave;
glm::vec3 sun;

private:
[[maybe_unused]]
glm::vec1 _glsl_140_padding {};
// 224 bytes
};
#pragma pack(pop)
#endif

class ECORE_API CDetailManager
{
public:
#ifdef USE_OGL
EnvironmentDetailData environmentDetailData[3];

UniformBufferObject uniformBufferObject = {
GL_NONE, GL_DYNAMIC_DRAW, sizeof(EnvironmentDetailData)*3
};
#endif

struct SlotItem
{ // один кустик
float scale;
Expand All @@ -70,9 +99,9 @@ class ECORE_API CDetailManager

struct SlotPart
{ //
u32 id; // ID модельки
SlotItemVec items; // список кустиков
SlotItemVec r_items[3]; // список кустиков for render
u32 id; // ID models
SlotItemVec items; // list of bushes
SlotItemVec r_items[3]; // list of bushes for render
};

enum SlotType : u32
Expand Down Expand Up @@ -197,7 +226,11 @@ class ECORE_API CDetailManager
void hw_Load_Shaders();
void hw_Unload();
void hw_Render(CBackend& cmd_list);
#ifdef USE_OGL
void hw_Render_dump(CBackend& cmd_list, u32 var_id, u32 lod_id);
#else
void hw_Render_dump(CBackend& cmd_list, const Fvector4& consts, const Fvector4& wave, const Fvector4& wind, u32 var_id, u32 lod_id);
#endif

// get unpacked slot
DetailSlot& QueryDB(int sx, int sz);
Expand Down
8 changes: 7 additions & 1 deletion src/Layers/xrRender/R_Backend.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
#include "Layers/xrRenderDX11/StateManager/dx11ShaderResourceStateCache.h"
#include "Layers/xrRenderDX11/StateManager/dx11StateCache.h"
#endif
#ifdef USE_OGL
#include <glm/glm.hpp>
#include "gl_backend_uniforms.h"
#endif

#include "FVF.h"

Expand Down Expand Up @@ -60,6 +64,9 @@ struct R_statistics
#pragma warning(push)
#pragma warning(disable:4324)
class ECORE_API CBackend
#ifdef USE_OGL
: public CBackendUniforms
#endif
{
public:
enum
Expand Down Expand Up @@ -103,7 +110,6 @@ class ECORE_API CBackend
#else
# error No graphics API selected or enabled!
#endif

// Vertices/Indices/etc
SDeclaration* decl;
VertexBufferHandle vb;
Expand Down
4 changes: 4 additions & 0 deletions src/Layers/xrRender/R_Backend_Runtime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,10 @@ void CBackend::OnDeviceCreate()

// invalidate caching
Invalidate();

#ifdef USE_OGL
initializeUniforms();
#endif
}

void CBackend::OnDeviceDestroy()
Expand Down
1 change: 1 addition & 0 deletions src/Layers/xrRender/SH_Atomic.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ struct ECORE_API SVS : public xr_resource_named
ID3DVertexShader* sh;
#elif defined(USE_OGL)
GLuint sh;
uint32_t bindingSlots = 0;
#else
# error No graphics API selected or enabled!
#endif
Expand Down
14 changes: 14 additions & 0 deletions src/Layers/xrRender/SkeletonX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,16 +73,30 @@ void CSkeletonX::_Render(CBackend& cmd_list, ref_geom& hGeom, u32 vCount, u32 iO
// transfer matrices
ref_constant array = cmd_list.get_c(s_bones_array_const);
u32 count = RMS_bonecount;
#ifdef USE_OGL
xr_vector<glm::vec4> uniformBuffer;
uniformBuffer.reserve(count*3);
#endif

for (u32 mid = 0; mid < count; mid++)
{
Fmatrix& M = Parent->LL_GetTransform_R(u16(mid));
#ifdef USE_OGL
uniformBuffer.emplace_back(M._11, M._21, M._31, M._41);
uniformBuffer.emplace_back(M._12, M._22, M._32, M._42);
uniformBuffer.emplace_back(M._13, M._23, M._33, M._43);
#else
u32 id = mid * 3;
cmd_list.set_ca(&*array, id + 0, M._11, M._21, M._31, M._41);
cmd_list.set_ca(&*array, id + 1, M._12, M._22, M._32, M._42);
cmd_list.set_ca(&*array, id + 2, M._13, M._23, M._33, M._43);
#endif
}

// render
#ifdef USE_OGL
cmd_list.set_uniforms(array->vs.program, array->vs.location, uniformBuffer);
#endif
cmd_list.set_Geometry(hGeom);
cmd_list.Render(D3DPT_TRIANGLELIST, 0, 0, vCount, iOffset, pCount);
if (RM_SKINNING_1B == RenderMode || RM_SKINNING_1B_HQ == RenderMode)
Expand Down
Loading
Loading