Skip to content

Commit

Permalink
shaders: Add GLSL port of skybox shaders.
Browse files Browse the repository at this point in the history
  • Loading branch information
CrossVR committed Mar 6, 2016
1 parent 87276b4 commit b506f1c
Show file tree
Hide file tree
Showing 11 changed files with 203 additions and 1 deletion.
Binary file added res/gamedata/shaders/gl/clouds.ps
Binary file not shown.
31 changes: 31 additions & 0 deletions res/gamedata/shaders/gl/clouds.vs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#include "common.h"
#include "shared\cloudconfig.h"
#include "iostructs\v_clouds.h"

vf _main (vi v)
{
vf o;

o.hpos = mul (m_WVP, v.p); // xform, input in world coords

// if (length(float3(v.p.x,0,v.p.z))>CLOUD_FADE) o.color.w = 0 ;

// generate tcs
float2 d0 = v.dir.xy*2-1;
float2 d1 = v.dir.wz*2-1;
float2 _0 = v.p.xz * CLOUD_TILE0 + d0*timers.z*CLOUD_SPEED0;
float2 _1 = v.p.xz * CLOUD_TILE1 + d1*timers.z*CLOUD_SPEED1;
o.tc0 = _0; // copy tc
o.tc1 = _1; // copy tc

o.color = v.color ; // copy color, low precision, cannot prescale even by 2
o.color.w *= pow (v.p.y,25);

// float scale = tex2Dlod (s_tonemap,float4(.5,.5,.5,.5)).x ;
// float scale = s_tonemap.Load( int3(0,0,0) ).x;
// float scale = s_tonemap.Load( int3(1,1,0) ).x;
float scale = texelFetch( s_tonemap, int2(0,0), 0 ).x;
o.color.rgb *= scale ; // high precision

return o;
}
2 changes: 1 addition & 1 deletion res/gamedata/shaders/gl/common_samplers.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#define Texture2D uniform sampler2D
#define Texture3D uniform sampler3D
#define Texture2DMS uniform sampler2DMS
#define TextureCube uniform samplerCube
#define TextureCube uniform samplerCube
#define Texture2DShadow uniform sampler2DShadow

//////////////////////////////////////////////////////////////////////////////////////////
Expand Down
25 changes: 25 additions & 0 deletions res/gamedata/shaders/gl/iostructs/p_clouds.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

out vec4 SV_Target;

struct v2p
{
float4 color ; // COLOR0; // rgb. intensity, for SM3 - tonemap prescaled
float2 tc0 ; // TEXCOORD0;
float2 tc1 ; // TEXCOORD1;
};

layout(location = COLOR0) in float4 p_clouds_color ; // COLOR0; // rgb. intensity, for SM3 - tonemap prescaled
layout(location = TEXCOORD0) in float2 p_clouds_tc0 ; // TEXCOORD0;
layout(location = TEXCOORD1) in float2 p_clouds_tc1 ; // TEXCOORD1;

float4 _main ( v2p I );

void main()
{
v2p I;
I.color = p_clouds_color;
I.tc0 = p_clouds_tc0;
I.tc1 = p_clouds_tc1;

SV_Target = _main ( I );
}
34 changes: 34 additions & 0 deletions res/gamedata/shaders/gl/iostructs/p_sky.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@

out vec4 SV_Target0;
out vec4 SV_Target1;

struct v2p
{
float4 factor ; // COLOR0; // for SM3 - factor.rgb - tonemap-prescaled
float3 tc0 ; // TEXCOORD0;
float3 tc1 ; // TEXCOORD1;
};
struct _out
{
float4 low ; // SV_Target0;
float4 high ; // SV_Target1;
};

layout(location = COLOR0) in float4 p_sky_factor; // COLOR0; // for SM3 - factor.rgb - tonemap-prescaled
layout(location = TEXCOORD0) in float3 p_sky_tc0 ; // TEXCOORD0;
layout(location = TEXCOORD1) in float3 p_sky_tc1 ; // TEXCOORD1;

_out _main( v2p I );

void main()
{
v2p I;
I.factor = p_sky_factor;
I.tc0 = p_sky_tc0;
I.tc1 = p_sky_tc1;

_out O = _main (I);

SV_Target0 = O.low;
SV_Target1 = O.high;
}
42 changes: 42 additions & 0 deletions res/gamedata/shaders/gl/iostructs/v_clouds.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@

out gl_PerVertex { vec4 gl_Position; };

struct vi
{
float4 p ; // POSITION;
float4 dir ; // COLOR0; // dir0,dir1(w<->z)
float4 color ; // COLOR1; // rgb. intensity
};

struct vf
{
float4 color ; // COLOR0; // rgb. intensity, for SM3 - tonemap-prescaled, HI-res
float2 tc0 ; // TEXCOORD0;
float2 tc1 ; // TEXCOORD1;
float4 hpos ; // SV_Position;
};

layout(location = POSITION) in float4 v_clouds_p ; // POSITION;
layout(location = COLOR0) in float4 v_clouds_dir ; // COLOR0; // dir0,dir1(w<->z)
layout(location = COLOR1) in float4 v_clouds_color ; // COLOR1; // rgb. intensity

layout(location = COLOR0) out float4 v2p_clouds_color ; // COLOR0; // rgb. intensity, for SM3 - tonemap-prescaled, HI-res
layout(location = TEXCOORD0) out float2 v2p_clouds_tc0 ; // TEXCOORD0;
layout(location = TEXCOORD1) out float2 v2p_clouds_tc1 ; // TEXCOORD1;

vf _main (vi v);

void main()
{
vi I;
I.p = v_clouds_p;
I.dir = v_clouds_dir;
I.color = v_clouds_color;

vf O = _main (I);

v2p_clouds_color = O.color;
v2p_clouds_tc0 = O.tc0;
v2p_clouds_tc1 = O.tc1;
gl_Position = O.hpos;
}
45 changes: 45 additions & 0 deletions res/gamedata/shaders/gl/iostructs/v_sky.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@

out gl_PerVertex { vec4 gl_Position; };

struct vi
{
float4 p ; // POSITION;
float4 c ; // COLOR0;
float3 tc0 ; // TEXCOORD0;
float3 tc1 ; // TEXCOORD1;
};

struct v2p
{
float4 c ; // COLOR0;
float3 tc0 ; // TEXCOORD0;
float3 tc1 ; // TEXCOORD1;
float4 hpos ; // SV_Position;
};

layout(location = POSITION) in float4 v_sky_p ; // POSITION;
layout(location = COLOR0) in float4 v_sky_c ; // COLOR0;
layout(location = TEXCOORD0) in float3 v_sky_tc0 ; // TEXCOORD0;
layout(location = TEXCOORD1) in float3 v_sky_tc1 ; // TEXCOORD1;

layout(location = COLOR0) out float4 v2p_sky_c ; // COLOR0;
layout(location = TEXCOORD0) out float3 v2p_sky_tc0 ; // TEXCOORD0;
layout(location = TEXCOORD1) out float3 v2p_sky_tc1 ; // TEXCOORD1;

v2p _main (vi v);

void main()
{
vi I;
I.p = v_sky_p;
I.c = v_sky_c;
I.tc0 = v_sky_tc0;
I.tc1 = v_sky_tc1;

v2p O = _main (I);

v2p_sky_c = O.c;
v2p_sky_tc0 = O.tc0;
v2p_sky_tc1 = O.tc1;
gl_Position = O.hpos;
}
2 changes: 2 additions & 0 deletions res/gamedata/shaders/gl/shared/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
#define float4x4 mat4
#define float3x4 mat4x3

vec4 mul(int a, vec4 b) { return a * b; }
vec4 mul(float a, vec4 b) { return a * b; }
vec3 mul(mat3 a, vec3 b) { return a * b; }
vec3 mul(vec3 a, mat3 b) { return a * b; }
mat3 mul(mat3 a, mat3 b) { return a * b; }
Expand Down
Binary file added res/gamedata/shaders/gl/sky2.ps
Binary file not shown.
21 changes: 21 additions & 0 deletions res/gamedata/shaders/gl/sky2.vs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#include "common.h"
#include "iostructs\v_sky.h"

v2p _main (vi v)
{
v2p o;

float4 tpos = mul (1000, v.p);
o.hpos = mul (m_WVP, tpos); // xform, input in world coords, 1000 - magic number
o.hpos.z = o.hpos.w;
o.tc0 = v.tc0; // copy tc
o.tc1 = v.tc1; // copy tc
// float scale = tex2Dlod (s_tonemap,float4(.5,.5,.5,.5)).x ;
// float scale = s_tonemap.Load( int3(0,0,0) ).x;
// float scale = s_tonemap.Load( int3(1,1,0) ).x;
float scale = texelFetch( s_tonemap, int2(0,0), 0 ).x;
// o.c = float4 ( v.c.rgb*(scale*1.7), v.c.a ); // copy color, pre-scale by tonemap //float4 ( v.c.rgb*scale*2, v.c.a );
o.c = float4 ( v.c.rgb*(scale*2.0), v.c.a ); // copy color, pre-scale by tonemap //float4 ( v.c.rgb*scale*2, v.c.a );

return o;
}
2 changes: 2 additions & 0 deletions src/Layers/xrRenderPC_GL/rgl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -919,6 +919,8 @@ HRESULT CRender::shader_compile(
if ((GLboolean)status == GL_TRUE) {
CHK_GL(glAttachShader(program, shader));
CHK_GL(glBindFragDataLocation(program, 0, "SV_Target"));
CHK_GL(glBindFragDataLocation(program, 0, "SV_Target0"));
CHK_GL(glBindFragDataLocation(program, 1, "SV_Target1"));
CHK_GL(glLinkProgram(program));
CHK_GL(glDetachShader(program, shader));
CHK_GL(glGetProgramiv(program, GL_LINK_STATUS, &status));
Expand Down

0 comments on commit b506f1c

Please sign in to comment.