Skip to content

Commit

Permalink
shaders: Add G-Buffer support to GLSL ports.
Browse files Browse the repository at this point in the history
  • Loading branch information
CrossVR committed Mar 24, 2016
1 parent c47e38c commit dfe5389
Show file tree
Hide file tree
Showing 14 changed files with 18 additions and 18 deletions.
Binary file modified res/gamedata/shaders/gl/combine_2_aa.ps
Binary file not shown.
18 changes: 9 additions & 9 deletions res/gamedata/shaders/gl/common_functions.h
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ f_deffer pack_gbuffer( float4 norm, float4 pos, float4 col, uint imask )
res.Ne = norm;
res.C = col;
#else
res.position = float4( gbuf_pack_normal( norm ), pos.z, gbuf_pack_hemi_mtl( norm.w, pos.w ) );
res.position = float4( gbuf_pack_normal( norm.xyz ), pos.z, gbuf_pack_hemi_mtl( norm.w, pos.w ) );
res.C = col;
#endif

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

#ifdef GBUFFER_OPTIMIZATION
gbuffer_data gbuffer_load_data( float2 tc, float2 pos2d, int iSample )
gbuffer_data gbuffer_load_data( float2 tc, float4 pos2d, uint iSample )
{
gbuffer_data gbd;

gbd.P = float3(0,0,0);
gbd.hemi = 0;
gbd.mtl = 0;
gbd.C = 0;
gbd.C = float3(0,0,0);
gbd.N = float3(0,0,0);

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

// reconstruct N
gbd.N = gbuf_unpack_normal( P.xy );
Expand All @@ -273,21 +273,21 @@ gbuffer_data gbuffer_load_data( float2 tc, float2 pos2d, int iSample )
return gbd;
}

gbuffer_data gbuffer_load_data( float2 tc, float2 pos2d )
gbuffer_data gbuffer_load_data( float2 tc, float4 pos2d )
{
return gbuffer_load_data( tc, pos2d, 0 );
}

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

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

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

return gbuffer_load_data( OffsetTC, pos2d + delta, iSample );
}
Expand Down
2 changes: 1 addition & 1 deletion res/gamedata/shaders/gl/deffer_base_bump.vs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "common.h"
#include "iostructs\v_static_bump.h"
#line 4 1

v2p_bumped _main( v_in I )
{
// I.color.rgb = I.color.bgr; // Swizzle to compensate DX9/DX10 format mismatch
Expand Down
2 changes: 1 addition & 1 deletion res/gamedata/shaders/gl/deffer_base_flat.vs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "common.h"
#include "iostructs\v_static_flat.h"
#line 4 1

v2p_flat _main ( v_in I )
{
I.Nh = unpack_D3DCOLOR(I.Nh);
Expand Down
Binary file modified res/gamedata/shaders/gl/deffer_impl_flat.ps
Binary file not shown.
2 changes: 1 addition & 1 deletion res/gamedata/shaders/gl/deffer_model_bump.vs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ v2p_bumped _main( v_model I )
float3 Nw = mul (float3x3(m_W), float3(I.N));
float3 hc_pos = float3(hemi_cube_pos_faces);
float3 hc_neg = float3(hemi_cube_neg_faces);
float3 hc_mixed= mix(hc_pos, hc_neg, lessThan(Nw, float3(0)));
float3 hc_mixed= mask(lessThan(Nw, float3(0)), hc_neg, hc_pos);
float hemi_val= dot( hc_mixed, abs(Nw) );
hemi_val = saturate(hemi_val);

Expand Down
2 changes: 1 addition & 1 deletion res/gamedata/shaders/gl/deffer_model_flat.vs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ v2p_flat _main( v_model I )
float3 Nw = mul (float3x3(m_W), float3(I.N));
float3 hc_pos = float3(hemi_cube_pos_faces);
float3 hc_neg = float3(hemi_cube_neg_faces);
float3 hc_mixed= mix(hc_pos, hc_neg, lessThan(Nw, float3(0)));
float3 hc_mixed= mask(lessThan(Nw, float3(0)), hc_neg, hc_pos);
float hemi_val= dot( hc_mixed, abs(Nw) );
hemi_val = saturate(hemi_val);

Expand Down
1 change: 0 additions & 1 deletion res/gamedata/shaders/gl/iostructs/p_TL_sun.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ void main()
I.Tex0 = p_TL_Tex0;
I.Color = p_TL_Color;

SV_Target = _main (I);
#ifdef MSAA_OPTIMIZATION
#ifdef GBUFFER_OPTIMIZATION
SV_Target = _main ( I, gl_FragCoord, gl_SampleID );
Expand Down
Binary file modified res/gamedata/shaders/gl/rain_apply_normal.ps
Binary file not shown.
Binary file modified res/gamedata/shaders/gl/rain_layer.ps
Binary file not shown.
Binary file modified res/gamedata/shaders/gl/rain_patch_normal.ps
Binary file not shown.
Binary file modified res/gamedata/shaders/gl/rain_patch_normal_new.ps
Binary file not shown.
8 changes: 4 additions & 4 deletions res/gamedata/shaders/gl/shadow.h
Original file line number Diff line number Diff line change
Expand Up @@ -453,9 +453,9 @@ float dx10_1_hw_hq_7x7( float3 tc )
// loop over the rows
for( row = -GS2; row <= GS2; row += 2 )
{
[unroll]for( col = -GS2; col <= GS2; col += 2 )
for( col = -GS2; col <= GS2; col += 2 )
{
float4 v = ( tc.zzzz <= textureGatherOffset( s_dmap, tc.xy, int2( col, row ) ) ) ? (1.0).xxxx : (0.0).xxxx;
float4 v = mask( lessThanEqual( tc.zzzz, textureGatherOffset( s_dmap, tc.xy, int2( col, row ) ) ), float4(1.0), float4(0.0));

if( row == -GS2 ) // top row
{
Expand All @@ -482,7 +482,7 @@ float dx10_1_hw_hq_7x7( float3 tc )
else if( col == GS2 ) // right
s += dot( float4( 1.0, fc.x, fc.x, 1.0 ), v );
else // center
s += dot( (1.0).xxxx, v );
s += dot( float4(1.0), v );
}
}
}
Expand Down Expand Up @@ -821,7 +821,7 @@ float shadow_rain (float4 tc, float2 tcJ) // jittered sampling

//////////////////////////////////////////////////////////////////////////////////////////
#ifdef USE_SUNMASK
float3x4 m_sunmask; // ortho-projection
uniform float3x4 m_sunmask; // ortho-projection
float sunmask( float4 P )
{
float2 tc = mul( m_sunmask, P ); //
Expand Down
1 change: 1 addition & 0 deletions res/gamedata/shaders/gl/shared/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ void sincos(float x, out float s, out float c) { s = sin(x); c = cos(x); }
#define texCUBE texture
#define asuint floatBitsToUint
#define asfloat uintBitsToFloat
#define mask(m,a,b) mix(b,a,m)

// Semantics assignment, maximum 16 slots
#define COLOR 0
Expand Down

0 comments on commit dfe5389

Please sign in to comment.