diff --git a/res/gamedata/shaders/r1/add_point.ps b/res/gamedata/shaders/r1/add_point.ps index e6e452f86fd..b57e0789724 100644 Binary files a/res/gamedata/shaders/r1/add_point.ps and b/res/gamedata/shaders/r1/add_point.ps differ diff --git a/res/gamedata/shaders/r1/add_point_dt.ps b/res/gamedata/shaders/r1/add_point_dt.ps new file mode 100644 index 00000000000..db713ae22d7 Binary files /dev/null and b/res/gamedata/shaders/r1/add_point_dt.ps differ diff --git a/res/gamedata/shaders/r1/add_spot.ps b/res/gamedata/shaders/r1/add_spot.ps index 37b0c7a1527..eafae517cc8 100644 Binary files a/res/gamedata/shaders/r1/add_spot.ps and b/res/gamedata/shaders/r1/add_spot.ps differ diff --git a/res/gamedata/shaders/r1/add_spot_dt.ps b/res/gamedata/shaders/r1/add_spot_dt.ps new file mode 100644 index 00000000000..b40217d282a Binary files /dev/null and b/res/gamedata/shaders/r1/add_spot_dt.ps differ diff --git a/res/gamedata/shaders/r1/base_lplanes.vs b/res/gamedata/shaders/r1/base_lplanes.vs index b43c8de0685..5c6a205f5fc 100644 --- a/res/gamedata/shaders/r1/base_lplanes.vs +++ b/res/gamedata/shaders/r1/base_lplanes.vs @@ -12,8 +12,7 @@ vf main (v_vert v) vf o; o.hpos = mul (m_WVP, v.P); // xform, input in world coords - o.tc0 = unpack_tc_base (v.uv,v.T.w,v.B.w); // copy tc -// o.tc0 = unpack_tc_base (v.tc); // copy tc + o.tc0 = unpack_tc_base (v.uv0,v.T.w,v.B.w); // copy tc // calculate fade float3 dir_v = normalize (mul(m_WV,v.P)); diff --git a/res/gamedata/shaders/r1/common.h b/res/gamedata/shaders/r1/common.h index 6c633bf606c..6ae83dace47 100644 --- a/res/gamedata/shaders/r1/common.h +++ b/res/gamedata/shaders/r1/common.h @@ -67,7 +67,7 @@ struct v_vert float4 T : TANGENT; float4 B : BINORMAL; float4 color : COLOR0; // (r,g,b,dir-occlusion) - float2 uv : TEXCOORD0; // (u0,v0) + float2 uv0 : TEXCOORD0; // (u0,v0) }; struct v_model { @@ -91,7 +91,10 @@ struct vf_spot float2 tc0 : TEXCOORD0; // base float4 tc1 : TEXCOORD1; // lmap, projected float2 tc2 : TEXCOORD2; // att + clipper - float4 color : COLOR0; +#ifdef DL_DETAILS + float2 tcd : TEXCOORD3; // details +#endif + float4 color: COLOR0; }; struct vf_point { @@ -99,7 +102,10 @@ struct vf_point float2 tc0 : TEXCOORD0; // base float2 tc1 : TEXCOORD1; // att1 + clipper float2 tc2 : TEXCOORD2; // att2 + clipper - float4 color : COLOR0; +#ifdef DL_DETAILS + float2 tcd : TEXCOORD3; // details +#endif + float4 color: COLOR0; }; ////////////////////////////////////////////////////////////////////////////////////////// uniform sampler2D s_base; diff --git a/res/gamedata/shaders/r1/effects_wallmarkmult.s b/res/gamedata/shaders/r1/effects_wallmarkmult.s index 1ab0d66d0d5..2bfae1f545e 100644 --- a/res/gamedata/shaders/r1/effects_wallmarkmult.s +++ b/res/gamedata/shaders/r1/effects_wallmarkmult.s @@ -3,7 +3,7 @@ function normal (shader, t_base, t_second, t_detail) : sorting (2, false) : blend (true,blend.destcolor,blend.srccolor) : aref (false,0) - : zb (true,true) + : zb (true,false) : fog (true) : wmark (true) shader:sampler ("s_base") :texture (t_base) @@ -11,9 +11,32 @@ end function l_spot (shader, t_base, t_second, t_detail) - r1_lspot (shader, t_base, "wmark_spot") + shader:begin ("wmark_spot","add_spot") + : fog (false) + : zb (true,false) + : blend (true,blend.srcalpha,blend.one) + : aref (true,aref or 0) + shader:sampler ("s_base") :texture (t_base) + shader:sampler ("s_lmap") :texture ("internal\\internal_light_att") + : clamp () + : f_linear () + : project (true) + shader:sampler ("s_att") :texture ("internal\\internal_light_attclip") + : clamp () + : f_linear () end function l_point (shader, t_base, t_second, t_detail) - r1_lpoint (shader, t_base, "wmark_point") -end \ No newline at end of file + shader:begin ("wmark_point","add_point") + : fog (false) + : zb (true,false) + : blend (true,blend.srcalpha,blend.one) + : aref (true,aref or 0) + shader:sampler ("s_base") :texture (t_base) + shader:sampler ("s_lmap") :texture (t_point_att) + : clamp () + : f_linear () + shader:sampler ("s_att") :texture (t_point_att) + : clamp () + : f_linear () +end diff --git a/res/gamedata/shaders/r1/impl.ps b/res/gamedata/shaders/r1/impl.ps index 2564265f6d4..ccf343c54be 100644 Binary files a/res/gamedata/shaders/r1/impl.ps and b/res/gamedata/shaders/r1/impl.ps differ diff --git a/res/gamedata/shaders/r1/impl.vs b/res/gamedata/shaders/r1/impl.vs index c85368c33a6..f7bf4abe5a0 100644 --- a/res/gamedata/shaders/r1/impl.vs +++ b/res/gamedata/shaders/r1/impl.vs @@ -5,8 +5,14 @@ struct vf float4 hpos : POSITION; float2 tc0 : TEXCOORD0; float2 tc1 : TEXCOORD1; - float3 c0 : COLOR0; // c0=hemi, c0.a = dt* - float3 c1 : COLOR1; // c1=sun, c1.a = dt+ +#ifdef T_DETAILS + float2 tcd : TEXCOORD2; + float4 c0 : COLOR0; // xyz=hemi, w=dt* + float4 c1 : COLOR1; // xyz=sun, w=dt+ +#else + float3 c0 : COLOR0; // hemi + float3 c1 : COLOR1; // sun +#endif float fog : FOG; }; @@ -14,13 +20,20 @@ vf main (v_lmap v) { vf o; - float3 N = unpack_normal (v.N); - o.hpos = mul (m_VP, v.P); // xform, input in world coords - o.tc0 = unpack_tc_base (v.uv0,v.T.w,v.B.w); // copy tc - o.tc1 = o.tc0; // copy tc - o.c0 = v_hemi (N); // hemi - o.c1 = v_sun (N); // sun - o.fog = calc_fogging (v.P); // fog, input in world coords + float3 N = unpack_normal(v.N); + o.hpos = mul(m_VP, v.P); // xform, input in world coords + o.tc0 = unpack_tc_base(v.uv0,v.T.w,v.B.w); + o.tc1 = o.tc0; // copy tc +#ifdef T_DETAILS + float2 dt = calc_detail(v.P); + o.tcd = o.tc0*dt_params; // dt tc + o.c0 = float4(v_hemi(N), dt.x); // xyz=hemi, w=dt* + o.c1 = float4(v_sun(N), dt.y); // xyz=sun, w=dt+ +#else + o.c0 = v_hemi(N); // hemi + o.c1 = v_sun(N); // sun +#endif + o.fog = calc_fogging(v.P); // fog, input in world coords return o; } diff --git a/res/gamedata/shaders/r1/impl_dt.ps b/res/gamedata/shaders/r1/impl_dt.ps index 625d7e0b7af..ccaa28d23aa 100644 Binary files a/res/gamedata/shaders/r1/impl_dt.ps and b/res/gamedata/shaders/r1/impl_dt.ps differ diff --git a/res/gamedata/shaders/r1/impl_dt.vs b/res/gamedata/shaders/r1/impl_dt.vs index 9cfbd1b8d96..e20ade76924 100644 --- a/res/gamedata/shaders/r1/impl_dt.vs +++ b/res/gamedata/shaders/r1/impl_dt.vs @@ -1,29 +1,3 @@ -#include "common.h" +#define T_DETAILS -struct vf -{ - float4 hpos : POSITION; - float2 tc0 : TEXCOORD0; - float2 tc1 : TEXCOORD1; - float2 tc2 : TEXCOORD2; - float4 c0 : COLOR0; // c0=hemi+v-lights, c0.a = dt* - float4 c1 : COLOR1; // c1=sun, c1.a = dt+ - float fog : FOG; -}; - -vf main (v_lmap v) -{ - vf o; - - float2 dt = calc_detail (v.P); - float3 N = unpack_normal (v.N); - o.hpos = mul (m_VP, v.P); // xform, input in world coords - o.tc0 = unpack_tc_base (v.uv0,v.T.w,v.B.w); // copy tc - o.tc1 = o.tc0; // copy tc - o.tc2 = o.tc0*dt_params; // dt tc - o.c0 = float4 (v_hemi(N), dt.x); // c0=v-lights, c0.a = dt* - o.c1 = float4 (v_sun(N), dt.y); // c1=sun, c1.a = dt+ - o.fog = calc_fogging (v.P); // fog, input in world coords - - return o; -} +#include "impl.vs" diff --git a/res/gamedata/shaders/r1/impl_point.vs b/res/gamedata/shaders/r1/impl_point.vs index 205393593b2..241fc040957 100644 --- a/res/gamedata/shaders/r1/impl_point.vs +++ b/res/gamedata/shaders/r1/impl_point.vs @@ -1,13 +1,4 @@ -#include "common.h" +#define DL_LMAP +#define DL_POINT -vf_point main (v_lmap v) -{ - vf_point o; - - o.hpos = mul (m_VP, v.P); // xform, input in world coords - o.tc0 = unpack_tc_base (v.uv0,v.T.w,v.B.w); // copy tc -// o.tc0 = unpack_tc_base(v.tc0); // copy tc - o.color = calc_point (o.tc1,o.tc2,v.P,unpack_normal(v.N)); // just hemisphere - - return o; -} +#include "shared_dynlight.vs" \ No newline at end of file diff --git a/res/gamedata/shaders/r1/impl_point_dt.vs b/res/gamedata/shaders/r1/impl_point_dt.vs new file mode 100644 index 00000000000..ffecac857af --- /dev/null +++ b/res/gamedata/shaders/r1/impl_point_dt.vs @@ -0,0 +1,5 @@ +#define DL_DETAILS +#define DL_LMAP +#define DL_POINT + +#include "shared_dynlight.vs" \ No newline at end of file diff --git a/res/gamedata/shaders/r1/impl_spot.vs b/res/gamedata/shaders/r1/impl_spot.vs index dce5b2706bb..937e5a4672e 100644 --- a/res/gamedata/shaders/r1/impl_spot.vs +++ b/res/gamedata/shaders/r1/impl_spot.vs @@ -1,13 +1,3 @@ -#include "common.h" +#define DL_LMAP -vf_spot main (v_lmap v) -{ - vf_spot o; - - o.hpos = mul (m_VP, v.P); // xform, input in world coords - o.tc0 = unpack_tc_base (v.uv0,v.T.w,v.B.w); // copy tc -// o.tc0 = unpack_tc_base(v.tc0); // copy tc - o.color = calc_spot (o.tc1,o.tc2,v.P,unpack_normal(v.N)); // just hemisphere - - return o; -} +#include "shared_dynlight.vs" \ No newline at end of file diff --git a/res/gamedata/shaders/r1/impl_spot_dt.vs b/res/gamedata/shaders/r1/impl_spot_dt.vs new file mode 100644 index 00000000000..b6b48037522 --- /dev/null +++ b/res/gamedata/shaders/r1/impl_spot_dt.vs @@ -0,0 +1,4 @@ +#define DL_DETAILS +#define DL_LMAP + +#include "shared_dynlight.vs" \ No newline at end of file diff --git a/res/gamedata/shaders/r1/lmap.ps b/res/gamedata/shaders/r1/lmap.ps index 3de42e4de78..98eafa79847 100644 Binary files a/res/gamedata/shaders/r1/lmap.ps and b/res/gamedata/shaders/r1/lmap.ps differ diff --git a/res/gamedata/shaders/r1/lmap.vs b/res/gamedata/shaders/r1/lmap.vs index 88ec7165c19..f220b5da147 100644 --- a/res/gamedata/shaders/r1/lmap.vs +++ b/res/gamedata/shaders/r1/lmap.vs @@ -6,8 +6,14 @@ struct vf float2 tc0 : TEXCOORD0; float2 tc1 : TEXCOORD1; float2 tch : TEXCOORD2; - float3 c0 : COLOR0; // c0=hemi+v-lights, c0.a = dt* - float3 c1 : COLOR1; // c1=sun, c1.a = dt+ +#ifdef T_DETAILS + float2 tcd : TEXCOORD3; + float4 c0 : COLOR0; // xyz=hemi+v-lights, w=dt* + float4 c1 : COLOR1; // xyz=sun, w=dt+ +#else + float3 c0 : COLOR0; // c0=hemi+v-lights + float3 c1 : COLOR1; // c1=sun +#endif float fog : FOG; }; @@ -15,15 +21,22 @@ vf main (v_lmap v) { vf o; - float3 N = unpack_normal (v.N); - o.hpos = mul (m_VP, v.P); // xform, input in world coords - o.tc0 = unpack_tc_base (v.uv0,v.T.w,v.B.w); // copy tc -// o.tc0 = unpack_tc_base (v.tc0); // copy tc - o.tc1 = unpack_tc_lmap (v.uv1); // copy tc + float3 N = unpack_normal(v.N); + + o.hpos = mul(m_VP, v.P); // xform, input in world coords + o.tc0 = unpack_tc_base(v.uv0,v.T.w,v.B.w); + o.tc1 = unpack_tc_lmap(v.uv1); o.tch = o.tc1; - o.c0 = v_hemi(N); // just hemisphere - o.c1 = v_sun(N); // sun - o.fog = calc_fogging (v.P); // fog, input in world coords +#ifdef T_DETAILS + float2 dt = calc_detail(v.P); + o.tcd = o.tc0*dt_params; // dt tc + o.c0 = float4(v_hemi(N),dt.x); // xyz=hemi+v-lights, w=dt* + o.c1 = float4(v_sun(N),dt.y); // xyz=sun, w=dt+ +#else + o.c0 = v_hemi(N); // hemi+v-lights + o.c1 = v_sun(N); // sun +#endif + o.fog = calc_fogging(v.P); // fog, input in world coords return o; } diff --git a/res/gamedata/shaders/r1/lmap_dt.ps b/res/gamedata/shaders/r1/lmap_dt.ps index c77fb54a034..b164e125535 100644 Binary files a/res/gamedata/shaders/r1/lmap_dt.ps and b/res/gamedata/shaders/r1/lmap_dt.ps differ diff --git a/res/gamedata/shaders/r1/lmap_dt.vs b/res/gamedata/shaders/r1/lmap_dt.vs index f1617ab110b..4445663d108 100644 --- a/res/gamedata/shaders/r1/lmap_dt.vs +++ b/res/gamedata/shaders/r1/lmap_dt.vs @@ -1,33 +1,3 @@ -#include "common.h" +#define T_DETAILS -struct vf -{ - float4 hpos : POSITION; - float2 tc0 : TEXCOORD0; - float2 tc1 : TEXCOORD1; - float2 tch : TEXCOORD2; - float2 tc2 : TEXCOORD3; - float4 c0 : COLOR0; // c0=hemi+v-lights, c0.a = dt* - float4 c1 : COLOR1; // c1=sun, c1.a = dt+ - float fog : FOG; -}; - -vf main (v_lmap v) -{ - vf o; - - float2 dt = calc_detail (v.P); - float3 N = unpack_normal (v.N); - - o.hpos = mul (m_VP, v.P); // xform, input in world coords - o.tc0 = unpack_tc_base (v.uv0,v.T.w,v.B.w); // copy tc -// o.tc0 = unpack_tc_base (v.tc0); // copy tc - o.tc1 = unpack_tc_lmap (v.uv1); // copy tc - o.tch = o.tc1; - o.tc2 = o.tc0*dt_params; // dt tc - o.c0 = float4 (v_hemi(N),dt.x); // c0=hemi+v-lights, c0.a = dt* - o.c1 = float4 (v_sun(N),dt.y); // c1=sun, c1.a = dt+ - o.fog = calc_fogging (v.P); // fog, input in world coords - - return o; -} +#include "lmap.vs" diff --git a/res/gamedata/shaders/r1/lmap_point.vs b/res/gamedata/shaders/r1/lmap_point.vs index 1b81dce9af7..c8d9321946a 100644 --- a/res/gamedata/shaders/r1/lmap_point.vs +++ b/res/gamedata/shaders/r1/lmap_point.vs @@ -1,13 +1,4 @@ -#include "common.h" +#define DL_LMAP +#define DL_POINT -vf_point main (v_lmap v) -{ - vf_point o; - - o.hpos = mul (m_VP, v.P); // xform, input in world coords - o.tc0 = unpack_tc_base(v.uv0,v.T.w,v.B.w); // copy tc - //o.tc0 = unpack_tc_base(v.tc0); // copy tc - o.color = calc_point (o.tc1,o.tc2,v.P,unpack_normal(v.N)); // just hemisphere - - return o; -} +#include "shared_dynlight.vs" diff --git a/res/gamedata/shaders/r1/lmap_point_dt.vs b/res/gamedata/shaders/r1/lmap_point_dt.vs new file mode 100644 index 00000000000..ffecac857af --- /dev/null +++ b/res/gamedata/shaders/r1/lmap_point_dt.vs @@ -0,0 +1,5 @@ +#define DL_DETAILS +#define DL_LMAP +#define DL_POINT + +#include "shared_dynlight.vs" \ No newline at end of file diff --git a/res/gamedata/shaders/r1/lmap_spot.vs b/res/gamedata/shaders/r1/lmap_spot.vs index 97fedacc3c2..9a34f134d25 100644 --- a/res/gamedata/shaders/r1/lmap_spot.vs +++ b/res/gamedata/shaders/r1/lmap_spot.vs @@ -1,13 +1,3 @@ -#include "common.h" +#define DL_LMAP -vf_spot main (v_lmap v) -{ - vf_spot o; - - o.hpos = mul (m_VP, v.P); // xform, input in world coords - o.tc0 = unpack_tc_base(v.uv0,v.T.w,v.B.w); // copy tc -// o.tc0 = unpack_tc_base(v.tc0); // copy tc - o.color = calc_spot (o.tc1,o.tc2,v.P,unpack_normal(v.N)); // just hemisphere - - return o; -} +#include "shared_dynlight.vs" diff --git a/res/gamedata/shaders/r1/lmap_spot_dt.vs b/res/gamedata/shaders/r1/lmap_spot_dt.vs new file mode 100644 index 00000000000..32ae1b68182 --- /dev/null +++ b/res/gamedata/shaders/r1/lmap_spot_dt.vs @@ -0,0 +1,4 @@ +#define DL_DETAILS +#define DL_LMAP + +#include "shared_dynlight.vs" \ No newline at end of file diff --git a/res/gamedata/shaders/r1/model_def_hq.ps b/res/gamedata/shaders/r1/model_def_hq.ps index f2751725609..2b0207376a4 100644 Binary files a/res/gamedata/shaders/r1/model_def_hq.ps and b/res/gamedata/shaders/r1/model_def_hq.ps differ diff --git a/res/gamedata/shaders/r1/model_def_hq.vs b/res/gamedata/shaders/r1/model_def_hq.vs index b0d32cd5a88..5fe1100b296 100644 --- a/res/gamedata/shaders/r1/model_def_hq.vs +++ b/res/gamedata/shaders/r1/model_def_hq.vs @@ -1,37 +1,43 @@ #include "common.h" #include "skin.h" -// #define SKIN_2 - struct vf { float4 hpos : POSITION; - float2 tc0 : TEXCOORD0; // base - float4 tc1 : TEXCOORD1; // projected lmap + float2 tc0 : TEXCOORD0; // base + float4 tc1 : TEXCOORD1; // projected lmap +#ifdef T_DETAILS + float2 tcd : TEXCOORD2; // details +#endif float3 c0 : COLOR0; // sun-color - float4 c1 : COLOR1; // lq-color + factor + float4 c1 : COLOR1; // xyz=lq-color, w=factor float fog : FOG; }; -vf _main (v_model v) +vf _main (v_model v) { vf o; - float4 pos = v.pos; - float3 pos_w = mul (m_W, pos); - float4 pos_w4 = float4 (pos_w,1); - float3 norm_w = normalize (mul(m_W,v.norm)); + float4 pos = v.pos; + float3 pos_w = mul(m_W, pos); + float4 pos_w4 = float4(pos_w,1); + float3 norm_w = normalize(mul(m_W,v.norm)); + + o.hpos = mul(m_WVP, pos); // xform, input in world coords + o.tc0 = v.tc.xy; // copy tc + o.tc1 = calc_model_lmap(pos_w); + +#ifdef T_DETAILS + o.tcd = o.tc0.xy*dt_params; // dt tc +#endif - o.hpos = mul (m_WVP, pos); // xform, input in world coords - o.tc0 = v.tc.xy; // copy tc - o.tc1 = calc_model_lmap (pos_w); // - o.c0 = calc_sun (norm_w); // sun - o.c1 = float4 (calc_model_lq_lighting(norm_w),m_plmap_clamp[0].w); - o.fog = calc_fogging (pos_w4); // fog, input in world coords + o.c0 = calc_sun(norm_w); // sun-color + o.c1 = float4(calc_model_lq_lighting(norm_w), m_plmap_clamp[0].w);// lq-color + o.fog = calc_fogging(pos_w4); // fog, input in world coords #ifdef SKIN_COLOR - o.c1.rgb *= v.rgb_tint; - o.c1.w = 1; + o.c1.rgb *= v.rgb_tint; + o.c1.w = 1; #endif return o; diff --git a/res/gamedata/shaders/r1/model_def_hq_dt.ps b/res/gamedata/shaders/r1/model_def_hq_dt.ps new file mode 100644 index 00000000000..ee3571b26f8 Binary files /dev/null and b/res/gamedata/shaders/r1/model_def_hq_dt.ps differ diff --git a/res/gamedata/shaders/r1/model_def_hq_dt.vs b/res/gamedata/shaders/r1/model_def_hq_dt.vs new file mode 100644 index 00000000000..a2ef3581227 --- /dev/null +++ b/res/gamedata/shaders/r1/model_def_hq_dt.vs @@ -0,0 +1,3 @@ +#define T_DETAILS + +#include "model_def_hq.vs" \ No newline at end of file diff --git a/res/gamedata/shaders/r1/model_def_point.vs b/res/gamedata/shaders/r1/model_def_point.vs index 2b70e9a97be..998b01d8356 100644 --- a/res/gamedata/shaders/r1/model_def_point.vs +++ b/res/gamedata/shaders/r1/model_def_point.vs @@ -1,22 +1,3 @@ -#include "common.h" -#include "skin.h" +#define DL_POINT -vf_point _main (v_model v) -{ - vf_point o; - - float4 pos = v.pos; - float3 pos_w = mul (m_W, pos); - float4 pos_w4 = float4 (pos_w,1); - float3 norm_w = normalize (mul(m_W,v.norm)); - - o.hpos = mul (m_WVP, pos); // xform, input in world coords - o.tc0 = v.tc.xy; // copy tc - o.color = calc_point (o.tc1,o.tc2,pos_w4,norm_w); // just hemisphere - - return o; -} - -///////////////////////////////////////////////////////////////////////// -#define SKIN_VF vf_point -#include "skin_main.h" \ No newline at end of file +#include "shared_dynlight_model.vs" diff --git a/res/gamedata/shaders/r1/model_def_point_dt.vs b/res/gamedata/shaders/r1/model_def_point_dt.vs new file mode 100644 index 00000000000..afe42fbed5f --- /dev/null +++ b/res/gamedata/shaders/r1/model_def_point_dt.vs @@ -0,0 +1,4 @@ +#define DL_DETAILS +#define DL_POINT + +#include "shared_dynlight_model.vs" \ No newline at end of file diff --git a/res/gamedata/shaders/r1/model_def_spot.vs b/res/gamedata/shaders/r1/model_def_spot.vs index 6e349f3b0bb..a140212ef4b 100644 --- a/res/gamedata/shaders/r1/model_def_spot.vs +++ b/res/gamedata/shaders/r1/model_def_spot.vs @@ -1,22 +1 @@ -#include "common.h" -#include "skin.h" - -vf_spot _main (v_model v) -{ - vf_spot o; - - float4 pos = v.pos; - float3 pos_w = mul (m_W, pos); - float4 pos_w4 = float4 (pos_w,1); - float3 norm_w = normalize (mul(m_W,v.norm)); - - o.hpos = mul (m_WVP, pos); // xform, input in world coords - o.tc0 = v.tc.xy; // copy tc - o.color = calc_spot (o.tc1,o.tc2,pos_w4,norm_w); // just hemisphere - - return o; -} - -///////////////////////////////////////////////////////////////////////// -#define SKIN_VF vf_spot -#include "skin_main.h" \ No newline at end of file +#include "shared_dynlight_model.vs" diff --git a/res/gamedata/shaders/r1/model_def_spot_dt.vs b/res/gamedata/shaders/r1/model_def_spot_dt.vs new file mode 100644 index 00000000000..9211e1d294a --- /dev/null +++ b/res/gamedata/shaders/r1/model_def_spot_dt.vs @@ -0,0 +1,3 @@ +#define DL_DETAILS + +#include "shared_dynlight_model.vs" \ No newline at end of file diff --git a/res/gamedata/shaders/r1/shared_dynlight.vs b/res/gamedata/shaders/r1/shared_dynlight.vs new file mode 100644 index 00000000000..eec2d10a2a3 --- /dev/null +++ b/res/gamedata/shaders/r1/shared_dynlight.vs @@ -0,0 +1,43 @@ +#include "common.h" + +#ifdef DL_POINT + #define _out vf_point +#else + #define _out vf_spot +#endif + +#ifdef DL_LMAP + #define _in v_lmap +#else + #define _in v_vert +#endif + +_out main (_in v) +{ + _out o; + + float3 N = unpack_bx2 (v.N); +#ifndef DL_WMARK + float4 P = v.P; +#else + float4 P = wmark_shift (v.P,N); +#endif + o.hpos = mul (m_VP, P); // xform, input in world coords + o.tc0 = unpack_tc_base(v.uv0,v.T.w,v.B.w); // copy tc +#ifdef DL_DETAILS + float2 dt = calc_detail (v.P); + o.tcd = o.tc0*dt_params; +#endif + +#ifdef DL_POINT + o.color = calc_point(o.tc1,o.tc2,P,N); +#else + o.color = calc_spot (o.tc1,o.tc2,P,N); +#endif + +#ifdef DL_DETAILS + o.color = o.color * dt.x + dt.y; +#endif + + return o; +} \ No newline at end of file diff --git a/res/gamedata/shaders/r1/shared_dynlight_model.vs b/res/gamedata/shaders/r1/shared_dynlight_model.vs new file mode 100644 index 00000000000..445a1a54d31 --- /dev/null +++ b/res/gamedata/shaders/r1/shared_dynlight_model.vs @@ -0,0 +1,35 @@ +#include "common.h" +#include "skin.h" + +#ifdef DL_POINT + #define _out vf_point +#else + #define _out vf_spot +#endif + +_out _main (v_model v) +{ + _out o; + + float4 pos = v.pos; + float4 pos_w4 = float4(mul(m_W,pos),1); + float3 norm_w = normalize(mul(m_W,v.norm)); + + o.hpos = mul(m_WVP, pos); // xform, input in world coords + o.tc0 = v.tc.xy; // copy tc +#ifdef DL_POINT + o.color = calc_point(o.tc1,o.tc2,pos_w4,norm_w); +#else + o.color = calc_spot(o.tc1,o.tc2,pos_w4,norm_w); +#endif + +#ifdef DL_DETAILS + o.tcd = o.tc0*dt_params; +#endif + + return o; +} + +///////////////////////////////////////////////////////////////////////// +#define SKIN_VF _out +#include "skin_main.h" \ No newline at end of file diff --git a/res/gamedata/shaders/r1/shared_dynlight_tree.vs b/res/gamedata/shaders/r1/shared_dynlight_tree.vs new file mode 100644 index 00000000000..7200d3db99d --- /dev/null +++ b/res/gamedata/shaders/r1/shared_dynlight_tree.vs @@ -0,0 +1,62 @@ +#include "common.h" + +#ifdef DL_POINT + #define _out vf_point +#else + #define _out vf_spot +#endif + +struct _in +{ + float4 P : POSITION; // (float,float,float,1) + float4 N : NORMAL; // (float,float,float,clr) + float4 misc : TEXCOORD0; // (u(Q),v(Q),frac,???) +}; + +uniform float3x4 m_xform; +uniform float4 consts; // {1/quant,1/quant,???,???} +#ifdef T_WAVE +uniform float4 wave; // cx,cy,cz,tm +uniform float4 wind; // direction2D +#endif + +_out main (_in v) +{ + _out o; + + float3 N = normalize(mul (m_xform, unpack_bx2(v.N))); + // Transform to world coords + float3 _P = mul(m_xform, v.P); + +#ifdef T_WAVE + float base = m_xform._24; // take base height from matrix + float dp = calc_cyclic(wave.w+dot(_P, wave.xyz)); + float H = _P.y - base; // height of vertex (scaled, rotated, etc.) + float frac = v.misc.z*consts.x; // fractional (or rigidity) + float inten = H * dp; // intensity + float2 result = calc_xz_wave(wind.xz*inten, frac); + float4 P = float4(_P.x+result.x, _P.y, _P.z+result.y, 1.0f); +#else + float4 P = float4(_P, 1.0f); +#endif + + // Final xform + o.hpos = mul (m_VP, P); + o.tc0 = v.misc.xy * consts.xy; +#ifdef DL_DETAILS + float2 dt = calc_detail (v.P); + o.tcd = o.tc0*dt_params; +#endif + +#ifdef DL_POINT + o.color = calc_point(o.tc1,o.tc2,P,N); +#else + o.color = calc_spot (o.tc1,o.tc2,P,N); +#endif + +#ifdef DL_DETAILS + o.color = o.color * dt.x + dt.y; +#endif + + return o; +} \ No newline at end of file diff --git a/res/gamedata/shaders/r1/simple.vs b/res/gamedata/shaders/r1/simple.vs index 79107537ea4..11e3f29f6c7 100644 --- a/res/gamedata/shaders/r1/simple.vs +++ b/res/gamedata/shaders/r1/simple.vs @@ -12,7 +12,7 @@ vf main (v_vert v) vf o; o.hpos = mul (m_VP, v.P); // xform, input in world coords - o.tc0 = unpack_tc_base (v.uv,v.T.w,v.B.w); // copy tc + o.tc0 = unpack_tc_base (v.uv0,v.T.w,v.B.w); // copy tc o.fog = calc_fogging (v.P); // fog, input in world coords return o; diff --git a/res/gamedata/shaders/r1/simple_point.vs b/res/gamedata/shaders/r1/simple_point.vs index a7264319441..0ddaba9d3ba 100644 --- a/res/gamedata/shaders/r1/simple_point.vs +++ b/res/gamedata/shaders/r1/simple_point.vs @@ -1,13 +1,4 @@ -#include "common.h" +#define LMAP +#define POINT -vf_point main (v_lmap v) -{ - vf_point o; - - o.hpos = mul (m_VP, v.P); // xform, input in world coords - o.tc0 = unpack_tc_base (v.uv0,v.T.w,v.B.w); // copy tc -// o.tc0 = unpack_tc_base(v.tc0); // copy tc - o.color = calc_point (o.tc1,o.tc2,v.P,unpack_normal(v.N)); // just hemisphere - - return o; -} +#include "shared_dynlight.vs" diff --git a/res/gamedata/shaders/r1/simple_spot.vs b/res/gamedata/shaders/r1/simple_spot.vs index dce5b2706bb..57105671f98 100644 --- a/res/gamedata/shaders/r1/simple_spot.vs +++ b/res/gamedata/shaders/r1/simple_spot.vs @@ -1,13 +1,3 @@ -#include "common.h" +#define LMAP -vf_spot main (v_lmap v) -{ - vf_spot o; - - o.hpos = mul (m_VP, v.P); // xform, input in world coords - o.tc0 = unpack_tc_base (v.uv0,v.T.w,v.B.w); // copy tc -// o.tc0 = unpack_tc_base(v.tc0); // copy tc - o.color = calc_spot (o.tc1,o.tc2,v.P,unpack_normal(v.N)); // just hemisphere - - return o; -} +#include "shared_dynlight.vs" diff --git a/res/gamedata/shaders/r1/tree.vs b/res/gamedata/shaders/r1/tree.vs new file mode 100644 index 00000000000..26a44e93e7c --- /dev/null +++ b/res/gamedata/shaders/r1/tree.vs @@ -0,0 +1,83 @@ +#include "common.h" + +struct av +{ + float4 pos : POSITION; // (float,float,float,1) + float4 nc : NORMAL; // (float,float,float,clr) + float4 misc: TEXCOORD0; // (u(Q),v(Q),frac,???) +}; + +struct vf +{ + float4 hpos : POSITION; + float2 tc0 : TEXCOORD0; +#ifdef T_DETAILS + float2 tcd : TEXCOORD1; // detail + float4 c0 : COLOR0; // xyz=all lighting, w=dt* + float4 c1 : COLOR1; // dt+ +#else + float3 c0 : COLOR0; // all lighting +#endif + float fog : FOG; +}; + +uniform float3x4 m_xform; +uniform float4 consts; // 1/quant,1/quant,???,??? +#ifdef TREE_WAVE +uniform float4 wave; // cx,cy,cz,tm +uniform float4 wind; // direction2D +#endif +uniform float4 c_bias; // + color +uniform float4 c_scale; // * color +uniform float2 c_sun; // x=*, y=+ + +vf main (av v) +{ + vf o; + + // Transform to world coords + float3 pos = mul(m_xform, v.pos); + +#ifdef TREE_WAVE + // Calc waving + float base = m_xform._24; // take base height from matrix + float dp = calc_cyclic(wave.w+dot(pos,(float3)wave)); + float H = pos.y - base; // height of vertex (scaled, rotated, etc.) + float frac = v.misc.z*consts.x; // fractional (or rigidity) + float inten = H * dp; // intensity + float2 result = calc_xz_wave(wind.xz*inten, frac); + float4 f_pos = float4(pos.x+result.x, pos.y, pos.z+result.y, 1); +#else + float4 f_pos = float4(pos,1); +#endif + + // Calc fog + o.fog = calc_fogging(f_pos); + + // Calc lighting + float3 N = mul(m_xform, unpack_normal(v.nc)); // normalize(mul(m_xform, unpack_normal(v.nc))); + float L_base = v.nc.w; // base hemisphere + float4 L_unpack= c_scale*L_base+c_bias; // unpacked and decompressed + float3 L_rgb = L_unpack.xyz; // precalculated RGB lighting + float3 L_hemi = v_hemi_wrap(N,0.75f)*L_unpack.w; // hemisphere + float3 L_sun = v_sun(N)*(L_base*c_sun.x+c_sun.y); // sun + // Some alternative sunlight calculating formulas (GSC) + //float3 L_sun = v_sun_wrap(N,0.25f)*(L_base*c_sun.x+c_sun.y); + //float3 L_sun = L_sun_color*(0.25f+0.75f*dot(N,-L_sun_dir_w))*(L_base*c_sun.x+c_sun.y); + //float3 L_sun = L_sun_color*max(0,(1+dot(N,-L_sun_dir_w))/2)*(L_base*c_sun.x+c_sun.y); + float3 L_final = L_rgb + L_hemi + L_sun; + + // Final xform, color, tc + o.hpos = mul(m_VP, f_pos); + o.tc0 = (v.misc * consts).xy; +#ifdef T_DETAILS + o.tcd = o.tc0*dt_params; // dt tc + float2 dt = calc_detail(f_pos); + o.c0 = float4(L_final,dt.x); // xyz=all lighting, w=dt* + o.c1 = dt.y; // dt+ +#else + o.c0 = L_final; +#endif + + return o; +} diff --git a/res/gamedata/shaders/r1/tree_s.vs b/res/gamedata/shaders/r1/tree_s.vs index e330f907963..3b4eabfeb96 100644 --- a/res/gamedata/shaders/r1/tree_s.vs +++ b/res/gamedata/shaders/r1/tree_s.vs @@ -1,64 +1 @@ -#include "common.h" - -struct av -{ - float4 pos : POSITION; // (float,float,float,1) - float4 nc : NORMAL; // (float,float,float,clr) - float4 misc : TEXCOORD0; // (u(Q),v(Q),frac,???) -}; - -struct vf -{ - float4 HPOS : POSITION; - float3 COL0 : COLOR0; - float2 TEX0 : TEXCOORD0; - float fog : FOG; -}; - -uniform float3x4 m_xform; -uniform float4 consts; // {1/quant,1/quant,???,???} -uniform float4 wave; // cx,cy,cz,tm -uniform float4 wind; // direction2D -uniform float4 c_bias; // + color -uniform float4 c_scale; // * color -uniform float2 c_sun; // x=*, y=+ - -vf main (av v) -{ - vf o; - - // Transform to world coords - float3 pos = mul (m_xform, v.pos); - - // - float base = m_xform._24; // take base height from matrix - float dp = calc_cyclic (wave.w+dot(pos,(float3)wave)); - float H = pos.y - base; // height of vertex (scaled, rotated, etc.) - float frac = v.misc.z*consts.x; // fractional (or rigidity) - float inten = H * dp; // intensity - float2 result = calc_xz_wave (wind.xz*inten, frac); - float4 f_pos = float4(pos,1);//float4 (pos.x+result.x, pos.y, pos.z+result.y, 1); - - // Calc fog - o.fog = calc_fogging (f_pos); - - // Final xform - o.HPOS = mul (m_VP, f_pos); - - // Lighting - float3 N = mul (m_xform, unpack_normal(v.nc)); //normalize (mul (m_xform, unpack_normal(v.nc))); - float L_base = v.nc.w; // base hemisphere - float4 L_unpack= c_scale*L_base+c_bias; // unpacked and decompressed - float3 L_rgb = L_unpack.xyz; // precalculated RGB lighting - float3 L_hemi = v_hemi_wrap(N,.75f)* L_unpack.w; // hemisphere - //float3 L_sun = v_sun_wrap (N,.25f)* (L_base*c_sun.x+c_sun.y); // sun - float3 L_sun = v_sun (N)* (L_base*c_sun.x+c_sun.y); // sun - //float3 L_sun = L_sun_color*(.25f+.75f*dot(N,-L_sun_dir_w))*(L_base*c_sun.x+c_sun.y); - float3 L_final = L_rgb + L_hemi + L_sun; - o.COL0 = L_final; - - // final xform, color, tc - o.TEX0.xy = (v.misc * consts).xy; - - return o; -} +#include "tree.vs" diff --git a/res/gamedata/shaders/r1/tree_s_dt.vs b/res/gamedata/shaders/r1/tree_s_dt.vs index 368d0d745a4..b2877bdb3a7 100644 --- a/res/gamedata/shaders/r1/tree_s_dt.vs +++ b/res/gamedata/shaders/r1/tree_s_dt.vs @@ -1,69 +1,3 @@ -#include "common.h" +#define T_DETAILS -struct av -{ - float4 pos : POSITION; // (float,float,float,1) - float4 nc : NORMAL; // (float,float,float,clr) - float4 misc : TEXCOORD0; // (u(Q),v(Q),frac,???) -}; - -struct vf -{ - float4 HPOS : POSITION; - float4 COL0 : COLOR0; - float4 c1 : COLOR1; - float2 TEX0 : TEXCOORD0; - float2 tc1 : TEXCOORD1; // detail - float fog : FOG; -}; - -uniform float3x4 m_xform; -uniform float4 consts; // {1/quant,1/quant,???,???} -uniform float4 wave; // cx,cy,cz,tm -uniform float4 wind; // direction2D -uniform float4 c_bias; // + color -uniform float4 c_scale; // * color -uniform float2 c_sun; // x=*, y=+ - -vf main (av v) -{ - vf o; - - // Transform to world coords - float3 pos = mul (m_xform, v.pos); - - // - float base = m_xform._24; // take base height from matrix - float dp = calc_cyclic (wave.w+dot(pos,(float3)wave)); - float H = pos.y - base; // height of vertex (scaled, rotated, etc.) - float frac = v.misc.z*consts.x; // fractional (or rigidity) - float inten = H * dp; // intensity - float2 result = calc_xz_wave (wind.xz*inten, frac); - float4 f_pos = float4(pos,1);//float4 (pos.x+result.x, pos.y, pos.z+result.y, 1); - - // Calc fog - o.fog = calc_fogging (f_pos); - - // Final xform - o.HPOS = mul (m_VP, f_pos); - - // Lighting - float3 N = mul (m_xform, unpack_normal(v.nc)); // normalize (mul (m_xform, unpack_normal(v.nc))); - float L_base = v.nc.w; // base hemisphere - float4 L_unpack= c_scale*L_base+c_bias; // unpacked and decompressed - float3 L_rgb = L_unpack.xyz; // precalculated RGB lighting - float3 L_hemi = v_hemi_wrap(N,.75f)* L_unpack.w; // hemisphere - float3 L_sun = v_sun (N)* (L_base*c_sun.x+c_sun.y); // sun - //float3 L_sun = v_sun_wrap (N,.25f)* (L_base*c_sun.x+c_sun.y); // sun - //float3 L_sun = L_sun_color*(.25f+.75f*dot(N,-L_sun_dir_w))*(L_base*c_sun.x+c_sun.y); - float3 L_final = L_rgb + L_hemi + L_sun; - - // final xform, color, tc - o.TEX0.xy = (v.misc * consts).xy; - o.tc1 = o.TEX0*dt_params; // dt tc - float2 dt = calc_detail (f_pos); // - o.COL0 = float4 (L_final,dt.x); // - o.c1 = dt.y; // - - return o ; -} +#include "tree.vs" diff --git a/res/gamedata/shaders/r1/tree_s_point.vs b/res/gamedata/shaders/r1/tree_s_point.vs index f2a6de1ab56..cc5d5dd4e0e 100644 --- a/res/gamedata/shaders/r1/tree_s_point.vs +++ b/res/gamedata/shaders/r1/tree_s_point.vs @@ -1,41 +1,3 @@ -#include "common.h" +#define DL_POINT -struct av -{ - float4 pos : POSITION; // (float,float,float,1) - float4 nc : NORMAL; // (float,float,float,clr) - float4 misc : TEXCOORD0; // (u(Q),v(Q),frac,???) -}; - -uniform float3x4 m_xform; -uniform float4 consts; // {1/quant,1/quant,???,???} -uniform float4 wave; // cx,cy,cz,tm -uniform float4 wind; // direction2D -uniform float4 c_bias; // + color -uniform float4 c_scale; // * color -uniform float2 c_sun; // x=*, y=+ - -vf_point main (av v) -{ - vf_point o; - - // Transform to world coords - float3 pos = mul (m_xform, v.pos); - - // - float base = m_xform._24; // take base height from matrix - float dp = calc_cyclic (wave.w+dot(pos,(float3)wave)); - float H = pos.y - base; // height of vertex (scaled, rotated, etc.) - float frac = v.misc.z*consts.x; // fractional (or rigidity) - float inten = H * dp; // intensity - float2 result = calc_xz_wave (wind.xz*inten, frac); - float4 f_pos = float4(pos,1); //float4 (pos.x+result.x, pos.y, pos.z+result.y, 1); - float3 f_N = normalize (mul (m_xform, unpack_normal(v.nc))); - - // Final xform - o.hpos = mul (m_VP, f_pos); - o.tc0 = (v.misc * consts).xy; - o.color = calc_point (o.tc1,o.tc2,f_pos,f_N); - - return o; -} +#include "shared_dynlight_tree.vs" diff --git a/res/gamedata/shaders/r1/tree_s_point_dt.vs b/res/gamedata/shaders/r1/tree_s_point_dt.vs new file mode 100644 index 00000000000..e08b6c77e77 --- /dev/null +++ b/res/gamedata/shaders/r1/tree_s_point_dt.vs @@ -0,0 +1,4 @@ +#define DL_DETAILS +#define DL_POINT + +#include "shared_dynlight_tree.vs" \ No newline at end of file diff --git a/res/gamedata/shaders/r1/tree_s_spot.vs b/res/gamedata/shaders/r1/tree_s_spot.vs index 5f3b3bfa82a..8b04fd4dbbd 100644 --- a/res/gamedata/shaders/r1/tree_s_spot.vs +++ b/res/gamedata/shaders/r1/tree_s_spot.vs @@ -1,41 +1 @@ -#include "common.h" - -struct av -{ - float4 pos : POSITION; // (float,float,float,1) - float4 nc : NORMAL; // (float,float,float,clr) - float4 misc : TEXCOORD0; // (u(Q),v(Q),frac,???) -}; - -uniform float3x4 m_xform; -uniform float4 consts; // {1/quant,1/quant,???,???} -uniform float4 wave; // cx,cy,cz,tm -uniform float4 wind; // direction2D -uniform float4 c_bias; // + color -uniform float4 c_scale; // * color -uniform float2 c_sun; // x=*, y=+ - -vf_spot main (av v) -{ - vf_spot o; - - // Transform to world coords - float3 pos = mul (m_xform, v.pos); - - // - float base = m_xform._24; // take base height from matrix - float dp = calc_cyclic (wave.w+dot(pos,(float3)wave)); - float H = pos.y - base; // height of vertex (scaled, rotated, etc.) - float frac = v.misc.z*consts.x; // fractional (or rigidity) - float inten = H * dp; // intensity - float2 result = calc_xz_wave (wind.xz*inten, frac); - float4 f_pos = float4(pos,1); //float4 (pos.x+result.x, pos.y, pos.z+result.y, 1); - float3 f_N = normalize (mul (m_xform, unpack_normal(v.nc))); - - // Final xform - o.hpos = mul (m_VP, f_pos); - o.tc0 = (v.misc * consts).xy; - o.color = calc_spot (o.tc1,o.tc2,f_pos,f_N); - - return o; -} +#include "shared_dynlight_tree.vs" diff --git a/res/gamedata/shaders/r1/tree_s_spot_dt.vs b/res/gamedata/shaders/r1/tree_s_spot_dt.vs new file mode 100644 index 00000000000..a025a36dc6e --- /dev/null +++ b/res/gamedata/shaders/r1/tree_s_spot_dt.vs @@ -0,0 +1,3 @@ +#define DL_DETAILS + +#include "shared_dynlight_tree.vs" \ No newline at end of file diff --git a/res/gamedata/shaders/r1/tree_w.vs b/res/gamedata/shaders/r1/tree_w.vs index 9a77f237c9b..21cffd038b0 100644 --- a/res/gamedata/shaders/r1/tree_w.vs +++ b/res/gamedata/shaders/r1/tree_w.vs @@ -1,63 +1,3 @@ -#include "common.h" +#define TREE_WAVE -struct av -{ - float4 pos : POSITION; // (float,float,float,1) - float4 nc : NORMAL; // (float,float,float,clr) - float4 misc : TEXCOORD0; // (u(Q),v(Q),frac,???) -}; - -struct vf -{ - float4 HPOS : POSITION; - float3 COL0 : COLOR0; - float2 TEX0 : TEXCOORD0; - float fog : FOG; -}; - -uniform float3x4 m_xform; -uniform float4 consts; // {1/quant,1/quant,???,???} -uniform float4 wave; // cx,cy,cz,tm -uniform float4 wind; // direction2D -uniform float4 c_bias; // + color -uniform float4 c_scale; // * color -uniform float2 c_sun; // x=*, y=+ - -vf main (av v) -{ - vf o; - - // Transform to world coords - float3 pos = mul (m_xform, v.pos); - - // - float base = m_xform._24; // take base height from matrix - float dp = calc_cyclic (wave.w+dot(pos,(float3)wave)); - float H = pos.y - base; // height of vertex (scaled, rotated, etc.) - float frac = v.misc.z*consts.x; // fractional (or rigidity) - float inten = H * dp; // intensity - float2 result = calc_xz_wave (wind.xz*inten, frac); - float4 f_pos = float4 (pos.x+result.x, pos.y, pos.z+result.y, 1); - - // Calc fog - o.fog = calc_fogging (f_pos); - - // Final xform - o.HPOS = mul (m_VP, f_pos); - - // Lighting - float3 N = mul (m_xform, unpack_normal(v.nc)); //normalize (mul (m_xform, unpack_normal(v.nc))); - float L_base = v.nc.w; // base hemisphere - float4 L_unpack= c_scale*L_base+c_bias; // unpacked and decompressed - float3 L_rgb = L_unpack.xyz; // precalculated RGB lighting - float3 L_hemi = v_hemi_wrap(N,.75f)* L_unpack.w; // hemisphere - float3 L_sun = v_sun (N)* (L_base*c_sun.x+c_sun.y); // sun - //float3 L_sun = L_sun_color*max( 0, (1+dot(N,-L_sun_dir_w))/2) * (L_base*c_sun.x+c_sun.y)*1.0f; // sun - float3 L_final = L_rgb + L_hemi + L_sun; - o.COL0 = L_final; - - // final xform, color, tc - o.TEX0.xy = (v.misc * consts).xy; - - return o; -} +#include "tree.vs" diff --git a/res/gamedata/shaders/r1/tree_w_dt.vs b/res/gamedata/shaders/r1/tree_w_dt.vs index c08389e010c..765970d0bf2 100644 --- a/res/gamedata/shaders/r1/tree_w_dt.vs +++ b/res/gamedata/shaders/r1/tree_w_dt.vs @@ -1,68 +1,4 @@ -#include "common.h" +#define T_DETAILS +#define TREE_WAVE -struct av -{ - float4 pos : POSITION; // (float,float,float,1) - float4 nc : NORMAL; // (float,float,float,clr) - float4 misc : TEXCOORD0; // (u(Q),v(Q),frac,???) -}; - -struct vf -{ - float4 HPOS : POSITION; - float2 tc0 : TEXCOORD0; - float2 tc1 : TEXCOORD1; // detail - float4 c0 : COLOR0; // c0=all lighting, c0.a needed for details - float4 c1 : COLOR1; // ps_1_1 read ports - float fog : FOG; -}; - -uniform float3x4 m_xform; -uniform float4 consts; // {1/quant,1/quant,???,???} -uniform float4 wave; // cx,cy,cz,tm -uniform float4 wind; // direction2D -uniform float4 c_bias; // + color -uniform float4 c_scale; // * color -uniform float2 c_sun; // x=*, y=+ - -vf main (av v) -{ - vf o; - - // Transform to world coords - float3 pos = mul (m_xform, v.pos); - - // - float base = m_xform._24; // take base height from matrix - float dp = calc_cyclic (wave.w+dot(pos,(float3)wave)); - float H = pos.y - base; // height of vertex (scaled, rotated, etc.) - float frac = v.misc.z*consts.x; // fractional (or rigidity) - float inten = H * dp; // intensity - float2 result = calc_xz_wave (wind.xz*inten, frac); - float4 f_pos = float4(pos.x+result.x, pos.y, pos.z+result.y, 1); - - // Calc fog - o.fog = calc_fogging (f_pos); - - // Final xform - o.HPOS = mul (m_VP, f_pos); - - // Lighting - float3 N = mul (m_xform, unpack_normal(v.nc)); //normalize (mul (m_xform, unpack_normal(v.nc))); - float L_base = v.nc.w; // base hemisphere - float4 L_unpack= c_scale*L_base+c_bias; // unpacked and decompressed - float3 L_rgb = L_unpack.xyz; // precalculated RGB lighting - float3 L_hemi = v_hemi_wrap(N,.75f)* L_unpack.w; // hemisphere - //float3 L_sun = v_sun_wrap (N,.25f)* (L_base*c_sun.x+c_sun.y); // sun - float3 L_sun = v_sun (N)* (L_base*c_sun.x+c_sun.y); // sun - float3 L_final = L_rgb + L_hemi + L_sun; - - // final xform, color, tc - o.tc0.xy = (v.misc * consts).xy; - o.tc1 = o.tc0*dt_params; // dt tc - float2 dt = calc_detail (f_pos); // - o.c0 = float4 (L_final,dt.x); // - o.c1 = dt.y; // - - return o; -} +#include "tree.vs" diff --git a/res/gamedata/shaders/r1/tree_w_point.vs b/res/gamedata/shaders/r1/tree_w_point.vs index 4cef243079a..686221ea287 100644 --- a/res/gamedata/shaders/r1/tree_w_point.vs +++ b/res/gamedata/shaders/r1/tree_w_point.vs @@ -1,41 +1,4 @@ -#include "common.h" +#define DL_POINT +#define T_WAVE -struct av -{ - float4 pos : POSITION; // (float,float,float,1) - float4 nc : NORMAL; // (float,float,float,clr) - float4 misc : TEXCOORD0; // (u(Q),v(Q),frac,???) -}; - -uniform float3x4 m_xform; -uniform float4 consts; // {1/quant,1/quant,???,???} -uniform float4 wave; // cx,cy,cz,tm -uniform float4 wind; // direction2D -uniform float4 c_bias; // + color -uniform float4 c_scale; // * color -uniform float2 c_sun; // x=*, y=+ - -vf_point main (av v) -{ - vf_point o; - - // Transform to world coords - float3 pos = mul (m_xform, v.pos); - - // - float base = m_xform._24; // take base height from matrix - float dp = calc_cyclic (wave.w+dot(pos,(float3)wave)); - float H = pos.y - base; // height of vertex (scaled, rotated, etc.) - float frac = v.misc.z*consts.x; // fractional (or rigidity) - float inten = H * dp; // intensity - float2 result = calc_xz_wave (wind.xz*inten, frac); - float4 f_pos = float4(pos.x+result.x, pos.y, pos.z+result.y, 1); - float3 f_N = normalize (mul (m_xform, unpack_normal(v.nc))); - - // Final xform - o.hpos = mul (m_VP, f_pos); - o.tc0 = (v.misc * consts).xy; - o.color = calc_point (o.tc1,o.tc2,f_pos,f_N); - - return o; -} +#include "shared_dynlight_tree.vs" diff --git a/res/gamedata/shaders/r1/tree_w_point_dt.vs b/res/gamedata/shaders/r1/tree_w_point_dt.vs new file mode 100644 index 00000000000..47773f00faf --- /dev/null +++ b/res/gamedata/shaders/r1/tree_w_point_dt.vs @@ -0,0 +1,5 @@ +#define DL_DETAILS +#define DL_POINT +#define T_WAVE + +#include "shared_dynlight_tree.vs" \ No newline at end of file diff --git a/res/gamedata/shaders/r1/tree_w_spot.vs b/res/gamedata/shaders/r1/tree_w_spot.vs index 64dceca1bbe..7f6dda20d93 100644 --- a/res/gamedata/shaders/r1/tree_w_spot.vs +++ b/res/gamedata/shaders/r1/tree_w_spot.vs @@ -1,41 +1,3 @@ -#include "common.h" +#define T_WAVE -struct av -{ - float4 pos : POSITION; // (float,float,float,1) - float4 nc : NORMAL; // (float,float,float,clr) - float4 misc : TEXCOORD0; // (u(Q),v(Q),frac,???) -}; - -uniform float3x4 m_xform; -uniform float4 consts; // {1/quant,1/quant,???,???} -uniform float4 wave; // cx,cy,cz,tm -uniform float4 wind; // direction2D -uniform float4 c_bias; // + color -uniform float4 c_scale; // * color -uniform float2 c_sun; // x=*, y=+ - -vf_spot main (av v) -{ - vf_spot o; - - // Transform to world coords - float3 pos = mul (m_xform, v.pos); - - // - float base = m_xform._24; // take base height from matrix - float dp = calc_cyclic (wave.w+dot(pos,(float3)wave)); - float H = pos.y - base; // height of vertex (scaled, rotated, etc.) - float frac = v.misc.z*consts.x; // fractional (or rigidity) - float inten = H * dp; // intensity - float2 result = calc_xz_wave (wind.xz*inten, frac); - float4 f_pos = float4(pos.x+result.x, pos.y, pos.z+result.y, 1); - float3 f_N = normalize (mul (m_xform, unpack_normal(v.nc))); - - // Final xform - o.hpos = mul (m_VP, f_pos); - o.tc0 = (v.misc * consts).xy; - o.color = calc_spot (o.tc1,o.tc2,f_pos,f_N); - - return o; -} +#include "shared_dynlight_tree.vs" diff --git a/res/gamedata/shaders/r1/tree_w_spot_dt.vs b/res/gamedata/shaders/r1/tree_w_spot_dt.vs new file mode 100644 index 00000000000..c7806ba24af --- /dev/null +++ b/res/gamedata/shaders/r1/tree_w_spot_dt.vs @@ -0,0 +1,4 @@ +#define DL_DETAILS +#define T_WAVE + +#include "shared_dynlight_tree.vs" \ No newline at end of file diff --git a/res/gamedata/shaders/r1/vert.ps b/res/gamedata/shaders/r1/vert.ps index 3cf53198891..7f971bdbe7e 100644 Binary files a/res/gamedata/shaders/r1/vert.ps and b/res/gamedata/shaders/r1/vert.ps differ diff --git a/res/gamedata/shaders/r1/vert.vs b/res/gamedata/shaders/r1/vert.vs index a6923aae762..387a97dd901 100644 --- a/res/gamedata/shaders/r1/vert.vs +++ b/res/gamedata/shaders/r1/vert.vs @@ -4,7 +4,13 @@ struct vf { float4 hpos : POSITION; float2 tc0 : TEXCOORD0; - float3 c0 : COLOR0; // c0=all lighting +#ifdef T_DETAILS + float2 tcd : TEXCOORD1; // detail + float4 c0 : COLOR0; // xyz=all lighting, w=dt* + float4 c1 : COLOR1; // dt+ +#else + float3 c0 : COLOR0; // all lighting +#endif float fog : FOG; }; @@ -12,18 +18,23 @@ vf main (v_vert v) { vf o; - float3 N = unpack_normal (v.N); - o.hpos = mul (m_VP, v.P); // xform, input in world coords - o.tc0 = unpack_tc_base (v.uv,v.T.w,v.B.w); // copy tc -// o.tc0 = unpack_tc_base (v.tc); // copy tc - + float3 N = unpack_normal(v.N); + o.hpos = mul(m_VP, v.P); // xform, input in world coords + o.tc0 = unpack_tc_base(v.uv0,v.T.w,v.B.w); + float3 L_rgb = v.color.xyz; // precalculated RGB lighting float3 L_hemi = v_hemi(N)*v.N.w; // hemisphere - float3 L_sun = v_sun(N)*v.color.w; // sun + float3 L_sun = v_sun(N)*v.color.w; // sun float3 L_final = L_rgb + L_hemi + L_sun + L_ambient; - - o.c0 = L_final; - o.fog = calc_fogging (v.P); // fog, input in world coords +#ifdef T_DETAILS + float2 dt = calc_detail(v.P); + o.tcd = o.tc0*dt_params; // dt tc + o.c0 = float4(L_final,dt.x); // xyz=all lighting, w=dt* + o.c1 = dt.y; // dt+ +#else + o.c0 = L_final; // c0=all lighting +#endif + o.fog = calc_fogging(v.P); // fog, input in world coords return o; } diff --git a/res/gamedata/shaders/r1/vert_dt.ps b/res/gamedata/shaders/r1/vert_dt.ps index 04e210cc54a..5b7efb7acf9 100644 Binary files a/res/gamedata/shaders/r1/vert_dt.ps and b/res/gamedata/shaders/r1/vert_dt.ps differ diff --git a/res/gamedata/shaders/r1/vert_dt.vs b/res/gamedata/shaders/r1/vert_dt.vs index 4ca34d49d91..342e519d31f 100644 --- a/res/gamedata/shaders/r1/vert_dt.vs +++ b/res/gamedata/shaders/r1/vert_dt.vs @@ -1,35 +1,3 @@ -#include "common.h" +#define T_DETAILS -struct vf -{ - float4 hpos : POSITION; - float2 tc0 : TEXCOORD0; - float2 tc1 : TEXCOORD1; // detail - float4 c0 : COLOR0; // c0=all lighting - float4 c1 : COLOR1; // ps_1_1 read ports - float fog : FOG; -}; - -vf main (v_vert v) -{ - vf o; - - float3 N = unpack_normal (v.N); - o.hpos = mul (m_VP, v.P); // xform, input in world coords - o.tc0 = unpack_tc_base (v.uv,v.T.w,v.B.w); // copy tc -// o.tc0 = unpack_tc_base (v.tc); // copy tc - o.tc1 = o.tc0*dt_params; // dt tc - - float3 L_rgb = v.color.xyz; // precalculated RGB lighting - float3 L_hemi = v_hemi(N)*v.N.w; // hemisphere - float3 L_sun = v_sun(N)*v.color.w; // sun - float3 L_final = L_rgb + L_hemi + L_sun + L_ambient; - - float2 dt = calc_detail (v.P); - - o.c0 = float4(L_final.x,L_final.y,L_final.z,dt.x); - o.c1 = dt.y; // - o.fog = calc_fogging (v.P); // fog, input in world coords - - return o; -} +#include "vert.vs" diff --git a/res/gamedata/shaders/r1/vert_point.vs b/res/gamedata/shaders/r1/vert_point.vs index a9243109cae..ca270db28ff 100644 --- a/res/gamedata/shaders/r1/vert_point.vs +++ b/res/gamedata/shaders/r1/vert_point.vs @@ -1,13 +1,3 @@ -#include "common.h" +#define DL_POINT -vf_point main (v_vert v) -{ - vf_point o; - - o.hpos = mul (m_VP, v.P); // xform, input in world coords - o.tc0 = unpack_tc_base (v.uv,v.T.w,v.B.w); // copy tc -// o.tc0 = unpack_tc_base (v.tc); // copy tc - o.color = calc_point (o.tc1,o.tc2,v.P,unpack_normal(v.N)); // just hemisphere - - return o; -} +#include "shared_dynlight.vs" diff --git a/res/gamedata/shaders/r1/vert_point_dt.vs b/res/gamedata/shaders/r1/vert_point_dt.vs new file mode 100644 index 00000000000..529869eb786 --- /dev/null +++ b/res/gamedata/shaders/r1/vert_point_dt.vs @@ -0,0 +1,4 @@ +#define DL_DETAILS +#define DL_POINT + +#include "shared_dynlight.vs" \ No newline at end of file diff --git a/res/gamedata/shaders/r1/vert_spot.vs b/res/gamedata/shaders/r1/vert_spot.vs index 1a302aa6545..f1767faa96e 100644 --- a/res/gamedata/shaders/r1/vert_spot.vs +++ b/res/gamedata/shaders/r1/vert_spot.vs @@ -1,13 +1 @@ -#include "common.h" - -vf_spot main (v_vert v) -{ - vf_spot o; - - o.hpos = mul (m_VP, v.P); // xform, input in world coords - o.tc0 = unpack_tc_base (v.uv,v.T.w,v.B.w); // copy tc -// o.tc0 = unpack_tc_base (v.tc); // copy tc - o.color = calc_spot (o.tc1,o.tc2,v.P,unpack_normal(v.N)); // just hemisphere - - return o; -} +#include "shared_dynlight.vs" diff --git a/res/gamedata/shaders/r1/vert_spot_dt.vs b/res/gamedata/shaders/r1/vert_spot_dt.vs new file mode 100644 index 00000000000..5874807099e --- /dev/null +++ b/res/gamedata/shaders/r1/vert_spot_dt.vs @@ -0,0 +1,3 @@ +#define DL_DETAILS + +#include "shared_dynlight.vs" \ No newline at end of file diff --git a/res/gamedata/shaders/r1/water.vs b/res/gamedata/shaders/r1/water.vs index ce7a82a282a..5aac0d44f64 100644 --- a/res/gamedata/shaders/r1/water.vs +++ b/res/gamedata/shaders/r1/water.vs @@ -20,7 +20,7 @@ vf main (v_vert v) P = watermove (P); - float2 tc_base = unpack_tc_base (v.uv,v.T.w,v.B.w); // copy tc + float2 tc_base = unpack_tc_base (v.uv0,v.T.w,v.B.w); // copy tc float amount ; float3 tc_refl = waterrefl (amount, P,N); diff --git a/res/gamedata/shaders/r1/waterd.vs b/res/gamedata/shaders/r1/waterd.vs index 57575056d70..a5a099d2208 100644 --- a/res/gamedata/shaders/r1/waterd.vs +++ b/res/gamedata/shaders/r1/waterd.vs @@ -18,7 +18,7 @@ vf main (v_vert v) float3 N = unpack_normal (v.N); P = watermove (P); - o.tbase = unpack_tc_base (v.uv,v.T.w,v.B.w); // copy tc + o.tbase = unpack_tc_base (v.uv0,v.T.w,v.B.w); // copy tc o.tdist0 = watermove_tc (o.tbase*W_DISTORT_BASE_TILE_0, P.xz, W_DISTORT_AMP_0); o.tdist1 = watermove_tc (o.tbase*W_DISTORT_BASE_TILE_1, P.xz, W_DISTORT_AMP_1); o.hpos = mul (m_VP, P); // xform, input in world coords diff --git a/res/gamedata/shaders/r1/wmark.vs b/res/gamedata/shaders/r1/wmark.vs index 5559cd877ab..1de01d4d28f 100644 --- a/res/gamedata/shaders/r1/wmark.vs +++ b/res/gamedata/shaders/r1/wmark.vs @@ -19,7 +19,7 @@ vf main (v_vert v) float3 N = unpack_normal (v.N); float4 P = wmark_shift (v.P,N); o.hpos = mul (m_VP, P); // xform, input in world coords - o.tc0 = unpack_tc_base (v.uv,v.T.w,v.B.w); // copy tc + o.tc0 = unpack_tc_base (v.uv0,v.T.w,v.B.w); // copy tc float3 L_rgb = v.color.xyz; // precalculated RGB lighting float3 L_hemi = v_hemi(N)*v.N.w; // hemisphere diff --git a/res/gamedata/shaders/r1/wmark_point.vs b/res/gamedata/shaders/r1/wmark_point.vs index cc188a818f7..5634d04a60b 100644 --- a/res/gamedata/shaders/r1/wmark_point.vs +++ b/res/gamedata/shaders/r1/wmark_point.vs @@ -1,15 +1,6 @@ -#include "common.h" #include "shared\wmark.h" -vf_point main (v_vert v) -{ - vf_point o; +#define DL_WMARK +#define DL_POINT - float3 N = unpack_normal (v.N); - float4 P = wmark_shift (v.P,N); - o.hpos = mul (m_VP, P); // xform, input in world coords - o.tc0 = unpack_tc_base (v.uv,v.T.w,v.B.w); // copy tc - o.color = calc_point (o.tc1,o.tc2,P,N); // just hemisphere - - return o; -} +#include "shared_dynlight.vs" diff --git a/res/gamedata/shaders/r1/wmark_spot.vs b/res/gamedata/shaders/r1/wmark_spot.vs index dcf6578c91c..15b770b6d0f 100644 --- a/res/gamedata/shaders/r1/wmark_spot.vs +++ b/res/gamedata/shaders/r1/wmark_spot.vs @@ -1,15 +1,5 @@ -#include "common.h" #include "shared\wmark.h" -vf_spot main (v_vert v) -{ - vf_spot o; +#define DL_WMARK - float3 N = unpack_normal (v.N); - float4 P = wmark_shift (v.P,N); - o.hpos = mul (m_VP, P); // xform, input in world coords - o.tc0 = unpack_tc_base (v.uv,v.T.w,v.B.w); // copy tc - o.color = calc_spot (o.tc1,o.tc2,P,N); // just hemisphere - - return o; -} +#include "shared_dynlight.vs" diff --git a/src/Layers/xrRender/Blender_BmmD.cpp b/src/Layers/xrRender/Blender_BmmD.cpp index af8c703acad..f77ef1bc4d2 100644 --- a/src/Layers/xrRender/Blender_BmmD.cpp +++ b/src/Layers/xrRender/Blender_BmmD.cpp @@ -90,8 +90,8 @@ void CBlender_BmmD::Compile(CBlender_Compile& C) } else { - if (C.L_textures.size() < 2) - xrDebug::Fatal(DEBUG_INFO, "Not enought textures for shader, base tex: %s", *C.L_textures[0]); + R_ASSERT3(C.L_textures.size() >= 2, "Not enought textures for shader, base tex: %s", *C.L_textures[0]); + switch (C.iElement) { case SE_R1_NORMAL_HQ: @@ -109,17 +109,19 @@ void CBlender_BmmD::Compile(CBlender_Compile& C) C.r_End(); break; case SE_R1_LPOINT: - C.r_Pass("impl_point", "add_point", FALSE, TRUE, FALSE, TRUE, D3DBLEND_ONE, D3DBLEND_ONE, TRUE); + C.r_Pass("impl_point_dt", "add_point_dt", FALSE, TRUE, FALSE, TRUE, D3DBLEND_ONE, D3DBLEND_ONE, TRUE); C.r_Sampler("s_base", C.L_textures[0]); C.r_Sampler_clf("s_lmap", TEX_POINT_ATT); C.r_Sampler_clf("s_att", TEX_POINT_ATT); + C.r_Sampler("s_detail", oT2_Name); C.r_End(); break; case SE_R1_LSPOT: - C.r_Pass("impl_spot", "add_spot", FALSE, TRUE, FALSE, TRUE, D3DBLEND_ONE, D3DBLEND_ONE, TRUE); + C.r_Pass("impl_spot_dt", "add_spot_dt", FALSE, TRUE, FALSE, TRUE, D3DBLEND_ONE, D3DBLEND_ONE, TRUE); C.r_Sampler("s_base", C.L_textures[0]); C.r_Sampler_clf("s_lmap", "internal\\internal_light_att", true); C.r_Sampler_clf("s_att", TEX_SPOT_ATT); + C.r_Sampler("s_detail", oT2_Name); C.r_End(); break; case SE_R1_LMODELS: diff --git a/src/Layers/xrRender/Blender_tree.cpp b/src/Layers/xrRender/Blender_tree.cpp index 4b15d4dd7be..a9a0f0d4455 100644 --- a/src/Layers/xrRender/Blender_tree.cpp +++ b/src/Layers/xrRender/Blender_tree.cpp @@ -67,94 +67,110 @@ void CBlender_Tree::Compile(CBlender_Compile& C) } else { - u32 tree_aref = 200; - if (oNotAnTree.value) - tree_aref = 0; + u32 tree_aref = oNotAnTree.value ? 0 : 200; + D3DBLEND blend_src, blend_dst; + if (oBlend.value) + { + blend_src = D3DBLEND_SRCALPHA; + blend_dst = D3DBLEND_INVSRCALPHA; + } + else + { + blend_src = D3DBLEND_ONE; + blend_dst = D3DBLEND_ZERO; + } - switch (C.iElement) + LPCSTR tsv_hq, tsp_hq; + LPCSTR tsv_point, tsv_spot, tsp_point, tsp_spot; + if (C.bDetail_Diffuse) { - case SE_R1_NORMAL_HQ: if (oNotAnTree.value) { - // Level view - LPCSTR tsv = "tree_s", tsp = "vert"; - if (C.bDetail_Diffuse) - { - tsv = "tree_s_dt"; - tsp = "vert_dt"; - } - if (oBlend.value) - C.r_Pass( - tsv, tsp, TRUE, TRUE, TRUE, TRUE, D3DBLEND_SRCALPHA, D3DBLEND_INVSRCALPHA, TRUE, tree_aref); - else - C.r_Pass(tsv, tsp, TRUE, TRUE, TRUE, TRUE, D3DBLEND_ONE, D3DBLEND_ZERO, TRUE, tree_aref); - C.r_Sampler("s_base", C.L_textures[0]); - C.r_Sampler("s_detail", C.detail_texture); - C.r_End(); + tsv_hq = "tree_s_dt"; + tsv_point = "tree_s_point_dt"; + tsv_spot = "tree_s_spot_dt"; } else { - // Level view - if (C.bDetail_Diffuse) - { - if (oBlend.value) - C.r_Pass("tree_w_dt", "vert_dt", TRUE, TRUE, TRUE, TRUE, D3DBLEND_SRCALPHA, - D3DBLEND_INVSRCALPHA, TRUE, tree_aref); - else - C.r_Pass("tree_w_dt", "vert_dt", TRUE, TRUE, TRUE, TRUE, D3DBLEND_ONE, D3DBLEND_ZERO, TRUE, - tree_aref); - C.r_Sampler("s_base", C.L_textures[0]); - C.r_Sampler("s_detail", C.detail_texture); - C.r_End(); - } - else - { - if (oBlend.value) - C.r_Pass("tree_w", "vert", TRUE, TRUE, TRUE, TRUE, D3DBLEND_SRCALPHA, D3DBLEND_INVSRCALPHA, - TRUE, tree_aref); - else - C.r_Pass( - "tree_w", "vert", TRUE, TRUE, TRUE, TRUE, D3DBLEND_ONE, D3DBLEND_ZERO, TRUE, tree_aref); - C.r_Sampler("s_base", C.L_textures[0]); - C.r_Sampler("s_detail", C.detail_texture); - C.r_End(); - } + tsv_hq = "tree_w_dt"; + tsv_point = "tree_w_point_dt"; + tsv_spot = "tree_w_spot_dt"; } - break; + tsp_hq = "vert_dt"; + tsp_point = "add_point_dt"; + tsp_spot = "add_spot_dt"; + } + else + { + if (oNotAnTree.value) + { + tsv_hq = "tree_s"; + tsv_point = "tree_s_point"; + tsv_spot = "tree_s_spot"; + } + else + { + tsv_hq = "tree_w"; + tsv_point = "tree_w_point"; + tsv_spot = "tree_w_spot"; + } + tsp_hq = "vert"; + tsp_point = "add_point"; + tsp_spot = "add_spot"; + } + + switch (C.iElement) + { + case SE_R1_NORMAL_HQ: + { + // Level view + C.r_Pass(tsv_hq, tsp_hq, TRUE, TRUE, TRUE, TRUE, blend_src, blend_dst, TRUE, tree_aref); + C.r_Sampler("s_base", C.L_textures[0]); + if (C.bDetail_Diffuse) + C.r_Sampler("s_detail", C.detail_texture); + C.r_End(); + } + break; case SE_R1_NORMAL_LQ: + { // Level view - if (oBlend.value) - C.r_Pass( - "tree_s", "vert", TRUE, TRUE, TRUE, TRUE, D3DBLEND_SRCALPHA, D3DBLEND_INVSRCALPHA, TRUE, tree_aref); - else - C.r_Pass("tree_s", "vert", TRUE, TRUE, TRUE, TRUE, D3DBLEND_ONE, D3DBLEND_ZERO, TRUE, tree_aref); + C.r_Pass("tree_s", "vert", TRUE, TRUE, TRUE, TRUE, blend_src, blend_dst, TRUE, tree_aref); C.r_Sampler("s_base", C.L_textures[0]); C.r_End(); - break; + } + break; case SE_R1_LPOINT: - C.r_Pass((oNotAnTree.value) ? "tree_s_point" : "tree_w_point", "add_point", FALSE, TRUE, FALSE, TRUE, - D3DBLEND_ONE, D3DBLEND_ONE, TRUE, 0); + { + C.r_Pass(tsv_point, tsp_point, FALSE, TRUE, FALSE, TRUE, D3DBLEND_ONE, D3DBLEND_ONE, TRUE, 0); C.r_Sampler("s_base", C.L_textures[0]); C.r_Sampler_clf("s_lmap", TEX_POINT_ATT); C.r_Sampler_clf("s_att", TEX_POINT_ATT); + if (C.bDetail_Diffuse) + C.r_Sampler("s_detail", C.detail_texture); C.r_End(); - break; + } + break; case SE_R1_LSPOT: - C.r_Pass((oNotAnTree.value) ? "tree_s_spot" : "tree_w_spot", "add_spot", FALSE, TRUE, FALSE, TRUE, - D3DBLEND_ONE, D3DBLEND_ONE, TRUE, 0); + { + C.r_Pass(tsv_spot, tsp_spot, FALSE, TRUE, FALSE, TRUE, D3DBLEND_ONE, D3DBLEND_ONE, TRUE, 0); C.r_Sampler("s_base", C.L_textures[0]); C.r_Sampler_clf("s_lmap", "internal\\internal_light_att", true); C.r_Sampler_clf("s_att", TEX_SPOT_ATT); + if (C.bDetail_Diffuse) + C.r_Sampler("s_detail", C.detail_texture); C.r_End(); - break; + } + break; case SE_R1_LMODELS: + { /* Don't use lighting from flora - strange visual results // Lighting only - C.r_Pass ("tree_wave","vert_l",FALSE); - C.r_Sampler ("s_base",C.L_textures[0]); - C.r_End (); + C.r_Pass ("tree_wave","vert_l",FALSE); + C.r_Sampler ("s_base",C.L_textures[0]); + C.r_End (); */ - break; + } + break; } } } diff --git a/src/Layers/xrRender/ResourceManager.cpp b/src/Layers/xrRender/ResourceManager.cpp index 5a716e1831e..83469c63933 100644 --- a/src/Layers/xrRender/ResourceManager.cpp +++ b/src/Layers/xrRender/ResourceManager.cpp @@ -206,49 +206,47 @@ Shader* CResourceManager::_cpp_Create( // Compile element (LOD0 - HQ) { - C.iElement = 0; + C.iElement = SE_R1_NORMAL_HQ; C.bDetail = m_textures_description.GetDetailTexture(C.L_textures[0], C.detail_texture, C.detail_scaler); - //. C.bDetail = _GetDetailTexture(*C.L_textures[0],C.detail_texture,C.detail_scaler); ShaderElement E; C._cpp_Compile(&E); - S.E[0] = _CreateElement(E); + S.E[C.iElement] = _CreateElement(E); } // Compile element (LOD1) { - C.iElement = 1; - //. C.bDetail = _GetDetailTexture(*C.L_textures[0],C.detail_texture,C.detail_scaler); + C.iElement = SE_R1_NORMAL_LQ; C.bDetail = m_textures_description.GetDetailTexture(C.L_textures[0], C.detail_texture, C.detail_scaler); ShaderElement E; C._cpp_Compile(&E); - S.E[1] = _CreateElement(E); + S.E[C.iElement] = _CreateElement(E); } // Compile element { - C.iElement = 2; - C.bDetail = FALSE; + C.iElement = SE_R1_LPOINT; + C.bDetail = m_textures_description.GetDetailTexture(C.L_textures[0], C.detail_texture, C.detail_scaler); ShaderElement E; C._cpp_Compile(&E); - S.E[2] = _CreateElement(E); + S.E[C.iElement] = _CreateElement(E); } // Compile element { - C.iElement = 3; - C.bDetail = FALSE; + C.iElement = SE_R1_LSPOT; + C.bDetail = m_textures_description.GetDetailTexture(C.L_textures[0], C.detail_texture, C.detail_scaler); ShaderElement E; C._cpp_Compile(&E); - S.E[3] = _CreateElement(E); + S.E[C.iElement] = _CreateElement(E); } // Compile element { - C.iElement = 4; + C.iElement = SE_R1_LMODELS; C.bDetail = TRUE; //.$$$ HACK :) ShaderElement E; C._cpp_Compile(&E); - S.E[4] = _CreateElement(E); + S.E[C.iElement] = _CreateElement(E); } // Compile element @@ -257,7 +255,7 @@ Shader* CResourceManager::_cpp_Create( C.bDetail = FALSE; ShaderElement E; C._cpp_Compile(&E); - S.E[5] = _CreateElement(E); + S.E[C.iElement] = _CreateElement(E); } // Search equal in shaders array diff --git a/src/Layers/xrRender/ResourceManager_Scripting.cpp b/src/Layers/xrRender/ResourceManager_Scripting.cpp index 2e0c999a225..59741a26433 100644 --- a/src/Layers/xrRender/ResourceManager_Scripting.cpp +++ b/src/Layers/xrRender/ResourceManager_Scripting.cpp @@ -342,56 +342,50 @@ Shader* CResourceManager::_lua_Create(LPCSTR d_shader, LPCSTR s_textures) if (ScriptEngine.object(s_shader, "normal_hq", LUA_TFUNCTION)) { // Analyze possibility to detail this shader - C.iElement = 0; + C.iElement = SE_R1_NORMAL_HQ; C.bDetail = m_textures_description.GetDetailTexture(C.L_textures[0], C.detail_texture, C.detail_scaler); - - if (C.bDetail) - S.E[0] = C._lua_Compile(s_shader, "normal_hq"); - else - S.E[0] = C._lua_Compile(s_shader, "normal"); + S.E[C.iElement] = C._lua_Compile(s_shader, C.bDetail ? "normal_hq" : "normal"); } else { if (ScriptEngine.object(s_shader, "normal", LUA_TFUNCTION)) { - C.iElement = 0; + C.iElement = SE_R1_NORMAL_HQ; C.bDetail = m_textures_description.GetDetailTexture(C.L_textures[0], C.detail_texture, C.detail_scaler); - S.E[0] = C._lua_Compile(s_shader, "normal"); + S.E[C.iElement] = C._lua_Compile(s_shader, "normal"); } } // Compile element (LOD1) if (ScriptEngine.object(s_shader, "normal", LUA_TFUNCTION)) { - C.iElement = 1; + C.iElement = SE_R1_NORMAL_LQ; C.bDetail = m_textures_description.GetDetailTexture(C.L_textures[0], C.detail_texture, C.detail_scaler); - S.E[1] = C._lua_Compile(s_shader, "normal"); + S.E[C.iElement] = C._lua_Compile(s_shader, "normal"); } // Compile element if (ScriptEngine.object(s_shader, "l_point", LUA_TFUNCTION)) { - C.iElement = 2; - C.bDetail = FALSE; - S.E[2] = C._lua_Compile(s_shader, "l_point"); - ; + C.iElement = SE_R1_LPOINT; + C.bDetail = m_textures_description.GetDetailTexture(C.L_textures[0], C.detail_texture, C.detail_scaler); + S.E[C.iElement] = C._lua_Compile(s_shader, "l_point"); } // Compile element if (ScriptEngine.object(s_shader, "l_spot", LUA_TFUNCTION)) { - C.iElement = 3; - C.bDetail = FALSE; - S.E[3] = C._lua_Compile(s_shader, "l_spot"); - ; + C.iElement = SE_R1_LSPOT; + C.bDetail = m_textures_description.GetDetailTexture(C.L_textures[0], C.detail_texture, C.detail_scaler); + S.E[C.iElement] = C._lua_Compile(s_shader, "l_spot"); } // Compile element if (ScriptEngine.object(s_shader, "l_special", LUA_TFUNCTION)) { - C.iElement = 4; + C.iElement = SE_R1_LMODELS; C.bDetail = FALSE; - S.E[4] = C._lua_Compile(s_shader, "l_special"); + S.E[C.iElement] = C._lua_Compile(s_shader, "l_special"); } // Search equal in shaders array diff --git a/src/Layers/xrRenderPC_R1/BlenderDefault.cpp b/src/Layers/xrRenderPC_R1/BlenderDefault.cpp index 8f2e0e38fc6..d2460b0bb2a 100644 --- a/src/Layers/xrRenderPC_R1/BlenderDefault.cpp +++ b/src/Layers/xrRenderPC_R1/BlenderDefault.cpp @@ -68,59 +68,85 @@ void CBlender_default::Compile(CBlender_Compile& C) } else { - if (C.L_textures.size() < 3) - xrDebug::Fatal(DEBUG_INFO, "Not enought textures for shader, base tex: %s", *C.L_textures[0]); + R_ASSERT3(C.L_textures.size() >= 3, "Not enought textures for shader, base tex: %s", *C.L_textures[0]); + + LPCSTR tsv_hq, tsp_hq; + LPCSTR tsv_point, tsv_spot, tsp_point, tsp_spot; + if (C.bDetail_Diffuse) + { + tsv_hq = "lmap_dt"; + tsv_point = "lmap_point_dt"; + tsv_spot = "lmap_spot_dt"; + + tsp_hq = "lmap_dt"; + tsp_point = "add_point_dt"; + tsp_spot = "add_spot_dt"; + } + else + { + tsv_hq = "lmap"; + tsv_point = "lmap_point"; + tsv_spot = "lmap_spot"; + + tsp_hq = "lmap"; + tsp_point = "add_point"; + tsp_spot = "add_spot"; + } + switch (C.iElement) { case SE_R1_NORMAL_HQ: + { // Level view - if (C.bDetail_Diffuse) - { - C.r_Pass("lmap_dt", "lmap_dt", TRUE); - C.r_Sampler("s_base", C.L_textures[0]); - C.r_Sampler("s_lmap", C.L_textures[1]); - C.r_Sampler("s_detail", C.detail_texture); - C.r_Sampler_clf("s_hemi", *C.L_textures[2]); - C.r_End(); - } - else - { - C.r_Pass("lmap", "lmap", TRUE); - C.r_Sampler("s_base", C.L_textures[0]); - C.r_Sampler("s_lmap", C.L_textures[1]); - C.r_Sampler_clf("s_hemi", *C.L_textures[2]); - C.r_End(); - } - break; + C.r_Pass(tsv_hq, tsp_hq, TRUE); + C.r_Sampler("s_base", C.L_textures[0]); + C.r_Sampler("s_lmap", C.L_textures[1]); + C.r_Sampler("s_detail", C.detail_texture); + C.r_Sampler_clf("s_hemi", *C.L_textures[2]); + C.r_End(); + } + break; case SE_R1_NORMAL_LQ: + { C.r_Pass("lmap", "lmap", TRUE); C.r_Sampler("s_base", C.L_textures[0]); C.r_Sampler("s_lmap", C.L_textures[1]); C.r_Sampler_clf("s_hemi", *C.L_textures[2]); C.r_End(); - break; + } + break; case SE_R1_LPOINT: - C.r_Pass("lmap_point", "add_point", FALSE, TRUE, FALSE, TRUE, D3DBLEND_ONE, D3DBLEND_ONE, TRUE); + { + C.r_Pass(tsv_point, tsp_point, FALSE, TRUE, FALSE, TRUE, D3DBLEND_ONE, D3DBLEND_ONE, TRUE); C.r_Sampler("s_base", C.L_textures[0]); C.r_Sampler_clf("s_lmap", TEX_POINT_ATT); C.r_Sampler_clf("s_att", TEX_POINT_ATT); + if (C.bDetail_Diffuse) + C.r_Sampler("s_detail", C.detail_texture); C.r_End(); - break; + } + break; case SE_R1_LSPOT: - C.r_Pass("lmap_spot", "add_spot", FALSE, TRUE, FALSE, TRUE, D3DBLEND_ONE, D3DBLEND_ONE, TRUE); + { + C.r_Pass(tsv_spot, tsp_spot, FALSE, TRUE, FALSE, TRUE, D3DBLEND_ONE, D3DBLEND_ONE, TRUE); C.r_Sampler("s_base", C.L_textures[0]); C.r_Sampler_clf("s_lmap", "internal\\internal_light_att", true); C.r_Sampler_clf("s_att", TEX_SPOT_ATT); + if (C.bDetail_Diffuse) + C.r_Sampler("s_detail", C.detail_texture); C.r_End(); - break; + } + break; case SE_R1_LMODELS: + { // Lighting only, not use alpha-channel C.r_Pass("lmap_l", "lmap_l", FALSE); C.r_Sampler("s_base", C.L_textures[0]); C.r_Sampler("s_lmap", C.L_textures[1]); C.r_Sampler_clf("s_hemi", *C.L_textures[2]); C.r_End(); - break; + } + break; } } } diff --git a/src/Layers/xrRenderPC_R1/Blender_Model.cpp b/src/Layers/xrRenderPC_R1/Blender_Model.cpp index cff032a07e1..a7ca89e35c5 100644 --- a/src/Layers/xrRenderPC_R1/Blender_Model.cpp +++ b/src/Layers/xrRenderPC_R1/Blender_Model.cpp @@ -88,59 +88,79 @@ void CBlender_Model::Compile(CBlender_Compile& C) } else { - LPCSTR vsname = nullptr; - LPCSTR psname = nullptr; + LPCSTR tsv_hq, tsp_hq; + LPCSTR tsv_point, tsv_spot, tsp_point, tsp_spot; + if (C.bDetail_Diffuse) + { + tsv_hq = "model_def_hq_dt"; + tsv_point = "model_def_point_dt"; + tsv_spot = "model_def_spot_dt"; + + tsp_hq = "model_def_hq_dt"; + tsp_point = "add_point_dt"; + tsp_spot = "add_spot_dt"; + } + else + { + tsv_hq = "model_def_hq"; + tsv_point = "model_def_point"; + tsv_spot = "model_def_spot"; + + tsp_hq = "model_def_hq"; + tsp_point = "add_point"; + tsp_spot = "add_spot"; + } + switch (C.iElement) { case SE_R1_NORMAL_HQ: - vsname = psname = "model_def_hq"; if (oBlend.value) C.r_Pass( - vsname, psname, TRUE, TRUE, TRUE, TRUE, D3DBLEND_SRCALPHA, D3DBLEND_INVSRCALPHA, TRUE, oAREF.value); + tsv_hq, tsp_hq, TRUE, TRUE, TRUE, TRUE, D3DBLEND_SRCALPHA, D3DBLEND_INVSRCALPHA, TRUE, oAREF.value); else - C.r_Pass(vsname, psname, TRUE); + C.r_Pass(tsv_hq, tsp_hq, TRUE); C.r_Sampler("s_base", C.L_textures[0]); C.r_Sampler_clf("s_lmap", "$user$projector", true); + if (C.bDetail_Diffuse) + C.r_Sampler("s_detail", C.detail_texture); C.r_End(); break; case SE_R1_NORMAL_LQ: - vsname = psname = "model_def_lq"; if (oBlend.value) - C.r_Pass( - vsname, psname, TRUE, TRUE, TRUE, TRUE, D3DBLEND_SRCALPHA, D3DBLEND_INVSRCALPHA, TRUE, oAREF.value); + C.r_Pass("model_def_lq", "model_def_lq", TRUE, TRUE, TRUE, TRUE, D3DBLEND_SRCALPHA, + D3DBLEND_INVSRCALPHA, TRUE, oAREF.value); else - C.r_Pass(vsname, psname, TRUE); + C.r_Pass("model_def_lq", "model_def_lq", TRUE); C.r_Sampler("s_base", C.L_textures[0]); C.r_End(); break; case SE_R1_LPOINT: - vsname = "model_def_point"; - psname = "add_point"; if (oBlend.value) - C.r_Pass(vsname, psname, FALSE, TRUE, FALSE, TRUE, D3DBLEND_ONE, D3DBLEND_ONE, TRUE, oAREF.value); + C.r_Pass(tsv_point, tsp_point, FALSE, TRUE, FALSE, TRUE, D3DBLEND_ONE, D3DBLEND_ONE, TRUE, oAREF.value); else - C.r_Pass(vsname, psname, FALSE, TRUE, FALSE, TRUE, D3DBLEND_ONE, D3DBLEND_ONE, TRUE); + C.r_Pass(tsv_point, tsp_point, FALSE, TRUE, FALSE, TRUE, D3DBLEND_ONE, D3DBLEND_ONE, TRUE); C.r_Sampler("s_base", C.L_textures[0]); C.r_Sampler_clf("s_lmap", TEX_POINT_ATT); C.r_Sampler_clf("s_att", TEX_POINT_ATT); + if (C.bDetail_Diffuse) + C.r_Sampler("s_detail", C.detail_texture); C.r_End(); break; case SE_R1_LSPOT: - vsname = "model_def_spot"; - psname = "add_spot"; if (oBlend.value) - C.r_Pass(vsname, psname, FALSE, TRUE, FALSE, TRUE, D3DBLEND_ONE, D3DBLEND_ONE, TRUE, oAREF.value); + C.r_Pass(tsv_spot, tsp_spot, FALSE, TRUE, FALSE, TRUE, D3DBLEND_ONE, D3DBLEND_ONE, TRUE, oAREF.value); else - C.r_Pass(vsname, psname, FALSE, TRUE, FALSE, TRUE, D3DBLEND_ONE, D3DBLEND_ONE, TRUE); + C.r_Pass(tsv_spot, tsp_spot, FALSE, TRUE, FALSE, TRUE, D3DBLEND_ONE, D3DBLEND_ONE, TRUE); C.r_Sampler("s_base", C.L_textures[0]); C.r_Sampler_clf("s_lmap", "internal\\internal_light_att", true); C.r_Sampler_clf("s_att", TEX_SPOT_ATT); + if (C.bDetail_Diffuse) + C.r_Sampler("s_detail", C.detail_texture); C.r_End(); break; case SE_R1_LMODELS: - vsname = "model_def_shadow"; - psname = "model_shadow"; - C.r_Pass(vsname, psname, FALSE, FALSE, FALSE, TRUE, D3DBLEND_ZERO, D3DBLEND_SRCCOLOR, FALSE, 0); + C.r_Pass("model_def_shadow", "model_shadow", FALSE, FALSE, FALSE, TRUE, D3DBLEND_ZERO, D3DBLEND_SRCCOLOR, + FALSE, 0); C.r_End(); break; } diff --git a/src/Layers/xrRenderPC_R1/Blender_Model.h b/src/Layers/xrRenderPC_R1/Blender_Model.h index afd2dae0c06..9d58e944207 100644 --- a/src/Layers/xrRenderPC_R1/Blender_Model.h +++ b/src/Layers/xrRenderPC_R1/Blender_Model.h @@ -15,6 +15,7 @@ class CBlender_Model : public IBlender public: virtual LPCSTR getComment() { return "MODEL: Default"; } virtual BOOL canBeLMAPped() { return FALSE; } + virtual BOOL canBeDetailed() { return TRUE; } virtual void Save(IWriter& fs); virtual void Load(IReader& fs, u16 version); diff --git a/src/Layers/xrRenderPC_R1/Blender_Vertex.cpp b/src/Layers/xrRenderPC_R1/Blender_Vertex.cpp index 6c25c458f91..aa636235ad1 100644 --- a/src/Layers/xrRenderPC_R1/Blender_Vertex.cpp +++ b/src/Layers/xrRenderPC_R1/Blender_Vertex.cpp @@ -74,50 +74,79 @@ void CBlender_Vertex::Compile(CBlender_Compile& C) } else { + LPCSTR tsv_hq, tsp_hq; + LPCSTR tsv_point, tsv_spot, tsp_point, tsp_spot; + if (C.bDetail_Diffuse) + { + tsv_hq = "vert_dt"; + tsv_point = "vert_point_dt"; + tsv_spot = "vert_spot_dt"; + + tsp_hq = "vert_dt"; + tsp_point = "add_point_dt"; + tsp_spot = "add_spot_dt"; + } + else + { + tsv_hq = "vert"; + tsv_point = "vert_point"; + tsv_spot = "vert_spot"; + + tsp_hq = "vert"; + tsp_point = "add_point"; + tsp_spot = "add_spot"; + } + switch (C.iElement) { case SE_R1_NORMAL_HQ: + { // Level view + C.r_Pass(tsv_hq, tsp_hq, TRUE); + C.r_Sampler("s_base", C.L_textures[0]); if (C.bDetail_Diffuse) - { - C.r_Pass("vert_dt", "vert_dt", TRUE); - C.r_Sampler("s_base", C.L_textures[0]); C.r_Sampler("s_detail", C.detail_texture); - C.r_End(); - } - else - { - C.r_Pass("vert", "vert", TRUE); - C.r_Sampler("s_base", C.L_textures[0]); - C.r_End(); - } - break; + C.r_End(); + } + break; case SE_R1_NORMAL_LQ: + { // Level view C.r_Pass("vert", "vert", TRUE); C.r_Sampler("s_base", C.L_textures[0]); C.r_End(); - break; + } + break; case SE_R1_LPOINT: - C.r_Pass("vert_point", "add_point", FALSE, TRUE, FALSE, TRUE, D3DBLEND_ONE, D3DBLEND_ONE, TRUE); + { + C.r_Pass(tsv_point, tsp_point, FALSE, TRUE, FALSE, TRUE, D3DBLEND_ONE, D3DBLEND_ONE, TRUE); C.r_Sampler("s_base", C.L_textures[0]); C.r_Sampler_clf("s_lmap", TEX_POINT_ATT); C.r_Sampler_clf("s_att", TEX_POINT_ATT); + if (C.bDetail_Diffuse) + C.r_Sampler("s_detail", C.detail_texture); C.r_End(); - break; + } + break; case SE_R1_LSPOT: - C.r_Pass("vert_spot", "add_spot", FALSE, TRUE, FALSE, TRUE, D3DBLEND_ONE, D3DBLEND_ONE, TRUE); + { + C.r_Pass(tsv_spot, tsp_spot, FALSE, TRUE, FALSE, TRUE, D3DBLEND_ONE, D3DBLEND_ONE, TRUE); C.r_Sampler("s_base", C.L_textures[0]); C.r_Sampler_clf("s_lmap", "internal\\internal_light_att", true); C.r_Sampler_clf("s_att", TEX_SPOT_ATT); + if (C.bDetail_Diffuse) + C.r_Sampler("s_detail", C.detail_texture); C.r_End(); - break; + } + break; case SE_R1_LMODELS: + { // Lighting only C.r_Pass("vert_l", "vert_l", FALSE); C.r_Sampler("s_base", C.L_textures[0]); C.r_End(); - break; + } + break; } } } diff --git a/src/Layers/xrRenderPC_R1/Blender_Vertex_aref.cpp b/src/Layers/xrRenderPC_R1/Blender_Vertex_aref.cpp index d2c45a17f5e..691843d7af8 100644 --- a/src/Layers/xrRenderPC_R1/Blender_Vertex_aref.cpp +++ b/src/Layers/xrRenderPC_R1/Blender_Vertex_aref.cpp @@ -75,58 +75,91 @@ void CBlender_Vertex_aref::Compile(CBlender_Compile& C) } else { + D3DBLEND blend_src, blend_dst; + if (oBlend.value) + { + blend_src = D3DBLEND_SRCALPHA; + blend_dst = D3DBLEND_INVSRCALPHA; + } + else + { + blend_src = D3DBLEND_ONE; + blend_dst = D3DBLEND_ZERO; + } + + LPCSTR tsv_hq, tsp_hq; + LPCSTR tsv_point, tsv_spot, tsp_point, tsp_spot; + if (C.bDetail_Diffuse) + { + tsv_hq = "vert_dt"; + tsv_point = "vert_point_dt"; + tsv_spot = "vert_spot_dt"; + + tsp_hq = "vert_dt"; + tsp_point = "add_point_dt"; + tsp_spot = "add_spot_dt"; + } + else + { + tsv_hq = "vert"; + tsv_point = "vert_point"; + tsv_spot = "vert_spot"; + + tsp_hq = "vert"; + tsp_point = "add_point"; + tsp_spot = "add_spot"; + } + switch (C.iElement) { case SE_R1_NORMAL_HQ: + { // Level view - { - LPCSTR sname = "vert"; - if (C.bDetail_Diffuse) - sname = "vert_dt"; - if (oBlend.value) - C.r_Pass(sname, sname, TRUE, TRUE, TRUE, TRUE, D3DBLEND_SRCALPHA, D3DBLEND_INVSRCALPHA, TRUE, - oAREF.value); - else - C.r_Pass(sname, sname, TRUE, TRUE, TRUE, TRUE, D3DBLEND_ONE, D3DBLEND_ZERO, TRUE, oAREF.value); - C.r_Sampler("s_base", C.L_textures[0]); + C.r_Pass(tsv_hq, tsp_hq, TRUE, TRUE, TRUE, TRUE, blend_src, blend_dst, TRUE, oAREF.value); + C.r_Sampler("s_base", C.L_textures[0]); + if (C.bDetail_Diffuse) C.r_Sampler("s_detail", C.detail_texture); - C.r_End(); - } - break; + C.r_End(); + } + break; case SE_R1_NORMAL_LQ: + { // Level view - { - LPCSTR sname = "vert"; - if (oBlend.value) - C.r_Pass(sname, sname, TRUE, TRUE, TRUE, TRUE, D3DBLEND_SRCALPHA, D3DBLEND_INVSRCALPHA, TRUE, - oAREF.value); - else - C.r_Pass(sname, sname, TRUE, TRUE, TRUE, TRUE, D3DBLEND_ONE, D3DBLEND_ZERO, TRUE, oAREF.value); - C.r_Sampler("s_base", C.L_textures[0]); - C.r_End(); - } - break; + C.r_Pass("vert", "vert", TRUE, TRUE, TRUE, TRUE, blend_src, blend_dst, TRUE, oAREF.value); + C.r_Sampler("s_base", C.L_textures[0]); + C.r_End(); + } + break; case SE_R1_LPOINT: - C.r_Pass( - "vert_point", "add_point", FALSE, TRUE, FALSE, TRUE, D3DBLEND_ONE, D3DBLEND_ONE, TRUE, oAREF.value); + { + C.r_Pass(tsv_point, tsp_point, FALSE, TRUE, FALSE, TRUE, D3DBLEND_ONE, D3DBLEND_ONE, TRUE, oAREF.value); C.r_Sampler("s_base", C.L_textures[0]); C.r_Sampler_clf("s_lmap", TEX_POINT_ATT); C.r_Sampler_clf("s_att", TEX_POINT_ATT); + if (C.bDetail_Diffuse) + C.r_Sampler("s_detail", C.detail_texture); C.r_End(); - break; + } + break; case SE_R1_LSPOT: - C.r_Pass("vert_spot", "add_spot", FALSE, TRUE, FALSE, TRUE, D3DBLEND_ONE, D3DBLEND_ONE, TRUE, oAREF.value); + { + C.r_Pass(tsv_spot, tsp_spot, FALSE, TRUE, FALSE, TRUE, D3DBLEND_ONE, D3DBLEND_ONE, TRUE, oAREF.value); C.r_Sampler("s_base", C.L_textures[0]); C.r_Sampler_clf("s_lmap", "internal\\internal_light_att", true); C.r_Sampler_clf("s_att", TEX_SPOT_ATT); + if (C.bDetail_Diffuse) + C.r_Sampler("s_detail", C.detail_texture); C.r_End(); - break; + } + break; case SE_R1_LMODELS: + { // Lighting only C.r_Pass("vert_l", "vert_l", FALSE); C.r_Sampler("s_base", C.L_textures[0]); C.r_End(); - break; + } + break; } } } diff --git a/src/Layers/xrRenderPC_R1/Blender_default_aref.cpp b/src/Layers/xrRenderPC_R1/Blender_default_aref.cpp index ddd5a584059..2396ae160d3 100644 --- a/src/Layers/xrRenderPC_R1/Blender_default_aref.cpp +++ b/src/Layers/xrRenderPC_R1/Blender_default_aref.cpp @@ -73,20 +73,48 @@ void CBlender_default_aref::Compile(CBlender_Compile& C) } else { - if (C.L_textures.size() < 2) - xrDebug::Fatal(DEBUG_INFO, "Not enought textures for shader, base tex: %s", *C.L_textures[0]); + R_ASSERT3(C.L_textures.size() >= 2, "Not enought textures for shader, base tex: %s", *C.L_textures[0]); + + D3DBLEND blend_src, blend_dst; + if (oBlend.value) + { + blend_src = D3DBLEND_SRCALPHA; + blend_dst = D3DBLEND_INVSRCALPHA; + } + else + { + blend_src = D3DBLEND_ONE; + blend_dst = D3DBLEND_ZERO; + } + + LPCSTR tsv_hq, tsp_hq; + LPCSTR tsv_point, tsv_spot, tsp_point, tsp_spot; + if (C.bDetail_Diffuse) + { + tsv_hq = "lmap_dt"; + tsv_point = "lmap_point_dt"; + tsv_spot = "lmap_spot_dt"; + + tsp_hq = "lmap_dt"; + tsp_point = "add_point_dt"; + tsp_spot = "add_spot_dt"; + } + else + { + tsv_hq = "lmap"; + tsv_point = "lmap_point"; + tsv_spot = "lmap_spot"; + + tsp_hq = "lmap"; + tsp_point = "add_point"; + tsp_spot = "add_spot"; + } + switch (C.iElement) { case SE_R1_NORMAL_HQ: { - LPCSTR sname = "lmap"; - if (C.bDetail_Diffuse) - sname = "lmap_dt"; - if (oBlend.value) - C.r_Pass( - sname, sname, TRUE, TRUE, TRUE, TRUE, D3DBLEND_SRCALPHA, D3DBLEND_INVSRCALPHA, TRUE, oAREF.value); - else - C.r_Pass(sname, sname, TRUE, TRUE, TRUE, TRUE, D3DBLEND_ONE, D3DBLEND_ZERO, TRUE, oAREF.value); + C.r_Pass(tsv_hq, tsp_hq, TRUE, TRUE, TRUE, TRUE, blend_src, blend_dst, TRUE, oAREF.value); C.r_Sampler("s_base", C.L_textures[0]); C.r_Sampler("s_lmap", C.L_textures[1]); C.r_Sampler("s_detail", C.detail_texture); @@ -96,12 +124,7 @@ void CBlender_default_aref::Compile(CBlender_Compile& C) break; case SE_R1_NORMAL_LQ: { - LPCSTR sname = "lmap"; - if (oBlend.value) - C.r_Pass( - sname, sname, TRUE, TRUE, TRUE, TRUE, D3DBLEND_SRCALPHA, D3DBLEND_INVSRCALPHA, TRUE, oAREF.value); - else - C.r_Pass(sname, sname, TRUE, TRUE, TRUE, TRUE, D3DBLEND_ONE, D3DBLEND_ZERO, TRUE, oAREF.value); + C.r_Pass("lmap", "lmap", TRUE, TRUE, TRUE, TRUE, blend_src, blend_dst, TRUE, oAREF.value); C.r_Sampler("s_base", C.L_textures[0]); C.r_Sampler("s_lmap", C.L_textures[1]); C.r_Sampler_clf("s_hemi", *C.L_textures[2]); @@ -109,35 +132,36 @@ void CBlender_default_aref::Compile(CBlender_Compile& C) } break; case SE_R1_LPOINT: - if (!oBlend.value) - { - C.r_Pass( - "lmap_point", "add_point", FALSE, TRUE, FALSE, TRUE, D3DBLEND_ONE, D3DBLEND_ONE, TRUE, oAREF.value); - C.r_Sampler("s_base", C.L_textures[0]); - C.r_Sampler_clf("s_lmap", TEX_POINT_ATT); - C.r_Sampler_clf("s_att", TEX_POINT_ATT); - C.r_End(); - } - break; + { + C.r_Pass(tsv_point, tsp_point, FALSE, TRUE, FALSE, TRUE, D3DBLEND_ONE, D3DBLEND_ONE, TRUE, oAREF.value); + C.r_Sampler("s_base", C.L_textures[0]); + C.r_Sampler_clf("s_lmap", TEX_POINT_ATT); + C.r_Sampler_clf("s_att", TEX_POINT_ATT); + if (C.bDetail_Diffuse) + C.r_Sampler("s_detail", C.detail_texture); + C.r_End(); + } + break; case SE_R1_LSPOT: - if (!oBlend.value) - { - C.r_Pass( - "lmap_spot", "add_spot", FALSE, TRUE, FALSE, TRUE, D3DBLEND_ONE, D3DBLEND_ONE, TRUE, oAREF.value); - C.r_Sampler("s_base", C.L_textures[0]); - C.r_Sampler_clf("s_lmap", "internal\\internal_light_att", true); - C.r_Sampler_clf("s_att", TEX_SPOT_ATT); - C.r_End(); - } - break; + { + C.r_Pass(tsv_spot, tsp_spot, FALSE, TRUE, FALSE, TRUE, D3DBLEND_ONE, D3DBLEND_ONE, TRUE, oAREF.value); + C.r_Sampler("s_base", C.L_textures[0]); + C.r_Sampler_clf("s_lmap", "internal\\internal_light_att", true); + C.r_Sampler_clf("s_att", TEX_SPOT_ATT); + if (C.bDetail_Diffuse) + C.r_Sampler("s_detail", C.detail_texture); + C.r_End(); + } + break; case SE_R1_LMODELS: + { // Lighting only, not use alpha-channel C.r_Pass("lmap_l", "lmap_l", FALSE); C.r_Sampler("s_base", C.L_textures[0]); C.r_Sampler("s_lmap", C.L_textures[1]); C.r_Sampler_clf("s_hemi", *C.L_textures[2]); C.r_End(); - break; + } } } }