From 1b8aa70c474247d7891601f580e041a9b2574d41 Mon Sep 17 00:00:00 2001 From: SkyLoaderr Date: Thu, 22 Nov 2018 16:37:47 +0300 Subject: [PATCH] xrRender_R2: Calculation of water fogging --- res/gamedata/shaders/r2/water.ps | Bin 0 -> 3097 bytes res/gamedata/shaders/r2/water.vs | 92 +++++++++++++++++++++++++++++++ 2 files changed, 92 insertions(+) create mode 100644 res/gamedata/shaders/r2/water.ps create mode 100644 res/gamedata/shaders/r2/water.vs diff --git a/res/gamedata/shaders/r2/water.ps b/res/gamedata/shaders/r2/water.ps new file mode 100644 index 0000000000000000000000000000000000000000..bd67afde11363aa27896386077129e7b75fb9af7 GIT binary patch literal 3097 zcmb_eOK;mo5I!$|#UKF!N}*{=vSZYO4y`Q(LLJMnm9{rwO)Vw1tN^2F!Z>RQP^%G~H-h~z&th4%rJu&m`#4&Qh<$ySt{xV%*s<0A=jgT!*7ide!bsVwN(^uwdLB}G~`$5t}#n;v1W^o@_!WoOQ z4aGZKd>%XB#*VX-afIAL$Y~5Q#$p zpJ79!JeDrD19%rUk%690Ju&3k`%LK6WmWIp2m z2sD7Sv4|)=1U6S@HBS7P9h9 z(74L_6TnA*XbEOfAxbF{)Gv9pE3l-&U1ybRy?B-$>yG8wlPD06PuFOBztmEmW;>il z6A1jl`SxSr56`!Kr833|0)t7kOA?B~gJ2>vdaJn!SBBO&lcqLxxY}r4dDyu;F@PFJ z+jrX*JStni*gWbNjv-QoC}rYd?uUUQ!dk-cs!USG%%HRanh}32XVg!f>y1bNjBWqP zf@v}&c#^!Jnc0#=EMtZqa9P+PYzXr9YwSYBZVEq*s+TTMGU3Oduwkj{9L zZ@Eg>MJHX>Z1;(7-p=CNXAYek^G#M<0$;D=3R8=@TZ_Ef;vUP&%p6$V!33DvbzWqD zyHKw1yjFN>b9*w`Is-L)ua%hzD*G=d4ak3?RHI)70z7TB7ogXbIOJw%qsNmoKiFbn zsh#w0VyF7o642@U>&LXBpMDbZs>AsI}X^ zbyjOcdS^2pR#|}|lxdb#+p-e58~DNSoDve?T`6kIdUwZ)xWOY$9J8o*@mf(&50g7r zeR-Hi`mwN2pZAZ9lRw>MR?Vc-5X}EW@yGvOs=jC0W0cxhFOvob!E+cEQ(en zYDVEwUkRvP3W4Jv$1Ww6{uS)zbS1Wa7xX+p6*bhT&0dcdT>OdHYzX>~y%mEBQip1P OT$F$NU)l}eoAVt7>~c8( literal 0 HcmV?d00001 diff --git a/res/gamedata/shaders/r2/water.vs b/res/gamedata/shaders/r2/water.vs new file mode 100644 index 00000000000..996b9d80afa --- /dev/null +++ b/res/gamedata/shaders/r2/water.vs @@ -0,0 +1,92 @@ +#include "common.h" +#include "shared\waterconfig.h" +#include "shared\watermove.h" + +struct v_vert +{ + float4 P : POSITION; // (float,float,float,1) + float4 N : NORMAL; // (nx,ny,nz,hemi occlusion) + float4 T : TANGENT; + float4 B : BINORMAL; + float4 color : COLOR0; // (r,g,b,dir-occlusion) + float2 uv : TEXCOORD0; // (u0,v0) +}; +struct vf +{ + float4 hpos : POSITION; + float2 tbase : TEXCOORD0; // base + float2 tnorm0 : TEXCOORD1; // nm0 + float2 tnorm1 : TEXCOORD2; // nm1 + half3 M1 : TEXCOORD3; + half3 M2 : TEXCOORD4; + half3 M3 : TEXCOORD5; + half3 v2point : TEXCOORD6; +#ifdef USE_SOFT_WATER +#ifdef NEED_SOFT_WATER + float4 tctexgen : TEXCOORD7; +#endif // USE_SOFT_WATER +#endif // NEED_SOFT_WATER + half4 c0 : COLOR0; + float fog : FOG; +}; + +vf main(v_vert v) +{ + vf o; + + float4 P = v.P ; // world + float3 NN = unpack_normal (v.N) ; + P = watermove (P) ; + + o.v2point = P-eye_position ; + o.tbase = unpack_tc_base (v.uv,v.T.w,v.B.w); // copy tc + o.tnorm0 = watermove_tc (o.tbase*W_DISTORT_BASE_TILE_0, P.xz, W_DISTORT_AMP_0); + o.tnorm1 = watermove_tc (o.tbase*W_DISTORT_BASE_TILE_1, P.xz, W_DISTORT_AMP_1); + + + // Calculate the 3x3 transform from tangent space to eye-space + // TangentToEyeSpace = object2eye * tangent2object + // = object2eye * transpose(object2tangent) (since the inverse of a rotation is its transpose) + float3 N = unpack_bx2(v.N); // just scale (assume normal in the -.5f, .5f) + float3 T = unpack_bx2(v.T); // + float3 B = unpack_bx2(v.B); // + float3x3 xform = mul ((float3x3)m_W, float3x3( + T.x,B.x,N.x, + T.y,B.y,N.y, + T.z,B.z,N.z + )); + // The pixel shader operates on the bump-map in [0..1] range + // Remap this range in the matrix, anyway we are pixel-shader limited :) + // ...... [ 2 0 0 0] + // ...... [ 0 2 0 0] + // ...... [ 0 0 2 0] + // ...... [-1 -1 -1 1] + // issue: strange, but it's slower :( + // issue: interpolators? dp4? VS limited? black magic? + + // Feed this transform to pixel shader + o.M1 = xform [0]; + o.M2 = xform [1]; + o.M3 = xform [2]; + + 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; + // L_final = v.N.w + L_ambient; + + o.hpos = mul (m_VP, P); // xform, input in world coords + o.fog = saturate(calc_fogging (v.P)); + + o.c0 = float4 (L_final,1); + +// Igor: for additional depth dest +#ifdef USE_SOFT_WATER +#ifdef NEED_SOFT_WATER + o.tctexgen = mul( m_texgen, P); + float3 Pe = mul (m_V, P); + o.tctexgen.z = Pe.z; +#endif // USE_SOFT_WATER +#endif // NEED_SOFT_WATER + return o; +}