Skip to content

Commit

Permalink
shaders: Implement particle shaders.
Browse files Browse the repository at this point in the history
  • Loading branch information
CrossVR committed Nov 15, 2015
1 parent af7fc18 commit af63791
Show file tree
Hide file tree
Showing 14 changed files with 105 additions and 39 deletions.
33 changes: 33 additions & 0 deletions cs/resources/shaders/gl/iostructs/p_particle.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@

struct v2p
{
float2 tc0; // base
half4 c; // color
// Igor: for additional depth dest
#ifdef USE_SOFT_PARTICLES
float4 tctexgen;
#endif // USE_SOFT_PARTICLES
float fog;
};

layout(location = TEXCOORD0) in vec2 tc0; // base
layout(location = COLOR0) in vec4 c0; // color
#ifdef USE_SOFT_PARTICLES
layout(location = TEXCOORD1) in vec4 tctexgen;
#endif // USE_SOFT_PARTICLES
layout(location = FOG) in float fog;

layout(location = COLOR0) out vec4 C;

half4 _main( v2p I );

void main()
{
v2p I;
I.tc0 = tc0;
I.c = c0;
I.tctexgen = tctexgen;
I.fog = fog;

C = _main(I);
}
51 changes: 51 additions & 0 deletions cs/resources/shaders/gl/iostructs/v_particle.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@

out gl_PerVertex { vec4 gl_Position; };

struct vv
{
float4 P;
float2 tc;
float4 c;
};
struct vf
{
float4 hpos;
float2 tc;
float4 c;

// Igor: for additional depth dest
#ifdef USE_SOFT_PARTICLES
float4 tctexgen;
#endif // USE_SOFT_PARTICLES
};

layout(location = POSITION) in float4 P;
layout(location = TEXCOORD0) in float2 tc;
layout(location = COLOR0) in float4 c;

layout(location = TEXCOORD0) out vec2 tc0; // base
layout(location = COLOR0) out vec4 c0; // color
#ifdef USE_SOFT_PARTICLES
layout(location = TEXCOORD1) out vec4 tctexgen;
#endif // USE_SOFT_PARTICLES
layout(location = FOG) out float fog;

vf _main( vv v );

void main()
{
vv I;
I.P = P;
I.tc = tc;
I.c = c;

vf O;
O = _main(I);

tc0 = O.tc;
c0 = O.c;
#ifdef USE_SOFT_PARTICLES
tctexgen = O.tctexgen;
#endif // USE_SOFT_PARTICLES
gl_Position = O.hpos;
}
26 changes: 10 additions & 16 deletions cs/resources/shaders/gl/particle-clip.vs
Original file line number Diff line number Diff line change
@@ -1,21 +1,15 @@
#include "common.h"
#include "iostructs/v_particle.h"

out gl_PerVertex { vec4 gl_Position; };

layout(location = 0) in vec4 P;
layout(location = 1) in vec2 tc;
layout(location = 2) in vec4 c;

layout(location = 0) out vec2 tc0;
layout(location = 1) out vec4 c0;

void main ()
vf _main (vv v)
{
float4 hpos = mul (m_WVP, P); // xform, input in world coords
hpos.z = abs (hpos.z);
hpos.w = abs (hpos.w);
tc0 = tc; // copy tc
c0 = c; // copy color
vf o;

o.hpos = mul (m_WVP, v.P); // xform, input in world coords
o.hpos.z = abs (o.hpos.z);
o.hpos.w = abs (o.hpos.w);
o.tc = v.tc; // copy tc
o.c = v.c; // copy color

gl_Position = hpos;
return o;
}
Binary file modified cs/resources/shaders/gl/particle.ps
Binary file not shown.
34 changes: 11 additions & 23 deletions cs/resources/shaders/gl/particle.vs
Original file line number Diff line number Diff line change
@@ -1,32 +1,20 @@
#include "common.h"
#include "iostructs/v_particle.h"

out gl_PerVertex { vec4 gl_Position; };

layout(location = 0) in vec4 P;
layout(location = 1) in vec2 tc;
layout(location = 2) in vec4 c;

layout(location = 0) out vec2 tc0;
layout(location = 1) out vec4 c0;
// Igor: for additional depth dest
#ifdef USE_SOFT_PARTICLES
layout(location = 2) out vec4 tctexgen;
#endif // USE_SOFT_PARTICLES

//uniform float4x4 mVPTexgen;

void main ()
vf _main (vv v)
{
float4 hpos = mul (m_WVP, P); // xform, input in world coords
// float4 hpos = mul (m_VP, P); // xform, input in world coords
tc0 = tc; // copy tc
c0 = unpack_D3DCOLOR(c); // copy color
vf o;

o.hpos = mul (m_WVP, v.P); // xform, input in world coords
// o.hpos = mul (m_VP, v.P); // xform, input in world coords
o.tc = v.tc; // copy tc
o.c = v.c; // copy color

// Igor: for additional depth dest
#ifdef USE_SOFT_PARTICLES
tctexgen = mul( mVPTexgen, P);
tctexgen.z = hpos.z;
o.tctexgen = mul( mVPTexgen, v.P);
o.tctexgen.z = o.hpos.z;
#endif // USE_SOFT_PARTICLES

gl_Position = hpos;
return o;
}
Binary file added cs/resources/shaders/gl/particle2t.ps
Binary file not shown.
Binary file modified cs/resources/shaders/gl/particle_alphaonly.ps
Binary file not shown.
Binary file modified cs/resources/shaders/gl/particle_distort.ps
Binary file not shown.
Binary file removed cs/resources/shaders/gl/particle_distort_hard.ps
Binary file not shown.
Binary file removed cs/resources/shaders/gl/particle_hard.ps
Binary file not shown.
Binary file modified cs/resources/shaders/gl/particle_s-aadd.ps
Binary file not shown.
Binary file modified cs/resources/shaders/gl/particle_s-add.ps
Binary file not shown.
Binary file modified cs/resources/shaders/gl/particle_s-blend.ps
Binary file not shown.
Binary file added cs/resources/shaders/gl/particle_s-mul.ps
Binary file not shown.

0 comments on commit af63791

Please sign in to comment.