#define _USE_LIGHTING #ifdef _HDR_FRAMEBUFFER_RGBM_HYBRID // output RGBM #undef _HDR_FRAMEBUFFER_RGBM_HYBRID #define _HDR_FRAMEBUFFER_RGBM #endif #include "Defs.fxh" #include "Ambient.fxh" #include "Fog.fxh" sampler2D TexLightBuffer; sampler2D TexDiffuse; sampler2D TexDepth; row_major float3x4 ViewMatrix; row_major float4x4 ProjMatrix; float4 ScreenSize; float4 NearFarZRange; float4 CameraPos; struct VSIn { float4 vPos : POSITION; }; struct VSOut { float4 vHPos : POSITION; float4 vWorldViewRay : TEXCOORD0; float4 fog_int : TEXCOORD1; }; VSOut VShader(in VSIn IN) { VSOut OUT = (VSOut)0; IN.vPos.z=0.0; OUT.vHPos = IN.vPos; // OUT.vHPos = float4(IN.vPos.xy, dot(ProjMatrix[2], IN.vPos) / dot(ProjMatrix[3], IN.vPos), 1); // wyliczamy ray world-space (x,y,z) dla danego wierzchołka (zinterpoluje się po pixlach) float3 view_ray = compute_view_ray(ProjMatrix, OUT.vHPos); OUT.vWorldViewRay.xyz = mul(view_ray, (float3x3)ViewMatrix); // ^-1 OUT.vWorldViewRay.w = length(OUT.vWorldViewRay.xyz); return OUT; } float4 PShader(in VSOut IN, half2 vPos: VPOS) : COLOR0 { half2 vScreenPos = get_screen_texcoord(vPos, (half4)ScreenSize); half3 dif, spc; SampleLightDiffuseSpecular(TexLightBuffer, vScreenPos, dif, spc); half3 amb = get_ambient_light(vScreenPos); // ten bufor jest liniowy half4 vDiffuseColor = h4tex2D(TexDiffuse, vScreenPos); half4 vResult; vResult.xyz = vDiffuseColor.xyz * (dif + amb); vResult.w = vDiffuseColor.w; float fDepth; SampleDepth_fast(TexDepth, vScreenPos.xy, NearFarZRange, fDepth); half fog_density = get_fog_density(vScreenPos.xy, fDepth * IN.vWorldViewRay.w); vResult = apply_fog(vResult, fog_density); return OutputColor(vResult); }