Skip to content

Commit

Permalink
* UPD: [xrEngine/xrGame/xrCore/xrRender] Update SSS 17.1 -> 21
Browse files Browse the repository at this point in the history
  • Loading branch information
yohjimane committed Aug 30, 2024
1 parent 34f7e49 commit 666f36c
Show file tree
Hide file tree
Showing 48 changed files with 2,253 additions and 102 deletions.
188 changes: 188 additions & 0 deletions src/Layers/xrRender/Blender_Recorder_StandartBinding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,24 @@ extern ENGINE_API Fvector4 ps_ssfx_wetsurfaces_2;
extern ENGINE_API int ps_ssfx_is_underground;
extern ENGINE_API Fvector4 ps_ssfx_lightsetup_1;

extern ENGINE_API float ps_ssfx_hud_hemi;
extern ENGINE_API Fvector4 ps_ssfx_il;
extern ENGINE_API Fvector4 ps_ssfx_il_setup1;
extern ENGINE_API Fvector4 ps_ssfx_ao;
extern ENGINE_API Fvector4 ps_ssfx_ao_setup1;
extern ENGINE_API Fvector4 ps_ssfx_water;
extern ENGINE_API Fvector4 ps_ssfx_water_setup1;
extern ENGINE_API Fvector4 ps_ssfx_water_setup2;

extern ENGINE_API Fvector4 ps_ssfx_volumetric;
extern ENGINE_API Fvector4 ps_ssfx_ssr_2;
extern ENGINE_API Fvector4 ps_ssfx_terrain_offset;

extern ENGINE_API Fvector3 ps_ssfx_shadow_bias;
extern ENGINE_API Fvector4 ps_ssfx_lut;
extern ENGINE_API Fvector4 ps_ssfx_wind_grass;
extern ENGINE_API Fvector4 ps_ssfx_wind_trees;

class cl_inv_v : public R_constant_setup
{
Fmatrix result;
Expand Down Expand Up @@ -617,6 +635,159 @@ class ssfx_florafixes_2 : public R_constant_setup
};
static ssfx_florafixes_2 binder_ssfx_florafixes_2;

class ssfx_wind_grass : public R_constant_setup
{
void setup(CBackend& cmd_list, R_constant* C) override
{
cmd_list.set_c(C, ps_ssfx_wind_grass);
}
};
static ssfx_wind_grass binder_ssfx_wind_grass;

class ssfx_wind_trees : public R_constant_setup
{
void setup(CBackend& cmd_list, R_constant* C) override
{
cmd_list.set_c(C, ps_ssfx_wind_trees);
}
};
static ssfx_wind_trees binder_ssfx_wind_trees;

class ssfx_wind_anim : public R_constant_setup
{
void setup(CBackend& cmd_list, R_constant* C) override
{
cmd_list.set_c(C, g_pGamePersistent->Environment().wind_anim);
}
};
static ssfx_wind_anim binder_ssfx_wind_anim;

class ssfx_lut : public R_constant_setup
{
void setup(CBackend& cmd_list, R_constant* C) override
{
cmd_list.set_c(C, ps_ssfx_lut);
}
};
static ssfx_lut binder_ssfx_lut;

class ssfx_shadow_bias : public R_constant_setup
{
void setup(CBackend& cmd_list, R_constant* C) override
{
cmd_list.set_c(C, ps_ssfx_shadow_bias.x, ps_ssfx_shadow_bias.y, 0.f, 0.f);
}
};
static ssfx_shadow_bias binder_ssfx_shadow_bias;

class ssfx_terrain_offset : public R_constant_setup
{
void setup(CBackend& cmd_list, R_constant* C) override
{
cmd_list.set_c(C, ps_ssfx_terrain_offset);
}
};
static ssfx_terrain_offset binder_ssfx_terrain_offset;

class ssfx_ssr_2 : public R_constant_setup
{
void setup(CBackend& cmd_list, R_constant* C) override
{
cmd_list.set_c(C, ps_ssfx_ssr_2);
}
};
static ssfx_ssr_2 binder_ssfx_ssr_2;

class ssfx_volumetric : public R_constant_setup
{
void setup(CBackend& cmd_list, R_constant* C) override
{
cmd_list.set_c(C, ps_ssfx_volumetric);
}
};
static ssfx_volumetric binder_ssfx_volumetric;

class ssfx_water : public R_constant_setup
{
void setup(CBackend& cmd_list, R_constant* C) override
{
cmd_list.set_c(C, ps_ssfx_water);
}
};
static ssfx_water binder_ssfx_water;

class ssfx_water_setup1 : public R_constant_setup
{
void setup(CBackend& cmd_list, R_constant* C) override
{
cmd_list.set_c(C, ps_ssfx_water_setup1);
}
};
static ssfx_water_setup1 binder_ssfx_water_setup1;

class ssfx_water_setup2 : public R_constant_setup
{
void setup(CBackend& cmd_list, R_constant* C) override
{
cmd_list.set_c(C, ps_ssfx_water_setup2);
}
};
static ssfx_water_setup2 binder_ssfx_water_setup2;

class ssfx_ao : public R_constant_setup
{
void setup(CBackend& cmd_list, R_constant* C) override
{
cmd_list.set_c(C, ps_ssfx_ao);
}
};
static ssfx_ao binder_ssfx_ao;

class ssfx_ao_setup1 : public R_constant_setup
{
void setup(CBackend& cmd_list, R_constant* C) override
{
cmd_list.set_c(C, ps_ssfx_ao_setup1);
}
};
static ssfx_ao_setup1 binder_ssfx_ao_setup1;

class ssfx_il : public R_constant_setup
{
void setup(CBackend& cmd_list, R_constant* C) override
{
cmd_list.set_c(C, ps_ssfx_il);
}
};
static ssfx_il binder_ssfx_il;

class ssfx_il_setup1 : public R_constant_setup
{
void setup(CBackend& cmd_list, R_constant* C) override
{
cmd_list.set_c(C, ps_ssfx_il_setup1);
}
};
static ssfx_il_setup1 binder_ssfx_il_setup1;

class ssfx_hud_hemi : public R_constant_setup
{
void setup(CBackend& cmd_list, R_constant* C) override
{
cmd_list.set_c(C, ps_ssfx_hud_hemi, 0.f, 0.f, 0.f);
}
};
static ssfx_hud_hemi binder_ssfx_hud_hemi;

class ssfx_issvp : public R_constant_setup
{
void setup(CBackend& cmd_list, R_constant* C) override
{
cmd_list.set_c(C, Device.m_SecondViewport.IsSVPFrame() ? 1.f : 0.f, 0.f, 0.f, 0.f);
}
};
static ssfx_issvp binder_ssfx_issvp;

// Standart constant-binding
void CBlender_Compile::SetMapping()
{
Expand Down Expand Up @@ -726,4 +897,21 @@ void CBlender_Compile::SetMapping()
r_Constant("ssfx_gloss", &binder_ssfx_gloss);
r_Constant("ssfx_florafixes_1", &binder_ssfx_florafixes_1);
r_Constant("ssfx_florafixes_2", &binder_ssfx_florafixes_2);
r_Constant("ssfx_issvp", &binder_ssfx_issvp);
r_Constant("ssfx_hud_hemi", &binder_ssfx_hud_hemi);
r_Constant("ssfx_il_setup", &binder_ssfx_il);
r_Constant("ssfx_il_setup2", &binder_ssfx_il_setup1);
r_Constant("ssfx_ao_setup", &binder_ssfx_ao);
r_Constant("ssfx_ao_setup2", &binder_ssfx_ao_setup1);
r_Constant("ssfx_water", &binder_ssfx_water);
r_Constant("ssfx_water_setup1", &binder_ssfx_water_setup1);
r_Constant("ssfx_water_setup2", &binder_ssfx_water_setup2);
r_Constant("ssfx_volumetric", &binder_ssfx_volumetric);
r_Constant("ssfx_ssr_2", &binder_ssfx_ssr_2);
r_Constant("ssfx_terrain_offset", &binder_ssfx_terrain_offset);
r_Constant("ssfx_shadow_bias", &binder_ssfx_shadow_bias);
r_Constant("ssfx_wind_anim", &binder_ssfx_wind_anim);
r_Constant("ssfx_wsetup_grass", &binder_ssfx_wind_grass);
r_Constant("ssfx_wsetup_trees", &binder_ssfx_wind_trees);
r_Constant("ssfx_lut", &binder_ssfx_lut);
}
26 changes: 16 additions & 10 deletions src/Layers/xrRender/Light_Render_Direct_ComputeXFS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,9 @@ void CLight_Compute_XFORM_and_VIS::compute_xf_spot(light* L)
float intensity1 = (L->color.r * 0.2125f + L->color.g * 0.7154f + L->color.b * 0.0721f);
float intensity = (intensity0 + intensity1) / 2.f; // intensity1 tends to underestimate...

// [SSS 19] Improve this code later?
// compute how much duelling frusta occurs [-1..1]-> 1 + [-0.5 .. +0.5]
float duel_dot = 1.f - 0.5f * Device.vCameraDirection.dotproduct(L_dir);
//float duel_dot = 1.f - 0.5f * Device.vCameraDirection.dotproduct(L_dir);

// compute how large the light is - give more texels to larger lights, assume 8m as being optimal radius
float sizefactor = L->range / 8.f; // 4m = .5, 8m=1.f, 16m=2.f, 32m=4.f
Expand All @@ -63,17 +64,20 @@ void CLight_Compute_XFORM_and_VIS::compute_xf_spot(light* L)
// factors
float factor0 = powf(ssa, 1.f / 2.f); // ssa is quadratic
float factor1 = powf(intensity, 1.f / 16.f); // less perceptually important?
float factor2 = powf(duel_dot, 1.f / 4.f); // difficult to fast-change this -> visible
//float factor2 = powf(duel_dot, 1.f / 4.f); // difficult to fast-change this -> visible
float factor3 = powf(sizefactor, 1.f / 4.f); // this shouldn't make much difference
float factor4 = powf(widefactor, 1.f / 2.f); // make it linear ???
float factor = ps_r2_ls_squality * factor0 * factor1 * factor2 * factor3 * factor4;
//float factor = ps_r2_ls_squality * factor0 * factor1 * factor2 * factor3 * factor4;
float factor = ps_r2_ls_squality * factor0 * factor1 * factor3 * factor4;

// final size calc
extern ENGINE_API Fvector3 ps_ssfx_shadows;
u32 max_size = (u32)(RImplementation.o.smapsize <= ps_ssfx_shadows.y ? RImplementation.o.smapsize : ps_ssfx_shadows.y);
u32 _size = iFloor(factor * SMAP_adapt_optimal);
if (_size < SMAP_adapt_min)
_size = SMAP_adapt_min;
if (_size > SMAP_adapt_max)
_size = SMAP_adapt_max;
if (_size < ps_ssfx_shadows.x)
_size = (u32)ps_ssfx_shadows.x;
if (_size > max_size)
_size = max_size;
int _epsilon = iCeil(float(_size) * 0.01f);
int _diff = _abs(int(_size) - int(_cached_size));
L->X.S.size = (_diff >= _epsilon) ? _size : _cached_size;
Expand All @@ -91,10 +95,12 @@ void CLight_Compute_XFORM_and_VIS::compute_xf_spot(light* L)
// _min(L->cone + deg2rad(4.5f), PI*0.98f) - Here, it is needed to enlarge the shadow map frustum to include also
// displaced pixels and the pixels neighbor to the examining one.
float tan_shift;
if (L->flags.type == IRender_Light::POINT)
tan_shift = deg2rad(11.5f);
if (L->flags.type == IRender_Light::OMNIPART) // [ SSS ] 0.3f fix almost all frustum problems... 0.5f was the old value ( SSS 19 ) but was causing issues?
tan_shift = 0.3f;
else if (L->flags.type == IRender_Light::POINT)
tan_shift = 0.2007129f; // deg2rad(11.5f);
else
tan_shift = deg2rad(3.5f);
tan_shift = 0.0610865f; //deg2rad(3.5f);

L->X.S.project.build_projection(L->cone + tan_shift, 1.f, L->virtual_size, L->range + EPS_S);
L->X.S.combine.mul(L->X.S.project, L->X.S.view);
Expand Down
7 changes: 7 additions & 0 deletions src/Layers/xrRender/ResourceManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,13 @@ Shader* CResourceManager::_cpp_Create(
S.E[5] = _CreateElement(std::move(E));
}

// Hacky way to remove from the HUD mask transparent stuff. ( Let's try something better later... )
if (GEnv.Render->hud_loading)
{
if (strstr(s_shader, "lens"))
S.E[0]->passes[0]->ps->hud_disabled = TRUE;
}

// Search equal in shaders array
for (u32 it = 0; it < v_shaders.size(); it++)
if (S.equal(v_shaders[it]))
Expand Down
4 changes: 4 additions & 0 deletions src/Layers/xrRender/Shader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ ShaderElement::ShaderElement()
flags.bEmissive = FALSE;
flags.bDistort = FALSE;
flags.bWmark = FALSE;

// SSS Custom rendering
flags.isLandscape = FALSE;
flags.isWater = FALSE;
}

BOOL ShaderElement::equal(ShaderElement& S)
Expand Down
2 changes: 2 additions & 0 deletions src/Layers/xrRender/Shader.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@ struct ECORE_API ShaderElement : public xr_resource_flagged
u32 bEmissive : 1;
u32 bDistort : 1;
u32 bWmark : 1;
u32 isLandscape : 1;
u32 isWater : 1;
};

Sflags flags;
Expand Down
1 change: 1 addition & 0 deletions src/Layers/xrRender/SkeletonCustom.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ class CKinematics : public FHierrarhyVisual, public IKinematics
protected:
SkeletonWMVec wallmarks;
u32 wm_frame;
u32 CurrentFrame;

xr_vector<dxRender_Visual*> children_invisible;

Expand Down
47 changes: 46 additions & 1 deletion src/Layers/xrRender/SkeletonX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "xrCore/FMesh.hpp"

shared_str s_bones_array_const;
shared_str s_bones_array_prev_const;

//////////////////////////////////////////////////////////////////////
// Body Part
Expand Down Expand Up @@ -40,6 +41,33 @@ void CSkeletonX::_Copy(CSkeletonX* B)
//////////////////////////////////////////////////////////////////////
void CSkeletonX::_Render(CBackend& cmd_list, ref_geom& hGeom, u32 vCount, u32 iOffset, u32 pCount)
{
bool CalcVelocity = false;

#ifdef USE_DX11

CalcVelocity = RImplementation.Target->RVelocity;

if (CalcVelocity)
{
// Previous WVP
RCache.set_c("m_WVP_prev", RImplementation.Target->Matrix_HUD_previous);

if (RenderMode > 1 && Device.dwFrame > Parent->CurrentFrame)
{
Parent->CurrentFrame = Device.dwFrame;

// Save bone matrix to use next frame
for (u16 b = 0; b < Parent->LL_BoneCount(); b++)
{
CBoneInstance& Bone = Parent->LL_GetBoneInstance(b);
Bone.mRenderTransform_prev.set(Bone.mRenderTransform_temp);
Bone.mRenderTransform_temp.set(Bone.mRenderTransform);
}
}
}

#endif

cmd_list.stat.r.s_dynamic.add(vCount);
switch (RenderMode)
{
Expand All @@ -53,6 +81,11 @@ void CSkeletonX::_Render(CBackend& cmd_list, ref_geom& hGeom, u32 vCount, u32 iO
Fmatrix W;
W.mul_43(cmd_list.xforms.m_w, Parent->LL_GetTransform_R(u16(RMS_boneid)));
cmd_list.set_xform_world(W);

// Add the bone transform
if (CalcVelocity)
RCache.set_c("m_bone", Parent->LL_GetTransform_R(u16(RMS_boneid)));

cmd_list.set_Geometry(hGeom);
cmd_list.Render(D3DPT_TRIANGLELIST, 0, 0, vCount, iOffset, pCount);
cmd_list.stat.r.s_dynamic_inst.add(vCount);
Expand All @@ -67,8 +100,10 @@ void CSkeletonX::_Render(CBackend& cmd_list, ref_geom& hGeom, u32 vCount, u32 iO
case RM_SKINNING_4B:
case RM_SKINNING_4B_HQ:
{
// transfer matrices
// transfer matrices ( current and previous )
ref_constant array = cmd_list.get_c(s_bones_array_const);
ref_constant array_prev = cmd_list.get_c(s_bones_array_prev_const);

u32 count = RMS_bonecount;
for (u32 mid = 0; mid < count; mid++)
{
Expand All @@ -77,6 +112,15 @@ void CSkeletonX::_Render(CBackend& cmd_list, ref_geom& hGeom, u32 vCount, u32 iO
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);

if (CalcVelocity)
{
// Previus transform
Fmatrix& Mprev = Parent->LL_GetBoneInstance(u16(mid)).mRenderTransform_prev;
cmd_list.set_ca(&*array_prev, id + 0, Mprev._11, Mprev._21, Mprev._31, Mprev._41);
cmd_list.set_ca(&*array_prev, id + 1, Mprev._12, Mprev._22, Mprev._32, Mprev._42);
cmd_list.set_ca(&*array_prev, id + 2, Mprev._13, Mprev._23, Mprev._33, Mprev._43);
}
}

// render
Expand Down Expand Up @@ -153,6 +197,7 @@ void CSkeletonX::_Render_soft(CBackend& cmd_list, ref_geom& hGeom, u32 vCount, u
void CSkeletonX::_Load(const char* N, IReader* data, u32& dwVertCount)
{
s_bones_array_const = "sbones_array";
s_bones_array_prev_const = "sbones_array_prev";
xr_vector<u16> bids;

// Load vertices
Expand Down
Loading

0 comments on commit 666f36c

Please sign in to comment.