Divergent/mods/Boomsticks and Sharpsticks/gamedata/shaders/r3/particleTGZ.ps

52 lines
1.4 KiB
PostScript

#include "common.h"
struct v2p
{
float2 tc0 : TEXCOORD0;
float4 c : COLOR0;
// Igor: for additional depth dest
#ifdef USE_SOFT_PARTICLES
float4 tctexgen : TEXCOORD1;
#endif // USE_SOFT_PARTICLES
float4 hpos : SV_Position;
};
// Must be less than view near
#define DEPTH_EPSILON 0.1h
//////////////////////////////////////////////////////////////////////////////////////////
// Pixel
float4 main( v2p I ) : SV_Target
{
// float4 result = I.c*tex2D (s_base,I.tc0);
float4 result = I.c * s_base.Sample( smp_base, I.tc0);
// Igor: additional depth test
#ifdef USE_SOFT_PARTICLES
// float4 _P = tex2Dproj (s_position, I.tctexgen);
float2 tcProj = I.tctexgen.xy / I.tctexgen.w;
#ifdef GBUFFER_OPTIMIZATION
gbuffer_data gbd = gbuffer_load_data( tcProj, I.hpos );
#else
gbuffer_data gbd = gbuffer_load_data( tcProj );
#endif
float4 _P = float4( gbd.P, gbd.mtl );
float spaceDepth = _P.z-I.tctexgen.z-DEPTH_EPSILON;
if (spaceDepth < -2*DEPTH_EPSILON ) spaceDepth = 100000.0h; // Skybox doesn't draw into position buffer
//result.a *= saturate(spaceDepth*0.3h);
result.a *= Contrast( saturate(spaceDepth*1.3h), 2);
result.rgb *= Contrast( saturate(spaceDepth*1.3h), 2);
// result = Contrast( saturate(spaceDepth*1.3h), 2);
// result = saturate (spaceDepth*5.0);
// result.rgb = float3(1,0,0);
// result.a = 1;
#endif // USE_SOFT_PARTICLES
clip(result.a-(0.01f/255.0f));
//clip(result.a-0.5);
return result;
}