Skip to content

Commit

Permalink
Updated to work with ascii's shaders/engine edits
Browse files Browse the repository at this point in the history
  • Loading branch information
yohjimane committed Dec 5, 2023
1 parent b528f83 commit d5677c2
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 1 deletion.
26 changes: 25 additions & 1 deletion res/gamedata/shaders/r5/deffer_grass.vs
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,41 @@ float4 benders_setup;
float4 consts; // {1/quant,1/quant,diffusescale,ambient}
float4 wave; // cx,cy,cz,tm
float4 dir2D;
float4 array[61*4];
#if INSTANCED_DETAILS
Texture1D<float4> array;
#else
//tbuffer DetailsData
//{
uniform float4 array[61*4];
//}
#endif

#if INSTANCED_DETAILS
v2p_bumped main (v_detail v, uint instance_id : SV_InstanceID)
#else
v2p_bumped main (v_detail v)
#endif
{
v2p_bumped O;
// index

#if INSTANCED_DETAILS
int i = instance_id * 2;

float4 a0 = array.Load(int2(i, 0), 0);
float4 a1 = array.Load(int2(i, 0), 1);

float4 m0 = float4(a0.y, 0, -a0.x, a1.x);
float4 m1 = float4( 0, a1.w, 0, a1.y);
float4 m2 = float4(a0.x, 0, a0.y, a1.z);
float4 c0 = a0.zzzw;
#else
int i = v.misc.w;
float4 m0 = array[i+0];
float4 m1 = array[i+1];
float4 m2 = array[i+2];
float4 c0 = array[i+3];
#endif

// Transform pos to world coords
float4 pos;
Expand Down
1 change: 1 addition & 0 deletions res/gamedata/shaders/r5/details_blend.s
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ function normal (shader, t_base, t_second, t_detail)
shader:dx10texture("s_base", t_base)
shader:dx10texture("s_bump", "levels\\" .. opt:getLevel() .. "\\" .. t_base.."_bump")
shader:dx10texture("s_bumpX", t_base.."_bump#")
shader:dx10texture("array", "$details$array")

shader:dx10sampler("smp_base")
end
1 change: 1 addition & 0 deletions src/Layers/xrRender/xrRender_console.h
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ enum
R_FLAGEXT_LIGHT_DETAILS = (1 << 12), // include grass in local lights shadowmaps
R_FLAGEXT_INSTANCED_DETAILS = (1 << 13), // instanced details draw
R_FLAGEXT_LINEAR_GRASS_FILTER = (1 << 14), // force disable anisotropy for grass filtering
R4FLAGEXT_NEW_SHADER_SUPPORT = (1 << 15),
};

extern void xrRender_initconsole();
Expand Down
41 changes: 41 additions & 0 deletions src/Layers/xrRenderDX11/dx11DetailManager_VS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,23 @@ void CDetailManager::draw_instances(
c_ambient.set(desc.ambient.x, desc.ambient.y, desc.ambient.z);
c_hemi.set(desc.hemi_color.x, desc.hemi_color.y, desc.hemi_color.z);

static shared_str strConsts("consts");
static shared_str strWave("wave");
static shared_str strDir2D("dir2D");
static shared_str strArray("array");
static shared_str strXForm("xform");
static shared_str strPos("benders_pos");
static shared_str strGrassSetup("benders_setup");

// Grass benders data
IGame_Persistent::grass_data& GData = g_pGamePersistent->grass_shader_data;
Fvector4 player_pos = { 0, 0, 0, 0 };
int BendersQty = _min(16, (int)(ps_ssfx_grass_interactive.y + 1));

// Add Player?
if (ps_ssfx_grass_interactive.x > 0)
player_pos.set(Device.vCameraPosition.x, Device.vCameraPosition.y, Device.vCameraPosition.z, -1);

// Iterate
for (u32 O = 0; O < objects.size(); O++)
{
Expand All @@ -365,6 +382,30 @@ void CDetailManager::draw_instances(
cmd_list.set_c(strDir2D, wind);
cmd_list.set_c(strXForm, Device.mFullTransform);

if (ps_ssfx_grass_interactive.y > 0)
{
cmd_list.set_c(strGrassSetup, ps_ssfx_int_grass_params_1);

Fvector4* c_grass{};
{
void* GrassData;
cmd_list.get_ConstantDirect(strPos, BendersQty * sizeof(Fvector4), &GrassData, 0, 0);
c_grass = (Fvector4*)GrassData;
}

if (c_grass)
{
c_grass[0].set(player_pos);
c_grass[16].set(0.0f, -99.0f, 0.0f, 1.0f);

for (int Bend = 1; Bend < BendersQty; Bend++)
{
c_grass[Bend].set(GData.pos[Bend].x, GData.pos[Bend].y, GData.pos[Bend].z, GData.radius_curr[Bend]);
c_grass[Bend + 16].set(GData.dir[Bend].x, GData.dir[Bend].y, GData.dir[Bend].z, GData.str[Bend]);
}
}
}

Fvector4* c_storage = upload_buffer[cmd_list.context_id];

u32 dwBatch = 0;
Expand Down

0 comments on commit d5677c2

Please sign in to comment.