Skip to content

Commit

Permalink
shaders: Add GLSL port of accum_volumetric.
Browse files Browse the repository at this point in the history
  • Loading branch information
CrossVR committed Mar 6, 2016
1 parent e82c4b0 commit 221062a
Show file tree
Hide file tree
Showing 21 changed files with 136 additions and 0 deletions.
21 changes: 21 additions & 0 deletions res/gamedata/shaders/gl/accum_volume.vs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#include "common.h"
#include "iostructs\v_volume.h"

//////////////////////////////////////////////////////////////////////////////////////////
uniform float4x4 m_texgen;
#ifdef USE_SJITTER
uniform float4x4 m_texgen_J;
#endif

//////////////////////////////////////////////////////////////////////////////////////////
// Vertex
v2p_volume _main ( float4 P )
{
v2p_volume O;
O.hpos = mul( m_WVP, P );
O.tc = mul( m_texgen, P );
#ifdef USE_SJITTER
O.tcJ = mul( m_texgen_J, P );
#endif
return O;
}
Binary file added res/gamedata/shaders/gl/accum_volumetric.ps
Binary file not shown.
34 changes: 34 additions & 0 deletions res/gamedata/shaders/gl/accum_volumetric.vs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#include "common.h"
#include "iostructs\v_volumetric.h"

//cbuffer VolumetricLights
//{
uniform float3 vMinBounds;
uniform float3 vMaxBounds;
uniform float4 FrustumClipPlane[6];
//}

v2p _main ( float3 P )
{
v2p o;
float4 vPos;
vPos.xyz = lerp( vMinBounds, vMaxBounds, P); // Position in camera space
vPos.w = 1;
o.hpos = mul (m_P, vPos); // xform, input in camera coordinates

o.lightToPos = vPos.xyz - Ldynamic_pos.xyz;
o.vPos = vPos.xyz;

// o.fDensity = (vMaxBounds.z-vMinBounds.z)/2000.0f;
// o.fDensity = (vMaxBounds.z-vMinBounds.z)/2000.0f*2;
o.fDensity = 1.0f/40.0f;
// o.fDensity = 1.0f/20.0f;

for (int i=0; i<3; ++i)
{
o.clip0[i] = dot( o.hpos, FrustumClipPlane[i]);
o.clip1[i] = dot( o.hpos, FrustumClipPlane[i+3]);
}

return o;
}
Binary file added res/gamedata/shaders/gl/accum_volumetric_msaa.ps
Binary file not shown.
Binary file added res/gamedata/shaders/gl/accum_volumetric_nomsaa.ps
Binary file not shown.
1 change: 1 addition & 0 deletions res/gamedata/shaders/gl/accum_volumetric_nomsaa.vs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#include "accum_volumetric.vs"
Binary file added res/gamedata/shaders/gl/accum_volumetric_sun.ps
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
39 changes: 39 additions & 0 deletions res/gamedata/shaders/gl/iostructs/p_volumetric.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@

out vec4 SV_Target;
#ifdef MSAA_OPTIMIZATION
in int gl_SampleID;
#endif

struct v2p
{
float3 lightToPos ; // TEXCOORD0; // light center to plane vector
float3 vPos ; // TEXCOORD1; // position in camera space
float fDensity ; // TEXCOORD2; // plane density along Z axis
// float2 tNoise ; // TEXCOORD3; // projective noise
};

layout(location = TEXCOORD0) in float3 v2p_lightToPos ; // TEXCOORD0; // light center to plane vector
layout(location = TEXCOORD1) in float3 v2p_vPos ; // TEXCOORD1; // position in camera space
layout(location = TEXCOORD2) in float v2p_fDensity ; // TEXCOORD2; // plane density along Z axis
//layout(location = TEXCOORD3) in float2 v2p_tNoise ; // TEXCOORD3; // projective noise

#ifdef MSAA_OPTIMIZATION
float4 _main ( v2p I, uint iSample );
#else
float4 _main ( v2p I );
#endif

void main()
{
v2p I;
I.lightToPos = v2p_lightToPos;
I.vPos = v2p_vPos;
I.fDensity = v2p_fDensity;
// I.tNoise = v2p_tNoise;

#ifdef MSAA_OPTIMIZATION
SV_Target = _main ( I, gl_SampleID );
#else
SV_Target = _main ( I );
#endif
}
41 changes: 41 additions & 0 deletions res/gamedata/shaders/gl/iostructs/v_volumetric.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@

out gl_PerVertex
{
vec4 gl_Position;
float gl_ClipDistance[6];
};

struct v2p
{
float3 lightToPos ; // TEXCOORD0; // light center to plane vector
float3 vPos ; // TEXCOORD1; // position in camera space
float fDensity ; // TEXCOORD2; // plane density alon Z axis
// float2 tNoise ; // TEXCOORD3; // projective noise
float3 clip0 ; // SV_ClipDistance0;
float3 clip1 ; // SV_ClipDistance1;
float4 hpos ; // SV_Position;
};

layout(location = POSITION) in float3 v_volumetric_P;

layout(location = TEXCOORD0) out float3 v2p_lightToPos ; // TEXCOORD0; // light center to plane vector
layout(location = TEXCOORD1) out float3 v2p_vPos ; // TEXCOORD1; // position in camera space
layout(location = TEXCOORD2) out float v2p_fDensity ; // TEXCOORD2; // plane density alon Z axis
//layout(location = TEXCOORD3) out float2 v2p_tNoise ; // TEXCOORD3; // projective noise

v2p _main ( float3 P );

void main()
{
v2p O = _main ( v_volumetric_P );
v2p_lightToPos = O.lightToPos;
v2p_vPos = O.vPos;
v2p_fDensity = O.fDensity;
// v2p_tNoise = O.tNoise;
gl_Position = O.hpos;
for (int i=0; i<3; ++i)
{
gl_ClipDistance[i] = O.clip0[i];
gl_ClipDistance[i+3] = O.clip1[i];
}
}

0 comments on commit 221062a

Please sign in to comment.