Skip to content
Draft
Show file tree
Hide file tree
Changes from all 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
11 changes: 4 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,15 @@
#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];
//}
#include "shared\ubo_render_dump.h"

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
15 changes: 5 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,15 @@
#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];
//}
#include "shared\ubo_render_dump.h"

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 +28,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
15 changes: 15 additions & 0 deletions res/gamedata/shaders/gl/shared/ubo_render_dump.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#ifndef OPENXRAY_UBO_RENDER_DUMP_H
#define OPENXRAY_UBO_RENDER_DUMP_H

layout(std140) uniform RenderDumpUBO {
float4x4 xform;
float4x4 formView;
float4 consts;
float4 scale;
float4 bias;
float4 wind;
float4 wave;
float4 sun;
};

#endif
25 changes: 21 additions & 4 deletions src/Layers/xrRender/DetailManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,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 @@ -185,19 +185,25 @@ class ECORE_API CDetailManager
VertexStagingBuffer hw_VB;
IndexStagingBuffer hw_IB;

#ifndef USE_OGL
ref_constant hwc_consts;
ref_constant hwc_wave;
ref_constant hwc_wind;
ref_constant hwc_array;
ref_constant hwc_s_consts;
ref_constant hwc_s_xform;
#endif
ref_constant hwc_array;
ref_constant hwc_s_array;
void hw_Load();
void hw_Load_Geom();
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 Expand Up @@ -225,5 +231,16 @@ class ECORE_API CDetailManager

CDetailManager();
virtual ~CDetailManager();

#ifdef USE_OGL
private:
// TODO move to global registry ?
GLuint renderDumpBlockBinding = 3;
ShaderInstanceData renderDumpData[3];

UniformBufferObject renderDumpUBO = {
BUFFER_DEBUG_NAME("DetailManagerUBO") GL_NONE, GL_DYNAMIC_DRAW, sizeof(ShaderInstanceData)*3
};
#endif
};
} // namespace xray::render::RENDER_NAMESPACE
9 changes: 8 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_extension.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 CBackendExtension
#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 Expand Up @@ -404,6 +410,7 @@ class ECORE_API CBackend
public:
#if defined(USE_OGL)
ICF bool is_TessEnabled() { return false; }
void RenderInstanced(D3DPRIMITIVETYPE T, u32 baseV, u32 startV, u32 countV, u32 startI, u32 PC, GLsizei instanceCount);
#elif defined(USE_DX11)
ICF bool is_TessEnabled();
#else
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.setUniforms(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