Skip to content

Commit dfe5389

Browse files
committed
shaders: Add G-Buffer support to GLSL ports.
1 parent c47e38c commit dfe5389

14 files changed

+18
-18
lines changed
12 Bytes
Binary file not shown.

res/gamedata/shaders/gl/common_functions.h

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ f_deffer pack_gbuffer( float4 norm, float4 pos, float4 col, uint imask )
214214
res.Ne = norm;
215215
res.C = col;
216216
#else
217-
res.position = float4( gbuf_pack_normal( norm ), pos.z, gbuf_pack_hemi_mtl( norm.w, pos.w ) );
217+
res.position = float4( gbuf_pack_normal( norm.xyz ), pos.z, gbuf_pack_hemi_mtl( norm.w, pos.w ) );
218218
res.C = col;
219219
#endif
220220

@@ -226,14 +226,14 @@ f_deffer pack_gbuffer( float4 norm, float4 pos, float4 col, uint imask )
226226
}
227227

228228
#ifdef GBUFFER_OPTIMIZATION
229-
gbuffer_data gbuffer_load_data( float2 tc, float2 pos2d, int iSample )
229+
gbuffer_data gbuffer_load_data( float2 tc, float4 pos2d, uint iSample )
230230
{
231231
gbuffer_data gbd;
232232

233233
gbd.P = float3(0,0,0);
234234
gbd.hemi = 0;
235235
gbd.mtl = 0;
236-
gbd.C = 0;
236+
gbd.C = float3(0,0,0);
237237
gbd.N = float3(0,0,0);
238238

239239
#ifndef USE_MSAA
@@ -250,7 +250,7 @@ gbuffer_data gbuffer_load_data( float2 tc, float2 pos2d, int iSample )
250250
// righttop = ( tan(fHorzFOV/2), tan(fVertFOV/2), 1 )
251251
// leftbottom = ( -tan(fHorzFOV/2), -tan(fVertFOV/2), 1 )
252252
// rightbottom = ( tan(fHorzFOV/2), -tan(fVertFOV/2), 1 )
253-
gbd.P = float3( P.z * ( pos2d * pos_decompression_params.zw - pos_decompression_params.xy ), P.z );
253+
gbd.P = float3( P.z * ( pos2d.xy * pos_decompression_params.zw - pos_decompression_params.xy ), P.z );
254254

255255
// reconstruct N
256256
gbd.N = gbuf_unpack_normal( P.xy );
@@ -273,21 +273,21 @@ gbuffer_data gbuffer_load_data( float2 tc, float2 pos2d, int iSample )
273273
return gbd;
274274
}
275275

276-
gbuffer_data gbuffer_load_data( float2 tc, float2 pos2d )
276+
gbuffer_data gbuffer_load_data( float2 tc, float4 pos2d )
277277
{
278278
return gbuffer_load_data( tc, pos2d, 0 );
279279
}
280280

281-
gbuffer_data gbuffer_load_data_offset( float2 tc, float2 OffsetTC, float2 pos2d )
281+
gbuffer_data gbuffer_load_data_offset( float2 tc, float2 OffsetTC, float4 pos2d )
282282
{
283-
float2 delta = ( ( OffsetTC - tc ) * pos_decompression_params2.xy );
283+
float4 delta = float4( ( OffsetTC - tc ) * pos_decompression_params2.xy, 0, 0 );
284284

285285
return gbuffer_load_data( OffsetTC, pos2d + delta, 0 );
286286
}
287287

288-
gbuffer_data gbuffer_load_data_offset( float2 tc, float2 OffsetTC, float2 pos2d, uint iSample )
288+
gbuffer_data gbuffer_load_data_offset( float2 tc, float2 OffsetTC, float4 pos2d, uint iSample )
289289
{
290-
float2 delta = ( ( OffsetTC - tc ) * pos_decompression_params2.xy );
290+
float4 delta = float4( ( OffsetTC - tc ) * pos_decompression_params2.xy, 0, 0 );
291291

292292
return gbuffer_load_data( OffsetTC, pos2d + delta, iSample );
293293
}

res/gamedata/shaders/gl/deffer_base_bump.vs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#include "common.h"
22
#include "iostructs\v_static_bump.h"
3-
#line 4 1
3+
44
v2p_bumped _main( v_in I )
55
{
66
// I.color.rgb = I.color.bgr; // Swizzle to compensate DX9/DX10 format mismatch

res/gamedata/shaders/gl/deffer_base_flat.vs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#include "common.h"
22
#include "iostructs\v_static_flat.h"
3-
#line 4 1
3+
44
v2p_flat _main ( v_in I )
55
{
66
I.Nh = unpack_D3DCOLOR(I.Nh);
-11 Bytes
Binary file not shown.

res/gamedata/shaders/gl/deffer_model_bump.vs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ v2p_bumped _main( v_model I )
2525
float3 Nw = mul (float3x3(m_W), float3(I.N));
2626
float3 hc_pos = float3(hemi_cube_pos_faces);
2727
float3 hc_neg = float3(hemi_cube_neg_faces);
28-
float3 hc_mixed= mix(hc_pos, hc_neg, lessThan(Nw, float3(0)));
28+
float3 hc_mixed= mask(lessThan(Nw, float3(0)), hc_neg, hc_pos);
2929
float hemi_val= dot( hc_mixed, abs(Nw) );
3030
hemi_val = saturate(hemi_val);
3131

res/gamedata/shaders/gl/deffer_model_flat.vs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ v2p_flat _main( v_model I )
2222
float3 Nw = mul (float3x3(m_W), float3(I.N));
2323
float3 hc_pos = float3(hemi_cube_pos_faces);
2424
float3 hc_neg = float3(hemi_cube_neg_faces);
25-
float3 hc_mixed= mix(hc_pos, hc_neg, lessThan(Nw, float3(0)));
25+
float3 hc_mixed= mask(lessThan(Nw, float3(0)), hc_neg, hc_pos);
2626
float hemi_val= dot( hc_mixed, abs(Nw) );
2727
hemi_val = saturate(hemi_val);
2828

res/gamedata/shaders/gl/iostructs/p_TL_sun.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ void main()
3030
I.Tex0 = p_TL_Tex0;
3131
I.Color = p_TL_Color;
3232

33-
SV_Target = _main (I);
3433
#ifdef MSAA_OPTIMIZATION
3534
#ifdef GBUFFER_OPTIMIZATION
3635
SV_Target = _main ( I, gl_FragCoord, gl_SampleID );
8 Bytes
Binary file not shown.

res/gamedata/shaders/gl/rain_layer.ps

18 Bytes
Binary file not shown.
32 Bytes
Binary file not shown.
40 Bytes
Binary file not shown.

res/gamedata/shaders/gl/shadow.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -453,9 +453,9 @@ float dx10_1_hw_hq_7x7( float3 tc )
453453
// loop over the rows
454454
for( row = -GS2; row <= GS2; row += 2 )
455455
{
456-
[unroll]for( col = -GS2; col <= GS2; col += 2 )
456+
for( col = -GS2; col <= GS2; col += 2 )
457457
{
458-
float4 v = ( tc.zzzz <= textureGatherOffset( s_dmap, tc.xy, int2( col, row ) ) ) ? (1.0).xxxx : (0.0).xxxx;
458+
float4 v = mask( lessThanEqual( tc.zzzz, textureGatherOffset( s_dmap, tc.xy, int2( col, row ) ) ), float4(1.0), float4(0.0));
459459

460460
if( row == -GS2 ) // top row
461461
{
@@ -482,7 +482,7 @@ float dx10_1_hw_hq_7x7( float3 tc )
482482
else if( col == GS2 ) // right
483483
s += dot( float4( 1.0, fc.x, fc.x, 1.0 ), v );
484484
else // center
485-
s += dot( (1.0).xxxx, v );
485+
s += dot( float4(1.0), v );
486486
}
487487
}
488488
}
@@ -821,7 +821,7 @@ float shadow_rain (float4 tc, float2 tcJ) // jittered sampling
821821

822822
//////////////////////////////////////////////////////////////////////////////////////////
823823
#ifdef USE_SUNMASK
824-
float3x4 m_sunmask; // ortho-projection
824+
uniform float3x4 m_sunmask; // ortho-projection
825825
float sunmask( float4 P )
826826
{
827827
float2 tc = mul( m_sunmask, P ); //

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ void sincos(float x, out float s, out float c) { s = sin(x); c = cos(x); }
4949
#define texCUBE texture
5050
#define asuint floatBitsToUint
5151
#define asfloat uintBitsToFloat
52+
#define mask(m,a,b) mix(b,a,m)
5253

5354
// Semantics assignment, maximum 16 slots
5455
#define COLOR 0

0 commit comments

Comments
 (0)