Skip to content

Commit b506f1c

Browse files
committed
shaders: Add GLSL port of skybox shaders.
1 parent 87276b4 commit b506f1c

File tree

11 files changed

+203
-1
lines changed

11 files changed

+203
-1
lines changed

res/gamedata/shaders/gl/clouds.ps

487 Bytes
Binary file not shown.

res/gamedata/shaders/gl/clouds.vs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#include "common.h"
2+
#include "shared\cloudconfig.h"
3+
#include "iostructs\v_clouds.h"
4+
5+
vf _main (vi v)
6+
{
7+
vf o;
8+
9+
o.hpos = mul (m_WVP, v.p); // xform, input in world coords
10+
11+
// if (length(float3(v.p.x,0,v.p.z))>CLOUD_FADE) o.color.w = 0 ;
12+
13+
// generate tcs
14+
float2 d0 = v.dir.xy*2-1;
15+
float2 d1 = v.dir.wz*2-1;
16+
float2 _0 = v.p.xz * CLOUD_TILE0 + d0*timers.z*CLOUD_SPEED0;
17+
float2 _1 = v.p.xz * CLOUD_TILE1 + d1*timers.z*CLOUD_SPEED1;
18+
o.tc0 = _0; // copy tc
19+
o.tc1 = _1; // copy tc
20+
21+
o.color = v.color ; // copy color, low precision, cannot prescale even by 2
22+
o.color.w *= pow (v.p.y,25);
23+
24+
// float scale = tex2Dlod (s_tonemap,float4(.5,.5,.5,.5)).x ;
25+
// float scale = s_tonemap.Load( int3(0,0,0) ).x;
26+
// float scale = s_tonemap.Load( int3(1,1,0) ).x;
27+
float scale = texelFetch( s_tonemap, int2(0,0), 0 ).x;
28+
o.color.rgb *= scale ; // high precision
29+
30+
return o;
31+
}

res/gamedata/shaders/gl/common_samplers.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#define Texture2D uniform sampler2D
55
#define Texture3D uniform sampler3D
66
#define Texture2DMS uniform sampler2DMS
7-
#define TextureCube uniform samplerCube
7+
#define TextureCube uniform samplerCube
88
#define Texture2DShadow uniform sampler2DShadow
99

1010
//////////////////////////////////////////////////////////////////////////////////////////
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
out vec4 SV_Target;
3+
4+
struct v2p
5+
{
6+
float4 color ; // COLOR0; // rgb. intensity, for SM3 - tonemap prescaled
7+
float2 tc0 ; // TEXCOORD0;
8+
float2 tc1 ; // TEXCOORD1;
9+
};
10+
11+
layout(location = COLOR0) in float4 p_clouds_color ; // COLOR0; // rgb. intensity, for SM3 - tonemap prescaled
12+
layout(location = TEXCOORD0) in float2 p_clouds_tc0 ; // TEXCOORD0;
13+
layout(location = TEXCOORD1) in float2 p_clouds_tc1 ; // TEXCOORD1;
14+
15+
float4 _main ( v2p I );
16+
17+
void main()
18+
{
19+
v2p I;
20+
I.color = p_clouds_color;
21+
I.tc0 = p_clouds_tc0;
22+
I.tc1 = p_clouds_tc1;
23+
24+
SV_Target = _main ( I );
25+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
2+
out vec4 SV_Target0;
3+
out vec4 SV_Target1;
4+
5+
struct v2p
6+
{
7+
float4 factor ; // COLOR0; // for SM3 - factor.rgb - tonemap-prescaled
8+
float3 tc0 ; // TEXCOORD0;
9+
float3 tc1 ; // TEXCOORD1;
10+
};
11+
struct _out
12+
{
13+
float4 low ; // SV_Target0;
14+
float4 high ; // SV_Target1;
15+
};
16+
17+
layout(location = COLOR0) in float4 p_sky_factor; // COLOR0; // for SM3 - factor.rgb - tonemap-prescaled
18+
layout(location = TEXCOORD0) in float3 p_sky_tc0 ; // TEXCOORD0;
19+
layout(location = TEXCOORD1) in float3 p_sky_tc1 ; // TEXCOORD1;
20+
21+
_out _main( v2p I );
22+
23+
void main()
24+
{
25+
v2p I;
26+
I.factor = p_sky_factor;
27+
I.tc0 = p_sky_tc0;
28+
I.tc1 = p_sky_tc1;
29+
30+
_out O = _main (I);
31+
32+
SV_Target0 = O.low;
33+
SV_Target1 = O.high;
34+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
2+
out gl_PerVertex { vec4 gl_Position; };
3+
4+
struct vi
5+
{
6+
float4 p ; // POSITION;
7+
float4 dir ; // COLOR0; // dir0,dir1(w<->z)
8+
float4 color ; // COLOR1; // rgb. intensity
9+
};
10+
11+
struct vf
12+
{
13+
float4 color ; // COLOR0; // rgb. intensity, for SM3 - tonemap-prescaled, HI-res
14+
float2 tc0 ; // TEXCOORD0;
15+
float2 tc1 ; // TEXCOORD1;
16+
float4 hpos ; // SV_Position;
17+
};
18+
19+
layout(location = POSITION) in float4 v_clouds_p ; // POSITION;
20+
layout(location = COLOR0) in float4 v_clouds_dir ; // COLOR0; // dir0,dir1(w<->z)
21+
layout(location = COLOR1) in float4 v_clouds_color ; // COLOR1; // rgb. intensity
22+
23+
layout(location = COLOR0) out float4 v2p_clouds_color ; // COLOR0; // rgb. intensity, for SM3 - tonemap-prescaled, HI-res
24+
layout(location = TEXCOORD0) out float2 v2p_clouds_tc0 ; // TEXCOORD0;
25+
layout(location = TEXCOORD1) out float2 v2p_clouds_tc1 ; // TEXCOORD1;
26+
27+
vf _main (vi v);
28+
29+
void main()
30+
{
31+
vi I;
32+
I.p = v_clouds_p;
33+
I.dir = v_clouds_dir;
34+
I.color = v_clouds_color;
35+
36+
vf O = _main (I);
37+
38+
v2p_clouds_color = O.color;
39+
v2p_clouds_tc0 = O.tc0;
40+
v2p_clouds_tc1 = O.tc1;
41+
gl_Position = O.hpos;
42+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
2+
out gl_PerVertex { vec4 gl_Position; };
3+
4+
struct vi
5+
{
6+
float4 p ; // POSITION;
7+
float4 c ; // COLOR0;
8+
float3 tc0 ; // TEXCOORD0;
9+
float3 tc1 ; // TEXCOORD1;
10+
};
11+
12+
struct v2p
13+
{
14+
float4 c ; // COLOR0;
15+
float3 tc0 ; // TEXCOORD0;
16+
float3 tc1 ; // TEXCOORD1;
17+
float4 hpos ; // SV_Position;
18+
};
19+
20+
layout(location = POSITION) in float4 v_sky_p ; // POSITION;
21+
layout(location = COLOR0) in float4 v_sky_c ; // COLOR0;
22+
layout(location = TEXCOORD0) in float3 v_sky_tc0 ; // TEXCOORD0;
23+
layout(location = TEXCOORD1) in float3 v_sky_tc1 ; // TEXCOORD1;
24+
25+
layout(location = COLOR0) out float4 v2p_sky_c ; // COLOR0;
26+
layout(location = TEXCOORD0) out float3 v2p_sky_tc0 ; // TEXCOORD0;
27+
layout(location = TEXCOORD1) out float3 v2p_sky_tc1 ; // TEXCOORD1;
28+
29+
v2p _main (vi v);
30+
31+
void main()
32+
{
33+
vi I;
34+
I.p = v_sky_p;
35+
I.c = v_sky_c;
36+
I.tc0 = v_sky_tc0;
37+
I.tc1 = v_sky_tc1;
38+
39+
v2p O = _main (I);
40+
41+
v2p_sky_c = O.c;
42+
v2p_sky_tc0 = O.tc0;
43+
v2p_sky_tc1 = O.tc1;
44+
gl_Position = O.hpos;
45+
}

res/gamedata/shaders/gl/shared/common.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
#define float4x4 mat4
2424
#define float3x4 mat4x3
2525

26+
vec4 mul(int a, vec4 b) { return a * b; }
27+
vec4 mul(float a, vec4 b) { return a * b; }
2628
vec3 mul(mat3 a, vec3 b) { return a * b; }
2729
vec3 mul(vec3 a, mat3 b) { return a * b; }
2830
mat3 mul(mat3 a, mat3 b) { return a * b; }

res/gamedata/shaders/gl/sky2.ps

530 Bytes
Binary file not shown.

res/gamedata/shaders/gl/sky2.vs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#include "common.h"
2+
#include "iostructs\v_sky.h"
3+
4+
v2p _main (vi v)
5+
{
6+
v2p o;
7+
8+
float4 tpos = mul (1000, v.p);
9+
o.hpos = mul (m_WVP, tpos); // xform, input in world coords, 1000 - magic number
10+
o.hpos.z = o.hpos.w;
11+
o.tc0 = v.tc0; // copy tc
12+
o.tc1 = v.tc1; // copy tc
13+
// float scale = tex2Dlod (s_tonemap,float4(.5,.5,.5,.5)).x ;
14+
// float scale = s_tonemap.Load( int3(0,0,0) ).x;
15+
// float scale = s_tonemap.Load( int3(1,1,0) ).x;
16+
float scale = texelFetch( s_tonemap, int2(0,0), 0 ).x;
17+
// 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 );
18+
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 );
19+
20+
return o;
21+
}

src/Layers/xrRenderPC_GL/rgl.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -919,6 +919,8 @@ HRESULT CRender::shader_compile(
919919
if ((GLboolean)status == GL_TRUE) {
920920
CHK_GL(glAttachShader(program, shader));
921921
CHK_GL(glBindFragDataLocation(program, 0, "SV_Target"));
922+
CHK_GL(glBindFragDataLocation(program, 0, "SV_Target0"));
923+
CHK_GL(glBindFragDataLocation(program, 1, "SV_Target1"));
922924
CHK_GL(glLinkProgram(program));
923925
CHK_GL(glDetachShader(program, shader));
924926
CHK_GL(glGetProgramiv(program, GL_LINK_STATUS, &status));

0 commit comments

Comments
 (0)