-
-
Notifications
You must be signed in to change notification settings - Fork 454
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
shaders: Add GLSL port of combination shaders.
This includes the DOF and SSAO shaders.
- Loading branch information
Showing
30 changed files
with
519 additions
and
37 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#include "common.h" | ||
#include "iostructs\v_combine.h" | ||
#line 4 2 | ||
////////////////////////////////////////////////////////////////////////////////////////// | ||
// Vertex | ||
v2p _main ( _in I ) | ||
{ | ||
v2p O; | ||
O.hpos = float4 (I.P.x, -I.P.y, 0, 1); | ||
float scale = texelFetch(s_tonemap,int2(0,0),0).x; | ||
O.tc0 = float4 (I.P.zw, scale, scale); | ||
O.tcJ = I.tcJ; | ||
return O; | ||
} |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#ifndef common_cbuffers_h_included | ||
#define common_cbuffers_h_included | ||
|
||
#ifndef MSAA_OPTIMIZATION | ||
// Used by dynamic lights and volumetric effects | ||
// TODO: OGL: Use constant buffers. | ||
//cbuffer dynamic_light | ||
//{ | ||
uniform float4 Ldynamic_color; // dynamic light color (rgb1) - spot/point/sun | ||
uniform float4 Ldynamic_pos; // dynamic light pos+1/range(w) - spot/point | ||
uniform float4 Ldynamic_dir; // dynamic light direction - sun | ||
//} | ||
#else | ||
//cbuffer dynamic_light | ||
//{ | ||
uniform float4 Ldynamic_color; // dynamic light color (rgb1) - spot/point/sun | ||
uniform float4 Ldynamic_pos; // dynamic light pos+1/range(w) - spot/point | ||
uniform float4 Ldynamic_dir; // dynamic light direction - sun | ||
//} | ||
#endif | ||
|
||
#endif // common_cbuffers_h_included |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
#ifndef DOF_H_INCLUDED | ||
#define DOF_H_INCLUDED | ||
|
||
//#define USE_DOF | ||
|
||
#ifndef USE_DOF | ||
|
||
float3 dof(float2 center) | ||
{ | ||
float3 img = tex2D (s_image, center).rgb; | ||
return img; | ||
} | ||
|
||
#else // USE_DOF | ||
|
||
// x - near y - focus z - far w - sky distance | ||
float4 dof_params; | ||
float3 dof_kernel; // x,y - resolution pre-scaled z - just kernel size | ||
|
||
float DOFFactor(float depth) | ||
{ | ||
float dist_to_focus = depth-dof_params.y; | ||
float blur_far = saturate( dist_to_focus | ||
/ (dof_params.z-dof_params.y) ); | ||
float blur_near = saturate( dist_to_focus | ||
/ (dof_params.x-dof_params.y) ); | ||
float blur = blur_near+blur_far; | ||
blur*=blur; | ||
return blur; | ||
} | ||
|
||
|
||
//#define MAXCOF 5.f | ||
#define MAXCOF 7.f | ||
#define EPSDEPTHDOF 0.0001f | ||
float3 dof(float2 center) | ||
{ | ||
// Scale tap offsets based on render target size | ||
#ifndef USE_MSAA | ||
float depth = tex2D(s_position,center).z; | ||
#else | ||
float depth = texelFetch(s_position, int2( center * pos_decompression_params2.xy ), 0, 0).z; | ||
#endif | ||
if (depth <= EPSDEPTHDOF) depth = dof_params.w; | ||
float blur = DOFFactor(depth); | ||
|
||
//float blur = 1; | ||
// const amount of blur: define controlled | ||
//float2 scale = float2 (.5f / 1024.f, .5f / 768.f) * MAXCOF * blur; | ||
// const amount of blur: engine controlled | ||
float2 scale = float2 (.5f / 1024.f, .5f / 768.f) * (dof_kernel.z * blur); | ||
// amount of blur varies according to resolution | ||
// but kernel size in pixels is fixed. | ||
// float2 scale = dof_kernel.xy * blur; | ||
|
||
// poisson | ||
float2 o [12]; | ||
o[0] = float2(-0.326212f , -0.405810f)*scale; | ||
o[1] = float2(-0.840144f , -0.073580f)*scale; | ||
o[2] = float2(-0.695914f , 0.457137f)*scale; | ||
o[3] = float2(-0.203345f , 0.620716f)*scale; | ||
o[4] = float2( 0.962340f , -0.194983f)*scale; | ||
o[5] = float2( 0.473434f , -0.480026f)*scale; | ||
o[6] = float2( 0.519456f , 0.767022f)*scale; | ||
o[7] = float2( 0.185461f , -0.893124f)*scale; | ||
o[8] = float2( 0.507431f , 0.064425f)*scale; | ||
o[9] = float2( 0.896420f , 0.412458f)*scale; | ||
o[10] = float2(-0.321940f , -0.932615f)*scale; | ||
o[11] = float2(-0.791559f , -0.597710f)*scale; | ||
|
||
// sample | ||
float3 sum = tex2D(s_image,center).rgb; | ||
float contrib = 1.f; | ||
|
||
for (int i=0; i<12; i++) | ||
{ | ||
float2 tap = center + o[i]; | ||
float4 tap_color = tex2D (s_image,tap); | ||
#ifndef USE_MSAA | ||
float tap_depth = tex2D (s_position,tap).z; | ||
#else | ||
float tap_depth = texelFetch(s_position, int2( tap* pos_decompression_params2.xy ), 0, 0).z; | ||
#endif | ||
if (tap_depth <= EPSDEPTHDOF) tap_depth = dof_params.w; | ||
float tap_contrib = DOFFactor(tap_depth); | ||
sum += tap_color.rgb * tap_contrib; | ||
contrib += tap_contrib; | ||
} | ||
|
||
return float3 (sum/contrib); | ||
} | ||
|
||
#endif // USE_DOF | ||
|
||
#endif // DOF_H_INCLUDED |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
#ifndef HMODEL_H | ||
#define HMODEL_H | ||
|
||
#include "common.h" | ||
#line 6 8 | ||
//uniform samplerCUBE env_s0 ; | ||
//uniform samplerCUBE env_s1 ; | ||
//uniform samplerCUBE sky_s0 ; | ||
//uniform samplerCUBE sky_s1 ; | ||
|
||
TextureCube env_s0; | ||
TextureCube env_s1; | ||
TextureCube sky_s0; | ||
TextureCube sky_s1; | ||
|
||
uniform float4 env_color; // color.w = lerp factor | ||
uniform float3x4 m_v2w; | ||
|
||
void hmodel | ||
( | ||
out float3 hdiffuse, out float3 hspecular, | ||
float m, float h, float s, float3 Pnt, float3 normal | ||
) | ||
{ | ||
// hscale - something like diffuse reflection | ||
float3 nw = mul( m_v2w, normal ); | ||
float hscale = h; //. * (.5h + .5h*nw.y); | ||
|
||
#ifdef USE_GAMMA_22 | ||
hscale = (hscale*hscale); // make it more linear | ||
#endif | ||
|
||
// reflection vector | ||
float3 v2PntL = normalize( Pnt ); | ||
float3 v2Pnt = mul( m_v2w, v2PntL ); | ||
float3 vreflect= reflect( v2Pnt, nw ); | ||
float hspec = .5f + .5f * dot( vreflect, v2Pnt ); | ||
|
||
// material // sample material | ||
//float4 light = tex3D( s_material, float3(hscale, hspec, m) ); | ||
// float4 light = s_material.Sample( smp_material, float3( hscale, hspec, m ) ).xxxy; | ||
float4 light = textureLod(s_material, float3( hscale, hspec, m ), 0 ).xxxy; | ||
// float4 light = float4(1,1,1,1); | ||
|
||
// diffuse color | ||
// float3 e0d = texCUBE( env_s0, nw ); | ||
// float3 e1d = texCUBE( env_s1, nw ); | ||
// float3 e0d = env_s0.Sample( smp_rtlinear, nw ); | ||
// float3 e1d = env_s1.Sample( smp_rtlinear, nw ); | ||
float3 e0d = textureLod( env_s0, nw, 0 ).rgb; | ||
float3 e1d = textureLod( env_s1, nw, 0 ).rgb; | ||
float3 env_d = env_color.xyz * lerp( e0d, e1d, env_color.w ); | ||
env_d *=env_d; // contrast | ||
hdiffuse= env_d * light.xyz + L_ambient.rgb; | ||
|
||
// specular color | ||
vreflect.y = vreflect.y*2-1; // fake remapping | ||
// float3 e0s = texCUBE( env_s0, vreflect ); | ||
// float3 e1s = texCUBE( env_s1, vreflect ); | ||
// float3 e0s = env_s0.Sample( smp_rtlinear, vreflect ); | ||
// float3 e1s = env_s1.Sample( smp_rtlinear, vreflect ); | ||
float3 e0s = textureLod( env_s0, vreflect, 0 ).rgb; | ||
float3 e1s = textureLod( env_s1, vreflect, 0 ).rgb; | ||
float3 env_s = env_color.xyz * lerp( e0s, e1s, env_color.w); | ||
env_s *=env_s; // contrast | ||
hspecular = env_s*light.w*s; //*h*m*s ; //env_s *light.w * s; | ||
} | ||
|
||
/* | ||
void hmodel_table (out float3 hdiffuse, out float3 hspecular, float m, float h, float s, float3 point, float3 normal) | ||
{ | ||
// hscale - something like diffuse reflection | ||
float hscale = h; | ||
// reflection vector | ||
float3 v2point = normalize (Pnt); | ||
float3 vreflect= reflect (v2point,normal); | ||
float hspec = .5h+.5h*dot (vreflect,v2point); | ||
// material | ||
float4 light = tex3D (s_material, float3(hscale, hspec, m) ); // sample material | ||
// diffuse color | ||
float3 env_d = texCUBE (env_s0,normal); | ||
// specular color | ||
float3 env_s = texCUBE (env_s0,vreflect); | ||
// | ||
hdiffuse = env_d *light.xyz + L_ambient.rgb ; | ||
hspecular = env_s *light.w * s ; | ||
} | ||
*/ | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
|
||
out vec4 SV_Target; | ||
in vec4 gl_FragCoord; | ||
|
||
layout(location = TEXCOORD0) in float2 p_aa_AA_Tex0 ; // TEXCOORD0; | ||
layout(location = TEXCOORD1) in float2 p_aa_AA_Tex1 ; // TEXCOORD1; | ||
layout(location = TEXCOORD2) in float2 p_aa_AA_Tex2 ; // TEXCOORD2; | ||
layout(location = TEXCOORD3) in float2 p_aa_AA_Tex3 ; // TEXCOORD3; | ||
layout(location = TEXCOORD4) in float2 p_aa_AA_Tex4 ; // TEXCOORD4; | ||
layout(location = TEXCOORD5) in float4 p_aa_AA_Tex5 ; // TEXCOORD5; | ||
layout(location = TEXCOORD6) in float4 p_aa_AA_Tex6 ; // TEXCOORD6; | ||
|
||
#ifdef GBUFFER_OPTIMIZATION | ||
float4 _main ( v_aa_AA I, float4 pos2d ); | ||
#else | ||
float4 _main ( v_aa_AA I ); | ||
#endif | ||
|
||
void main() | ||
{ | ||
v_aa_AA I; | ||
I.P = gl_FragCoord; | ||
I.Tex0 = p_aa_AA_Tex0; | ||
I.Tex1 = p_aa_AA_Tex1; | ||
I.Tex2 = p_aa_AA_Tex2; | ||
I.Tex3 = p_aa_AA_Tex3; | ||
I.Tex4 = p_aa_AA_Tex4; | ||
I.Tex5 = p_aa_AA_Tex5; | ||
I.Tex6 = p_aa_AA_Tex6; | ||
|
||
#ifdef GBUFFER_OPTIMIZATION | ||
SV_Target = _main ( I, gl_FragCoord ); | ||
#else | ||
SV_Target = _main ( I ); | ||
#endif | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
|
||
out vec4 SV_Target0; | ||
out vec4 SV_Target1; | ||
in vec4 gl_FragCoord; | ||
#ifdef MSAA_OPTIMIZATION | ||
in int gl_SampleID; | ||
#endif | ||
#line 9 10 | ||
struct _input | ||
{ | ||
float4 tc0 ; // TEXCOORD0; // tc.xy, tc.w = tonemap scale | ||
float2 tcJ ; // TEXCOORD1; // jitter coords | ||
float4 pos2d ; // SV_Position; | ||
}; | ||
|
||
struct _out | ||
{ | ||
float4 low ; // SV_Target0; | ||
float4 high ; // SV_Target1; | ||
}; | ||
|
||
layout(location = TEXCOORD0) in float4 p_combine_tc0 ; // TEXCOORD0; // tc.xy, tc.w = tonemap scale | ||
layout(location = TEXCOORD1) in float2 p_combine_tcJ ; // TEXCOORD1; // jitter coords | ||
|
||
#ifndef MSAA_OPTIMIZATION | ||
_out _main ( _input I ); | ||
#else | ||
_out _main ( _input I, uint iSample ); | ||
#endif | ||
|
||
void main() | ||
{ | ||
_input I; | ||
I.tc0 = p_combine_tc0; | ||
I.tcJ = p_combine_tcJ; | ||
I.pos2d = gl_FragCoord; | ||
|
||
#ifndef MSAA_OPTIMIZATION | ||
_out O = _main ( I ); | ||
#else | ||
_out O = _main ( I, gl_SampleID ); | ||
#endif | ||
|
||
SV_Target0 = O.low; | ||
SV_Target1 = O.high; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
|
||
out vec4 SV_Target; | ||
in vec4 gl_FragCoord; | ||
#ifdef USE_MSAA | ||
out float gl_FragDepth; | ||
#endif | ||
|
||
struct c2_out | ||
{ | ||
float4 Color ; // SV_Target; | ||
#ifdef USE_MSAA | ||
float Depth ; // SV_Depth; | ||
#endif | ||
}; | ||
|
||
layout(location = TEXCOORD0) in float2 p_aa_AA_Tex0 ; // TEXCOORD0; | ||
layout(location = TEXCOORD1) in float2 p_aa_AA_Tex1 ; // TEXCOORD1; | ||
layout(location = TEXCOORD2) in float2 p_aa_AA_Tex2 ; // TEXCOORD2; | ||
layout(location = TEXCOORD3) in float2 p_aa_AA_Tex3 ; // TEXCOORD3; | ||
layout(location = TEXCOORD4) in float2 p_aa_AA_Tex4 ; // TEXCOORD4; | ||
layout(location = TEXCOORD5) in float4 p_aa_AA_Tex5 ; // TEXCOORD5; | ||
layout(location = TEXCOORD6) in float4 p_aa_AA_Tex6 ; // TEXCOORD6; | ||
|
||
c2_out _main ( v2p_aa_AA I ); | ||
|
||
void main() | ||
{ | ||
v2p_aa_AA I; | ||
I.HPos = gl_FragCoord; | ||
I.Tex0 = p_aa_AA_Tex0; | ||
I.Tex1 = p_aa_AA_Tex1; | ||
I.Tex2 = p_aa_AA_Tex2; | ||
I.Tex3 = p_aa_AA_Tex3; | ||
I.Tex4 = p_aa_AA_Tex4; | ||
I.Tex5 = p_aa_AA_Tex5; | ||
I.Tex6 = p_aa_AA_Tex6; | ||
|
||
c2_out O = _main (I); | ||
|
||
SV_Target = O.Color; | ||
#ifdef USE_MSAA | ||
gl_FragDepth = O.Depth; | ||
#endif | ||
} |
Oops, something went wrong.