float4 CameraPos : register(c16); row_major float3x4 ViewMatrix : register(c8); row_major float4x4 ProjMatrix : register(c12); float4 NearFarZRange : register(c18); float4 ScreenSize; float4 FogParams; sampler2D TexDepth; #include "Defs.fxh" struct VSInput { float4 vPos : POSITION; }; struct VSOutput { float4 vHPos : POSITION; float4 vWorldViewRay1 : TEXCOORD0; }; VSOutput VShader(in VSInput IN) { VSOutput OUT; IN.vPos.z=0; OUT.vHPos = IN.vPos; float4 hpos = IN.vPos; float zf = NearFarZRange.y; float3 view_ray = compute_view_ray(ProjMatrix, hpos)*zf; float3 world_ray = mul(view_ray, (float3x3)ViewMatrix); OUT.vWorldViewRay1.xyz = world_ray / zf; // ? OUT.vWorldViewRay1.w = length(OUT.vWorldViewRay1.xyz); return OUT; } half ComputeVolumetricFog( in float4 cameraToWorldPos ) { #define atmosphereScale FogParams.x #define volFogHeightDensityAtViewer FogParams.y #define fogDensity FogParams.z #define artistTweakDensityOffset FogParams.w half fogInt = 1; const half c_slopeThreshold = 0.01; half t = cameraToWorldPos.z * atmosphereScale; // lim[t->0]((1-exp(-t))/t) = 1 if( abs( t ) > c_slopeThreshold ) fogInt = ( 1.0 - exp( -t ) ) / t; // NOTE: volFogHeightDensityAtViewer = log2(e) * fogDensity * exp( -atmosphereScale * ( vfViewPos.z - waterLevel ) ); half u = cameraToWorldPos.w * volFogHeightDensityAtViewer; fogInt = fogInt * u - artistTweakDensityOffset; return 1-saturate( exp2( -fogInt ) ); #undef atmosphereScale #undef volFogHeightDensityAtViewer #undef fogDensity #undef artistTweakDensityOffset } half4 PShader(in VSOutput IN, half2 vPos: VPOS) : COLOR0 { half2 tc = get_screen_texcoord(vPos, (half4)ScreenSize); float fDepth; SampleDepth_fast(TexDepth, tc, NearFarZRange, fDepth); // to dzielenie tu jest z D***** float4 cam_to_world = fDepth*IN.vWorldViewRay1; return sqrt(ComputeVolumetricFog(cam_to_world)); } DEVTEST_TECH(__t1, VShader, PShader)