Skip to content

Commit

Permalink
Detail objects are now affected by fog.
Browse files Browse the repository at this point in the history
  • Loading branch information
RainbowZerg committed Jun 27, 2018
1 parent 683e54c commit 8e0176b
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 28 deletions.
20 changes: 12 additions & 8 deletions res/gamedata/shaders/r1/detail_still.vs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ struct vf
float4 hpos : POSITION;
float4 C : COLOR0;
float2 tc : TEXCOORD0;
float fog : FOG;
};

uniform float4 consts; // {1/quant,1/quant,diffusescale,ambient}
uniform float4 array [200] : register(c10);
uniform float4 consts; // {1/quant,1/quant,diffusescale,ambient}
uniform float4 array[200] : register(c10);

vf main (v_detail v)
{
Expand All @@ -22,15 +23,18 @@ vf main (v_detail v)
float4 c0 = array[i+3];

// Transform to world coords
float4 pos;
pos.x = dot (m0, v.pos);
pos.y = dot (m1, v.pos);
pos.z = dot (m2, v.pos);
float4 pos;
pos.x = dot(m0, v.pos);
pos.y = dot(m1, v.pos);
pos.z = dot(m2, v.pos);
pos.w = 1;

// Calc fog
o.fog = calc_fogging(pos);

// Final out
o.hpos = mul (m_WVP,pos);
o.C = c0;
o.hpos = mul(m_WVP,pos);
o.C = c0;
o.tc.xy = (v.misc * consts).xy;

return o;
Expand Down
40 changes: 22 additions & 18 deletions res/gamedata/shaders/r1/detail_wave.vs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@ struct vf
float4 hpos : POSITION;
float4 C : COLOR0;
float2 tc : TEXCOORD0;
float fog : FOG;
};

uniform float4 consts; // {1/quant,1/quant,diffusescale,ambient}
uniform float4 wave; // cx,cy,cz,tm
uniform float4 dir2D;
uniform float4 array [200] : register(c10);
uniform float4 consts; // {1/quant,1/quant,diffusescale,ambient}
uniform float4 wave; // cx,cy,cz,tm
uniform float4 dir2D;
uniform float4 array[200] : register(c10);

vf main (v_detail v)
{
Expand All @@ -25,27 +26,30 @@ vf main (v_detail v)

// Transform to world coords
float4 pos;
pos.x = dot (m0, v.pos);
pos.y = dot (m1, v.pos);
pos.z = dot (m2, v.pos);
pos.x = dot(m0, v.pos);
pos.y = dot(m1, v.pos);
pos.z = dot(m2, v.pos);
pos.w = 1;

//
float base = m1.w;
float dp = calc_cyclic (dot(pos,wave));
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);
pos = float4(pos.x+result.x, pos.y, pos.z+result.y, 1);
o.hpos = mul (m_WVP,pos);
float base = m1.w;
float dp = calc_cyclic(dot(pos,wave));
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);
pos = float4(pos.x+result.x, pos.y, pos.z+result.y, 1);

// Calc fog
o.fog = calc_fogging(pos);

// Fake lighting
float dpc = max (0.f, dp);
o.C = c0 * (consts.w+consts.z*dpc*frac);
float dpc = max(0.f, dp);
o.C = c0 * (consts.w+consts.z*dpc*frac);

// final xform, color, tc
o.tc.xy = (v.misc * consts).xy;
o.hpos = mul(m_WVP,pos);
o.tc.xy = (v.misc * consts).xy;

return o;
}
4 changes: 2 additions & 2 deletions src/Layers/xrRender/Blender_detail_still.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,13 @@ void CBlender_Detail_Still::Compile(CBlender_Compile& C)
switch (C.iElement)
{
case SE_R1_NORMAL_HQ:
C.r_Pass("detail_wave", "detail", FALSE, TRUE, TRUE, FALSE, D3DBLEND_ONE, D3DBLEND_ZERO,
C.r_Pass("detail_wave", "detail", TRUE, TRUE, TRUE, FALSE, D3DBLEND_ONE, D3DBLEND_ZERO,
oBlend.value ? TRUE : FALSE, oBlend.value ? 200 : 0);
C.r_Sampler("s_base", C.L_textures[0]);
C.r_End();
break;
case SE_R1_NORMAL_LQ:
C.r_Pass("detail_still", "detail", FALSE, TRUE, TRUE, FALSE, D3DBLEND_ONE, D3DBLEND_ZERO,
C.r_Pass("detail_still", "detail", TRUE, TRUE, TRUE, FALSE, D3DBLEND_ONE, D3DBLEND_ZERO,
oBlend.value ? TRUE : FALSE, oBlend.value ? 200 : 0);
C.r_Sampler("s_base", C.L_textures[0]);
C.r_End();
Expand Down

0 comments on commit 8e0176b

Please sign in to comment.