From 8e0176b327879723b196b73446a00c0c488de317 Mon Sep 17 00:00:00 2001 From: RainbowZerg Date: Wed, 27 Jun 2018 14:24:43 +0300 Subject: [PATCH] Detail objects are now affected by fog. --- res/gamedata/shaders/r1/detail_still.vs | 20 ++++++---- res/gamedata/shaders/r1/detail_wave.vs | 40 +++++++++++--------- src/Layers/xrRender/Blender_detail_still.cpp | 4 +- 3 files changed, 36 insertions(+), 28 deletions(-) diff --git a/res/gamedata/shaders/r1/detail_still.vs b/res/gamedata/shaders/r1/detail_still.vs index 7fec3044e95..a49c9bc3c60 100644 --- a/res/gamedata/shaders/r1/detail_still.vs +++ b/res/gamedata/shaders/r1/detail_still.vs @@ -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) { @@ -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; diff --git a/res/gamedata/shaders/r1/detail_wave.vs b/res/gamedata/shaders/r1/detail_wave.vs index 54f183079ee..b1527aa8f67 100644 --- a/res/gamedata/shaders/r1/detail_wave.vs +++ b/res/gamedata/shaders/r1/detail_wave.vs @@ -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) { @@ -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; } diff --git a/src/Layers/xrRender/Blender_detail_still.cpp b/src/Layers/xrRender/Blender_detail_still.cpp index 05b024ebb08..718ec4fc361 100644 --- a/src/Layers/xrRender/Blender_detail_still.cpp +++ b/src/Layers/xrRender/Blender_detail_still.cpp @@ -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();