diff options
Diffstat (limited to 'src/shader')
| -rw-r--r-- | src/shader/CalcGradient.fx | 60 | ||||
| -rw-r--r-- | src/shader/CalcGradient_glsl_ps.h | 36 | ||||
| -rw-r--r-- | src/shader/CalcGradient_glsl_vs.h | 26 | ||||
| -rw-r--r-- | src/shader/FoamGeneration.fx | 54 | ||||
| -rw-r--r-- | src/shader/FoamGeneration_glsl_ps.h | 41 | ||||
| -rw-r--r-- | src/shader/FoamGeneration_glsl_vs.h | 25 | ||||
| -rw-r--r-- | src/shader/Quadtree_SM4_sig.fx | 2 | ||||
| -rw-r--r-- | src/shader/Quadtree_SM5_sig.fx | 2 |
8 files changed, 187 insertions, 59 deletions
diff --git a/src/shader/CalcGradient.fx b/src/shader/CalcGradient.fx index 58ffd3e..f2526a9 100644 --- a/src/shader/CalcGradient.fx +++ b/src/shader/CalcGradient.fx @@ -43,41 +43,41 @@ // Global variables //------------------------------------------------------------------------------------ -BEGIN_CBUFFER(nvsf_globals,0) -DECLARE_ATTR_CONSTANT(float4,nvsf_g_Scales, 0); // was: float nvsf_g_ChoppyScale, nvsf_g_GradMap2TexelWSScale -DECLARE_ATTR_CONSTANT(float4,nvsf_g_OneTexel_Left, 1); -DECLARE_ATTR_CONSTANT(float4,nvsf_g_OneTexel_Right,2); -DECLARE_ATTR_CONSTANT(float4,nvsf_g_OneTexel_Back, 3); -DECLARE_ATTR_CONSTANT(float4,nvsf_g_OneTexel_Front,4); +BEGIN_CBUFFER(globals,0) +DECLARE_ATTR_CONSTANT(float4,g_Scales, 0); // was: float g_ChoppyScale, g_GradMap2TexelWSScale +DECLARE_ATTR_CONSTANT(float4,g_OneTexel_Left, 1); +DECLARE_ATTR_CONSTANT(float4,g_OneTexel_Right,2); +DECLARE_ATTR_CONSTANT(float4,g_OneTexel_Back, 3); +DECLARE_ATTR_CONSTANT(float4,g_OneTexel_Front,4); END_CBUFFER -DECLARE_ATTR_SAMPLER(nvsf_g_textureDisplacementMap,nvsf_g_samplerDisplacementMap,0); +DECLARE_ATTR_SAMPLER(g_textureDisplacementMap,g_samplerDisplacementMap,0); #ifdef GFSDK_WAVEWORKS_GL -varying float2 nvsf_vInterpTexCoord; +varying float2 vInterpTexCoord; #endif #ifndef GFSDK_WAVEWORKS_OMIT_VS #ifdef GFSDK_WAVEWORKS_GL -attribute float4 nvsf_vInPos; -attribute float2 nvsf_vInTexCoord; -#define nvsf_vOutPos gl_Position +attribute float4 vInPos; +attribute float2 vInTexCoord; +#define vOutPos gl_Position void main() #else void vs( - float4 nvsf_vInPos SEMANTIC(POSITION), - float2 nvsf_vInTexCoord SEMANTIC(TEXCOORD0), - out float2 nvsf_vInterpTexCoord SEMANTIC(TEXCOORD0), - out float4 nvsf_vOutPos SEMANTIC(SV_Position) + float4 vInPos SEMANTIC(POSITION), + float2 vInTexCoord SEMANTIC(TEXCOORD0), + out float2 vInterpTexCoord SEMANTIC(TEXCOORD0), + out float4 vOutPos SEMANTIC(SV_Position) ) #endif { // No need to do matrix transform. - nvsf_vOutPos = nvsf_vInPos; + vOutPos = vInPos; // Pass through general texture coordinate. - nvsf_vInterpTexCoord = nvsf_vInTexCoord; + vInterpTexCoord = vInTexCoord; } #endif // !GFSDK_WAVEWORKS_OMIT_VS @@ -86,32 +86,32 @@ void vs( #ifndef GFSDK_WAVEWORKS_OMIT_PS #ifdef GFSDK_WAVEWORKS_GL -#define nvsf_Output gl_FragColor +#define Output gl_FragColor void main() #else void ps( - float2 nvsf_vInterpTexCoord SEMANTIC(TEXCOORD0), - out float4 nvsf_Output SEMANTIC(SV_Target) + float2 vInterpTexCoord SEMANTIC(TEXCOORD0), + out float4 Output SEMANTIC(SV_Target) ) #endif { // Sample neighbour texels - float3 nvsf_displace_left = SampleTex2D(nvsf_g_textureDisplacementMap, nvsf_g_samplerDisplacementMap, nvsf_vInterpTexCoord.xy + nvsf_g_OneTexel_Left.xy).rgb; - float3 nvsf_displace_right = SampleTex2D(nvsf_g_textureDisplacementMap, nvsf_g_samplerDisplacementMap, nvsf_vInterpTexCoord.xy + nvsf_g_OneTexel_Right.xy).rgb; - float3 nvsf_displace_back = SampleTex2D(nvsf_g_textureDisplacementMap, nvsf_g_samplerDisplacementMap, nvsf_vInterpTexCoord.xy + nvsf_g_OneTexel_Back.xy).rgb; - float3 nvsf_displace_front = SampleTex2D(nvsf_g_textureDisplacementMap, nvsf_g_samplerDisplacementMap, nvsf_vInterpTexCoord.xy + nvsf_g_OneTexel_Front.xy).rgb; + float3 displace_left = SampleTex2D(g_textureDisplacementMap, g_samplerDisplacementMap, vInterpTexCoord.xy + g_OneTexel_Left.xy).rgb; + float3 displace_right = SampleTex2D(g_textureDisplacementMap, g_samplerDisplacementMap, vInterpTexCoord.xy + g_OneTexel_Right.xy).rgb; + float3 displace_back = SampleTex2D(g_textureDisplacementMap, g_samplerDisplacementMap, vInterpTexCoord.xy + g_OneTexel_Back.xy).rgb; + float3 displace_front = SampleTex2D(g_textureDisplacementMap, g_samplerDisplacementMap, vInterpTexCoord.xy + g_OneTexel_Front.xy).rgb; // -------- Do not store the actual normal value, instead, it preserves two differential values. - float2 nvsf_gradient = float2(-(nvsf_displace_right.z - nvsf_displace_left.z) / max(0.01,1.0 + nvsf_g_Scales.y*(nvsf_displace_right.x - nvsf_displace_left.x)), -(nvsf_displace_front.z - nvsf_displace_back.z) / max(0.01,1.0+nvsf_g_Scales.y*(nvsf_displace_front.y - nvsf_displace_back.y))); - //float2 nvsf_gradient = {-(nvsf_displace_right.z - nvsf_displace_left.z), -(nvsf_displace_front.z - nvsf_displace_back.z) }; + float2 gradient = float2(-(displace_right.z - displace_left.z) / max(0.01,1.0 + g_Scales.y*(displace_right.x - displace_left.x)), -(displace_front.z - displace_back.z) / max(0.01,1.0+g_Scales.y*(displace_front.y - displace_back.y))); + //float2 gradient = {-(displace_right.z - displace_left.z), -(displace_front.z - displace_back.z) }; // Calculate Jacobian corelation from the partial differential of displacement field - float2 nvsf_Dx = (nvsf_displace_right.xy - nvsf_displace_left.xy) * nvsf_g_Scales.x; - float2 nvsf_Dy = (nvsf_displace_front.xy - nvsf_displace_back.xy) * nvsf_g_Scales.x; - float nvsf_J = (1.0f + nvsf_Dx.x) * (1.0f + nvsf_Dy.y) - nvsf_Dx.y * nvsf_Dy.x; + float2 Dx = (displace_right.xy - displace_left.xy) * g_Scales.x; + float2 Dy = (displace_front.xy - displace_back.xy) * g_Scales.x; + float J = (1.0f + Dx.x) * (1.0f + Dy.y) - Dx.y * Dy.x; // Output - nvsf_Output = float4(nvsf_gradient, nvsf_J, 0); + Output = float4(gradient, J, 0); } #endif // !GFSDK_WAVEWORKS_OMIT_PS diff --git a/src/shader/CalcGradient_glsl_ps.h b/src/shader/CalcGradient_glsl_ps.h new file mode 100644 index 0000000..2ef7ed8 --- /dev/null +++ b/src/shader/CalcGradient_glsl_ps.h @@ -0,0 +1,36 @@ +R"glsl( +//------------------------------------------------------------------------------------ +// Global variables +//------------------------------------------------------------------------------------ + +uniform vec4 g_Scales; +uniform vec4 g_OneTexel_Left; +uniform vec4 g_OneTexel_Right; +uniform vec4 g_OneTexel_Back; +uniform vec4 g_OneTexel_Front; + +uniform sampler2D g_samplerDisplacementMap; + +varying float2 vInterpTexCoord; + +void main() +{ + // Sample neighbour texels + float3 displace_left = texture(g_samplerDisplacementMap, vInterpTexCoord.xy + g_OneTexel_Left.xy).rgb; + float3 displace_right = texture(g_samplerDisplacementMap, vInterpTexCoord.xy + g_OneTexel_Right.xy).rgb; + float3 displace_back = texture(g_samplerDisplacementMap, vInterpTexCoord.xy + g_OneTexel_Back.xy).rgb; + float3 displace_front = texture(g_samplerDisplacementMap, vInterpTexCoord.xy + g_OneTexel_Front.xy).rgb; + + // -------- Do not store the actual normal value, instead, it preserves two differential values. + float2 gradient = float2(-(displace_right.z - displace_left.z) / max(0.01,1.0 + g_Scales.y*(displace_right.x - displace_left.x)), -(displace_front.z - displace_back.z) / max(0.01,1.0+g_Scales.y*(displace_front.y - displace_back.y))); + //float2 gradient = {-(displace_right.z - displace_left.z), -(displace_front.z - displace_back.z) }; + + // Calculate Jacobian corelation from the partial differential of displacement field + float2 Dx = (displace_right.xy - displace_left.xy) * g_Scales.x; + float2 Dy = (displace_front.xy - displace_back.xy) * g_Scales.x; + float J = (1.0f + Dx.x) * (1.0f + Dy.y) - Dx.y * Dy.x; + + // Output + gl_FragColor = float4(gradient, J, 0); +} +)glsl"; diff --git a/src/shader/CalcGradient_glsl_vs.h b/src/shader/CalcGradient_glsl_vs.h new file mode 100644 index 0000000..aa2747a --- /dev/null +++ b/src/shader/CalcGradient_glsl_vs.h @@ -0,0 +1,26 @@ +R"glsl( +//------------------------------------------------------------------------------------ +// Global variables +//------------------------------------------------------------------------------------ + +uniform vec4 g_Scales; +uniform vec4 g_OneTexel_Left; +uniform vec4 g_OneTexel_Right; +uniform vec4 g_OneTexel_Back; +uniform vec4 g_OneTexel_Front; + +uniform sampler2D g_textureDisplacementMap; + +varying float2 vInterpTexCoord; + +attribute float4 vInPos; +attribute float2 vInTexCoord; +void main() +{ + // No need to do matrix transform. + gl_Position = vInPos; + + // Pass through general texture coordinate. + vInterpTexCoord = vInTexCoord; +} +)glsl"; diff --git a/src/shader/FoamGeneration.fx b/src/shader/FoamGeneration.fx index 50a7007..a50e821 100644 --- a/src/shader/FoamGeneration.fx +++ b/src/shader/FoamGeneration.fx @@ -43,39 +43,39 @@ // Global variables //------------------------------------------------------------------------------------ -BEGIN_CBUFFER(nvsf_globals,0) -DECLARE_ATTR_CONSTANT(float4,nvsf_g_DissipationFactors,0); // x - the blur extents, y - the fadeout multiplier, z - the accumulation multiplier, w - foam generation threshold -DECLARE_ATTR_CONSTANT(float4,nvsf_g_SourceComponents ,1); // xyzw - weights of energy map components to be sampled -DECLARE_ATTR_CONSTANT(float4,nvsf_g_UVOffsets ,2); // xy - defines either horizontal offsets either vertical offsets +BEGIN_CBUFFER(globals,0) +DECLARE_ATTR_CONSTANT(float4,g_DissipationFactors,0); // x - the blur extents, y - the fadeout multiplier, z - the accumulation multiplier, w - foam generation threshold +DECLARE_ATTR_CONSTANT(float4,g_SourceComponents ,1); // xyzw - weights of energy map components to be sampled +DECLARE_ATTR_CONSTANT(float4,g_UVOffsets ,2); // xy - defines either horizontal offsets either vertical offsets END_CBUFFER -DECLARE_ATTR_SAMPLER(nvsf_g_textureEnergyMap,nvsf_g_samplerEnergyMap,0); +DECLARE_ATTR_SAMPLER(g_textureEnergyMap,g_samplerEnergyMap,0); #ifdef GFSDK_WAVEWORKS_GL -varying float2 nvsf_vInterpTexCoord; +varying float2 vInterpTexCoord; #endif #ifndef GFSDK_WAVEWORKS_OMIT_VS #ifdef GFSDK_WAVEWORKS_GL -attribute float4 nvsf_vInPos; -attribute float2 nvsf_vInTexCoord; -#define nvsf_vOutPos gl_Position +attribute float4 vInPos; +attribute float2 vInTexCoord; +#define vOutPos gl_Position void main() #else void vs( - float4 nvsf_vInPos SEMANTIC(POSITION), - float2 nvsf_vInTexCoord SEMANTIC(TEXCOORD0), - out float2 nvsf_vInterpTexCoord SEMANTIC(TEXCOORD0), - out float4 nvsf_vOutPos SEMANTIC(SV_Position) + float4 vInPos SEMANTIC(POSITION), + float2 vInTexCoord SEMANTIC(TEXCOORD0), + out float2 vInterpTexCoord SEMANTIC(TEXCOORD0), + out float4 vOutPos SEMANTIC(SV_Position) ) #endif { // No need to do matrix transform. - nvsf_vOutPos = nvsf_vInPos; + vOutPos = vInPos; // Pass through general texture coordinate. - nvsf_vInterpTexCoord = nvsf_vInTexCoord; + vInterpTexCoord = vInTexCoord; } #endif // !GFSDK_WAVEWORKS_OMIT_VS @@ -89,33 +89,33 @@ void vs( #ifndef GFSDK_WAVEWORKS_OMIT_PS #ifdef GFSDK_WAVEWORKS_GL -#define nvsf_Output gl_FragColor +#define Output gl_FragColor void main() #else void ps( - float2 nvsf_vInterpTexCoord SEMANTIC(TEXCOORD0), - out float4 nvsf_Output SEMANTIC(SV_Target) + float2 vInterpTexCoord SEMANTIC(TEXCOORD0), + out float4 Output SEMANTIC(SV_Target) ) #endif { - float2 nvsf_UVoffset = nvsf_g_UVOffsets.xy*nvsf_g_DissipationFactors.x; + float2 UVoffset = g_UVOffsets.xy*g_DissipationFactors.x; // blur with variable size kernel is done by doing 4 bilinear samples, // each sample is slightly offset from the center point - float nvsf_foamenergy1 = dot(nvsf_g_SourceComponents, SampleTex2D(nvsf_g_textureEnergyMap, nvsf_g_samplerEnergyMap, nvsf_vInterpTexCoord.xy + nvsf_UVoffset)); - float nvsf_foamenergy2 = dot(nvsf_g_SourceComponents, SampleTex2D(nvsf_g_textureEnergyMap, nvsf_g_samplerEnergyMap, nvsf_vInterpTexCoord.xy - nvsf_UVoffset)); - float nvsf_foamenergy3 = dot(nvsf_g_SourceComponents, SampleTex2D(nvsf_g_textureEnergyMap, nvsf_g_samplerEnergyMap, nvsf_vInterpTexCoord.xy + nvsf_UVoffset*2.0)); - float nvsf_foamenergy4 = dot(nvsf_g_SourceComponents, SampleTex2D(nvsf_g_textureEnergyMap, nvsf_g_samplerEnergyMap, nvsf_vInterpTexCoord.xy - nvsf_UVoffset*2.0)); + float foamenergy1 = dot(g_SourceComponents, SampleTex2D(g_textureEnergyMap, g_samplerEnergyMap, vInterpTexCoord.xy + UVoffset)); + float foamenergy2 = dot(g_SourceComponents, SampleTex2D(g_textureEnergyMap, g_samplerEnergyMap, vInterpTexCoord.xy - UVoffset)); + float foamenergy3 = dot(g_SourceComponents, SampleTex2D(g_textureEnergyMap, g_samplerEnergyMap, vInterpTexCoord.xy + UVoffset*2.0)); + float foamenergy4 = dot(g_SourceComponents, SampleTex2D(g_textureEnergyMap, g_samplerEnergyMap, vInterpTexCoord.xy - UVoffset*2.0)); - float nvsf_folding = max(0,SampleTex2D(nvsf_g_textureEnergyMap, nvsf_g_samplerEnergyMap, nvsf_vInterpTexCoord.xy).z); + float folding = max(0,SampleTex2D(g_textureEnergyMap, g_samplerEnergyMap, vInterpTexCoord.xy).z); - float nvsf_energy = nvsf_g_DissipationFactors.y*((nvsf_foamenergy1 + nvsf_foamenergy2 + nvsf_foamenergy3 + nvsf_foamenergy4)*0.25 + max(0,(1.0-nvsf_folding-nvsf_g_DissipationFactors.w))*nvsf_g_DissipationFactors.z); + float energy = g_DissipationFactors.y*((foamenergy1 + foamenergy2 + foamenergy3 + foamenergy4)*0.25 + max(0,(1.0-folding-g_DissipationFactors.w))*g_DissipationFactors.z); - nvsf_energy = min(1.0,nvsf_energy); + energy = min(1.0,energy); // Output - nvsf_Output = float4(nvsf_energy,nvsf_energy,nvsf_energy,nvsf_energy); + Output = float4(energy,energy,energy,energy); } #endif // !GFSDK_WAVEWORKS_OMIT_PS
\ No newline at end of file diff --git a/src/shader/FoamGeneration_glsl_ps.h b/src/shader/FoamGeneration_glsl_ps.h new file mode 100644 index 0000000..0ab5eed --- /dev/null +++ b/src/shader/FoamGeneration_glsl_ps.h @@ -0,0 +1,41 @@ +R"glsl( +//------------------------------------------------------------------------------------ +// Global variables +//------------------------------------------------------------------------------------ + +uniform vec4 g_DissipationFactors; +uniform vec4 g_SourceComponents; +uniform vec4 g_UVOffsets; + +uniform sampler2D g_samplerDisplacementMap; + +varying float2 vInterpTexCoord; + +// at 1st rendering step, the folding and the accumulated foam values are being read from gradient map (components z and w), +// blurred by X, summed, faded and written to foam energy map + +// at 2nd rendering step, the accumulated foam values are being read from foam energy texture, +// blurred by Y and written to w component of gradient map + +void main() +{ + + float2 UVoffset = g_UVOffsets.xy*g_DissipationFactors.x; + + // blur with variable size kernel is done by doing 4 bilinear samples, + // each sample is slightly offset from the center point + float foamenergy1 = dot(g_SourceComponents, texture(g_samplerEnergyMap, vInterpTexCoord.xy + UVoffset)); + float foamenergy2 = dot(g_SourceComponents, texture(g_samplerEnergyMap, vInterpTexCoord.xy - UVoffset)); + float foamenergy3 = dot(g_SourceComponents, texture(g_samplerEnergyMap, vInterpTexCoord.xy + UVoffset*2.0)); + float foamenergy4 = dot(g_SourceComponents, texture(g_samplerEnergyMap, vInterpTexCoord.xy - UVoffset*2.0)); + + float folding = max(0,texture(g_samplerEnergyMap, vInterpTexCoord.xy).z); + + float energy = g_DissipationFactors.y*((foamenergy1 + foamenergy2 + foamenergy3 + foamenergy4)*0.25 + max(0,(1.0-folding-g_DissipationFactors.w))*g_DissipationFactors.z); + + energy = min(1.0,energy); + + // Output + gl_FragColor = float4(energy,energy,energy,energy); +} +)glsl"; diff --git a/src/shader/FoamGeneration_glsl_vs.h b/src/shader/FoamGeneration_glsl_vs.h new file mode 100644 index 0000000..519efb2 --- /dev/null +++ b/src/shader/FoamGeneration_glsl_vs.h @@ -0,0 +1,25 @@ +R"glsl( +//------------------------------------------------------------------------------------ +// Global variables +//------------------------------------------------------------------------------------ + +uniform vec4 g_DissipationFactors; +uniform vec4 g_SourceComponents; +uniform vec4 g_UVOffsets; + +uniform sampler2D g_samplerDisplacementMap; + +varying float2 vInterpTexCoord; + +attribute float4 vInPos; +attribute float2 vInTexCoord; + +void main() +{ + // No need to do matrix transform. + gl_Position = vInPos; + + // Pass through general texture coordinate. + vInterpTexCoord = vInTexCoord; +} +)glsl";
\ No newline at end of file diff --git a/src/shader/Quadtree_SM4_sig.fx b/src/shader/Quadtree_SM4_sig.fx index f8d1a9d..c121356 100644 --- a/src/shader/Quadtree_SM4_sig.fx +++ b/src/shader/Quadtree_SM4_sig.fx @@ -35,5 +35,5 @@ float4 GFSDK_WAVEWORKS_VERTEX_INPUT_Sig(GFSDK_WAVEWORKS_VERTEX_INPUT In) : SV_Position { - return In.nvsf_vPos; + return In.vPos; } diff --git a/src/shader/Quadtree_SM5_sig.fx b/src/shader/Quadtree_SM5_sig.fx index c33887e..adefd2a 100644 --- a/src/shader/Quadtree_SM5_sig.fx +++ b/src/shader/Quadtree_SM5_sig.fx @@ -41,5 +41,5 @@ float4 GFSDK_WAVEWORKS_VERTEX_INPUT_Sig(GFSDK_WAVEWORKS_VERTEX_INPUT In) : SV_Position { - return In.nvsf_vPos; + return In.vPos; } |