diff options
| author | Jason Maskell <[email protected]> | 2016-05-09 10:39:54 +0200 |
|---|---|---|
| committer | Jason Maskell <[email protected]> | 2016-05-09 10:39:54 +0200 |
| commit | 79b3462799c28af8ba586349bd671b1b56e72353 (patch) | |
| tree | 3b06e36c390254c0dc7f3733a0d32af213d87293 /src/shader | |
| download | waveworks_archive-79b3462799c28af8ba586349bd671b1b56e72353.tar.xz waveworks_archive-79b3462799c28af8ba586349bd671b1b56e72353.zip | |
Initial commit with PS4 and XBone stuff trimmed.
Diffstat (limited to 'src/shader')
| -rw-r--r-- | src/shader/Attributes.fxh | 403 | ||||
| -rw-r--r-- | src/shader/CalcGradient.fx | 117 | ||||
| -rw-r--r-- | src/shader/CalcGradient_SM3.fx | 30 | ||||
| -rw-r--r-- | src/shader/CalcGradient_SM4.fx | 30 | ||||
| -rw-r--r-- | src/shader/CalcGradient_glsl.ps | 31 | ||||
| -rw-r--r-- | src/shader/CalcGradient_glsl.vs | 31 | ||||
| -rw-r--r-- | src/shader/CalcGradient_gnm.fx | 30 | ||||
| -rw-r--r-- | src/shader/Common.fxh | 79 | ||||
| -rw-r--r-- | src/shader/FoamGeneration.fx | 121 | ||||
| -rw-r--r-- | src/shader/FoamGeneration_SM3.fx | 30 | ||||
| -rw-r--r-- | src/shader/FoamGeneration_SM4.fx | 30 | ||||
| -rw-r--r-- | src/shader/FoamGeneration_glsl.ps | 31 | ||||
| -rw-r--r-- | src/shader/FoamGeneration_glsl.vs | 31 | ||||
| -rw-r--r-- | src/shader/FoamGeneration_gnm.fx | 30 | ||||
| -rw-r--r-- | src/shader/Quadtree.fxh | 178 | ||||
| -rw-r--r-- | src/shader/Quadtree_GNM_sig.fx | 43 | ||||
| -rw-r--r-- | src/shader/Quadtree_SM4_sig.fx | 39 | ||||
| -rw-r--r-- | src/shader/Quadtree_SM5_sig.fx | 45 |
18 files changed, 1329 insertions, 0 deletions
diff --git a/src/shader/Attributes.fxh b/src/shader/Attributes.fxh new file mode 100644 index 0000000..d887f8c --- /dev/null +++ b/src/shader/Attributes.fxh @@ -0,0 +1,403 @@ +/* + * This code contains NVIDIA Confidential Information and is disclosed + * under the Mutual Non-Disclosure Agreement. + * + * Notice + * ALL NVIDIA DESIGN SPECIFICATIONS AND CODE ("MATERIALS") ARE PROVIDED "AS IS" NVIDIA MAKES + * NO REPRESENTATIONS, WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO + * THE MATERIALS, AND EXPRESSLY DISCLAIMS ANY IMPLIED WARRANTIES OF NONINFRINGEMENT, + * MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. + * + * NVIDIA Corporation assumes no responsibility for the consequences of use of such + * information or for any infringement of patents or other rights of third parties that may + * result from its use. No license is granted by implication or otherwise under any patent + * or patent rights of NVIDIA Corporation. No third party distribution is allowed unless + * expressly authorized by NVIDIA. Details are subject to change without notice. + * This code supersedes and replaces all information previously supplied. + * NVIDIA Corporation products are not authorized for use as critical + * components in life support devices or systems without express written approval of + * NVIDIA Corporation. + * + * Copyright � 2008- 2013 NVIDIA Corporation. All rights reserved. + * + * NVIDIA Corporation and its licensors retain all intellectual property and proprietary + * rights in and to this software and related documentation and any modifications thereto. + * Any use, reproduction, disclosure or distribution of this software and related + * documentation without an express license agreement from NVIDIA Corporation is + * strictly prohibited. + */ + +#ifndef _GFSDK_WAVEWORKS_ATTRIBUTES_FX +#define _GFSDK_WAVEWORKS_ATTRIBUTES_FX + +/* + * + * + */ + +#include "GFSDK_WaveWorks_Common.fxh" + +/* + * + * + */ + +#if defined(GFSDK_WAVEWORKS_SM3) || defined(GFSDK_WAVEWORKS_GL) + #define GFSDK_WAVEWORKS_BEGIN_ATTR_VS_CBUFFER(Label) + #define GFSDK_WAVEWORKS_END_ATTR_VS_CBUFFER + #define GFSDK_WAVEWORKS_BEGIN_ATTR_PS_CBUFFER(Label) + #define GFSDK_WAVEWORKS_END_ATTR_PS_CBUFFER +#endif + + +#if defined( GFSDK_WAVEWORKS_USE_TESSELLATION ) + #define GFSDK_WAVEWORKS_BEGIN_ATTR_DISPLACEMENT_CBUFFER(Label) GFSDK_WAVEWORKS_BEGIN_ATTR_DS_CBUFFER(Label) + #define GFSDK_WAVEWORKS_DECLARE_ATTR_DISPLACEMENT_CONSTANT(Type,Label,Regoff) GFSDK_WAVEWORKS_DECLARE_ATTR_DS_CONSTANT(Type,Label,Regoff) + #define GFSDK_WAVEWORKS_END_ATTR_DISPLACEMENT_CBUFFER GFSDK_WAVEWORKS_END_ATTR_DS_CBUFFER + #define GFSDK_WAVEWORKS_DECLARE_ATTR_DISPLACEMENT_SAMPLER(SampLabel,TexLabel,Regoff) GFSDK_WAVEWORKS_DECLARE_ATTR_DS_SAMPLER(SampLabel,TexLabel,Regoff) + #define GFSDK_WAVEWORKS_DECLARE_ATTR_DISPLACEMENT_SAMPLER_TEXTUREARRAY(SampLabel,TexLabel,Regoff) GFSDK_WAVEWORKS_DECLARE_ATTR_DS_SAMPLER_TEXTUREARRAY(SampLabel,TexLabel,Regoff) +#else + #define GFSDK_WAVEWORKS_BEGIN_ATTR_DISPLACEMENT_CBUFFER(Label) GFSDK_WAVEWORKS_BEGIN_ATTR_VS_CBUFFER(Label) + #define GFSDK_WAVEWORKS_DECLARE_ATTR_DISPLACEMENT_CONSTANT(Type,Label,Regoff) GFSDK_WAVEWORKS_DECLARE_ATTR_VS_CONSTANT(Type,Label,Regoff) + #define GFSDK_WAVEWORKS_END_ATTR_DISPLACEMENT_CBUFFER GFSDK_WAVEWORKS_END_ATTR_VS_CBUFFER + #define GFSDK_WAVEWORKS_DECLARE_ATTR_DISPLACEMENT_SAMPLER(SampLabel,TexLabel,Regoff) GFSDK_WAVEWORKS_DECLARE_ATTR_VS_SAMPLER(SampLabel,TexLabel,Regoff) + #define GFSDK_WAVEWORKS_DECLARE_ATTR_DISPLACEMENT_SAMPLER_TEXTUREARRAY(SampLabel,TexLabel,Regoff) GFSDK_WAVEWORKS_DECLARE_ATTR_VS_SAMPLER_TEXTUREARRAY(SampLabel,TexLabel,Regoff) +#endif + +GFSDK_WAVEWORKS_BEGIN_ATTR_DISPLACEMENT_CBUFFER(nvsf_attr_vs_buffer) +GFSDK_WAVEWORKS_DECLARE_ATTR_DISPLACEMENT_CONSTANT(float3, nvsf_g_WorldEye, 0) +#if defined( GFSDK_WAVEWORKS_GL ) + GFSDK_WAVEWORKS_DECLARE_ATTR_DISPLACEMENT_CONSTANT(float, nvsf_g_UseTextureArrays, 1) +#else + GFSDK_WAVEWORKS_DECLARE_ATTR_DISPLACEMENT_CONSTANT(float, nvsf_g_Pad1, 1) +#endif +GFSDK_WAVEWORKS_DECLARE_ATTR_DISPLACEMENT_CONSTANT(float4, nvsf_g_UVScaleCascade0123, 2) +GFSDK_WAVEWORKS_END_ATTR_DISPLACEMENT_CBUFFER + +GFSDK_WAVEWORKS_DECLARE_ATTR_DISPLACEMENT_SAMPLER(nvsf_g_samplerDisplacementMap0, nvsf_g_textureDisplacementMap0, 0) +GFSDK_WAVEWORKS_DECLARE_ATTR_DISPLACEMENT_SAMPLER(nvsf_g_samplerDisplacementMap1, nvsf_g_textureDisplacementMap1, 1) +GFSDK_WAVEWORKS_DECLARE_ATTR_DISPLACEMENT_SAMPLER(nvsf_g_samplerDisplacementMap2, nvsf_g_textureDisplacementMap2, 2) +GFSDK_WAVEWORKS_DECLARE_ATTR_DISPLACEMENT_SAMPLER(nvsf_g_samplerDisplacementMap3, nvsf_g_textureDisplacementMap3, 3) + +#if defined( GFSDK_WAVEWORKS_GL ) + GFSDK_WAVEWORKS_DECLARE_ATTR_DISPLACEMENT_SAMPLER_TEXTUREARRAY(nvsf_g_samplerDisplacementMapTextureArray, nvsf_g_textureArrayDisplacementMap, 4) +#endif + +GFSDK_WAVEWORKS_BEGIN_ATTR_PS_CBUFFER(nvsf_attr_ps_buffer) +GFSDK_WAVEWORKS_DECLARE_ATTR_PS_CONSTANT(float, nvsf_g_TexelLength_x2_PS, 0) +GFSDK_WAVEWORKS_DECLARE_ATTR_PS_CONSTANT(float, nvsf_g_Cascade1Scale_PS, 1) +GFSDK_WAVEWORKS_DECLARE_ATTR_PS_CONSTANT(float, nvsf_g_Cascade1TexelScale_PS, 2) +GFSDK_WAVEWORKS_DECLARE_ATTR_PS_CONSTANT(float, nvsf_g_Cascade1UVOffset_PS, 3) +GFSDK_WAVEWORKS_DECLARE_ATTR_PS_CONSTANT(float, nvsf_g_Cascade2Scale_PS, 4) +GFSDK_WAVEWORKS_DECLARE_ATTR_PS_CONSTANT(float, nvsf_g_Cascade2TexelScale_PS, 5) +GFSDK_WAVEWORKS_DECLARE_ATTR_PS_CONSTANT(float, nvsf_g_Cascade2UVOffset_PS, 6) +GFSDK_WAVEWORKS_DECLARE_ATTR_PS_CONSTANT(float, nvsf_g_Cascade3Scale_PS, 7) +GFSDK_WAVEWORKS_DECLARE_ATTR_PS_CONSTANT(float, nvsf_g_Cascade3TexelScale_PS, 8) +GFSDK_WAVEWORKS_DECLARE_ATTR_PS_CONSTANT(float, nvsf_g_Cascade3UVOffset_PS, 9) +GFSDK_WAVEWORKS_END_ATTR_PS_CBUFFER + +GFSDK_WAVEWORKS_DECLARE_ATTR_PS_SAMPLER(nvsf_g_samplerGradientMap0, nvsf_g_textureGradientMap0, 0) +GFSDK_WAVEWORKS_DECLARE_ATTR_PS_SAMPLER(nvsf_g_samplerGradientMap1, nvsf_g_textureGradientMap1, 1) +GFSDK_WAVEWORKS_DECLARE_ATTR_PS_SAMPLER(nvsf_g_samplerGradientMap2, nvsf_g_textureGradientMap2, 2) +GFSDK_WAVEWORKS_DECLARE_ATTR_PS_SAMPLER(nvsf_g_samplerGradientMap3, nvsf_g_textureGradientMap3, 3) + +#if defined( GFSDK_WAVEWORKS_GL ) + GFSDK_WAVEWORKS_DECLARE_ATTR_PS_SAMPLER_TEXTUREARRAY(nvsf_g_samplerGradientMapTextureArray, nvsf_g_textureArrayGradientMap, 4) +#endif + +struct GFSDK_WAVEWORKS_INTERPOLATED_VERTEX_OUTPUT +{ + float4 nvsf_tex_coord_cascade01 SEMANTIC(TEXCOORD0); + float4 nvsf_tex_coord_cascade23 SEMANTIC(TEXCOORD1); + float4 nvsf_blend_factor_cascade0123 SEMANTIC(TEXCOORD2); + float3 nvsf_eye_vec SEMANTIC(TEXCOORD3); +}; + +struct GFSDK_WAVEWORKS_VERTEX_OUTPUT +{ + centroid GFSDK_WAVEWORKS_INTERPOLATED_VERTEX_OUTPUT interp; + float3 pos_world; + float3 pos_world_undisplaced; + float3 world_displacement; +}; + +GFSDK_WAVEWORKS_VERTEX_OUTPUT GFSDK_WaveWorks_GetDisplacedVertex(GFSDK_WAVEWORKS_VERTEX_INPUT In) +{ + // Get starting position and distance to camera + float3 nvsf_pos_world_undisplaced = GFSDK_WaveWorks_GetUndisplacedVertexWorldPosition(In); + float nvsf_distance = length(nvsf_g_WorldEye - nvsf_pos_world_undisplaced); + + // UVs + float2 nvsf_uv_world_cascade0 = nvsf_pos_world_undisplaced.xy * nvsf_g_UVScaleCascade0123.x; + float2 nvsf_uv_world_cascade1 = nvsf_pos_world_undisplaced.xy * nvsf_g_UVScaleCascade0123.y; + float2 nvsf_uv_world_cascade2 = nvsf_pos_world_undisplaced.xy * nvsf_g_UVScaleCascade0123.z; + float2 nvsf_uv_world_cascade3 = nvsf_pos_world_undisplaced.xy * nvsf_g_UVScaleCascade0123.w; + + // cascade blend factors + float4 nvsf_blendfactors; + float4 nvsf_cascade_spatial_size = 1.0/nvsf_g_UVScaleCascade0123.xyzw; + nvsf_blendfactors.x = 1.0; + nvsf_blendfactors.yzw = saturate(0.25*(nvsf_cascade_spatial_size.yzw*24.0-nvsf_distance)/nvsf_cascade_spatial_size.yzw); + nvsf_blendfactors.yzw *= nvsf_blendfactors.yzw; + + + // Displacement map + #if defined(GFSDK_WAVEWORKS_GL) + float3 nvsf_displacement; + if(nvsf_g_UseTextureArrays > 0) + { + nvsf_displacement = nvsf_blendfactors.x * SampleTex2Dlod(nvsf_g_textureArrayDisplacementMap, nvsf_g_samplerDisplacementMapTextureArray, vec3(nvsf_uv_world_cascade0, 0.0), 0).xyz; + nvsf_displacement += nvsf_blendfactors.y==0? float3(0,0,0) : nvsf_blendfactors.y * SampleTex2Dlod(nvsf_g_textureArrayDisplacementMap, nvsf_g_samplerDisplacementMapTextureArray, vec3(nvsf_uv_world_cascade1, 1.0), 0).xyz; + nvsf_displacement += nvsf_blendfactors.z==0? float3(0,0,0) : nvsf_blendfactors.z * SampleTex2Dlod(nvsf_g_textureArrayDisplacementMap, nvsf_g_samplerDisplacementMapTextureArray, vec3(nvsf_uv_world_cascade2, 2.0), 0).xyz; + nvsf_displacement += nvsf_blendfactors.w==0? float3(0,0,0) : nvsf_blendfactors.w * SampleTex2Dlod(nvsf_g_textureArrayDisplacementMap, nvsf_g_samplerDisplacementMapTextureArray, vec3(nvsf_uv_world_cascade3, 3.0), 0).xyz; + } + else + { + nvsf_displacement = nvsf_blendfactors.x * SampleTex2Dlod(nvsf_g_textureDisplacementMap0, nvsf_g_samplerDisplacementMap0, nvsf_uv_world_cascade0, 0).xyz; + nvsf_displacement += nvsf_blendfactors.y==0? float3(0,0,0) : nvsf_blendfactors.y * SampleTex2Dlod(nvsf_g_textureDisplacementMap1, nvsf_g_samplerDisplacementMap1, nvsf_uv_world_cascade1, 0).xyz; + nvsf_displacement += nvsf_blendfactors.z==0? float3(0,0,0) : nvsf_blendfactors.z * SampleTex2Dlod(nvsf_g_textureDisplacementMap2, nvsf_g_samplerDisplacementMap2, nvsf_uv_world_cascade2, 0).xyz; + nvsf_displacement += nvsf_blendfactors.w==0? float3(0,0,0) : nvsf_blendfactors.w * SampleTex2Dlod(nvsf_g_textureDisplacementMap3, nvsf_g_samplerDisplacementMap3, nvsf_uv_world_cascade3, 0).xyz; + } + #else + float3 nvsf_displacement = nvsf_blendfactors.x * SampleTex2Dlod(nvsf_g_textureDisplacementMap0, nvsf_g_samplerDisplacementMap0, nvsf_uv_world_cascade0, 0).xyz; + nvsf_displacement += nvsf_blendfactors.y==0? float3(0,0,0) : nvsf_blendfactors.y * SampleTex2Dlod(nvsf_g_textureDisplacementMap1, nvsf_g_samplerDisplacementMap1, nvsf_uv_world_cascade1, 0).xyz; + nvsf_displacement += nvsf_blendfactors.z==0? float3(0,0,0) : nvsf_blendfactors.z * SampleTex2Dlod(nvsf_g_textureDisplacementMap2, nvsf_g_samplerDisplacementMap2, nvsf_uv_world_cascade2, 0).xyz; + nvsf_displacement += nvsf_blendfactors.w==0? float3(0,0,0) : nvsf_blendfactors.w * SampleTex2Dlod(nvsf_g_textureDisplacementMap3, nvsf_g_samplerDisplacementMap3, nvsf_uv_world_cascade3, 0).xyz; + #endif + + float3 nvsf_pos_world = nvsf_pos_world_undisplaced + nvsf_displacement; + + // Output + GFSDK_WAVEWORKS_VERTEX_OUTPUT Output; + Output.interp.nvsf_eye_vec = nvsf_g_WorldEye - nvsf_pos_world; + Output.interp.nvsf_tex_coord_cascade01.xy = nvsf_uv_world_cascade0; + Output.interp.nvsf_tex_coord_cascade01.zw = nvsf_uv_world_cascade1; + Output.interp.nvsf_tex_coord_cascade23.xy = nvsf_uv_world_cascade2; + Output.interp.nvsf_tex_coord_cascade23.zw = nvsf_uv_world_cascade3; + Output.interp.nvsf_blend_factor_cascade0123 = nvsf_blendfactors; + Output.pos_world = nvsf_pos_world; + Output.pos_world_undisplaced = nvsf_pos_world_undisplaced; + Output.world_displacement = nvsf_displacement; + return Output; +} + +GFSDK_WAVEWORKS_VERTEX_OUTPUT GFSDK_WaveWorks_GetDisplacedVertexAfterTessellation(float4 In0, float4 In1, float4 In2, float3 BarycentricCoords) +{ + // Get starting position + float3 nvsf_tessellated_ws_position = In0.xyz * BarycentricCoords.x + + In1.xyz * BarycentricCoords.y + + In2.xyz * BarycentricCoords.z; + float3 nvsf_pos_world_undisplaced = nvsf_tessellated_ws_position; + + + // blend factors for cascades + float4 nvsf_blendfactors; + float nvsf_distance = length(nvsf_g_WorldEye - nvsf_pos_world_undisplaced); + float4 nvsf_cascade_spatial_size = 1.0/nvsf_g_UVScaleCascade0123.xyzw; + nvsf_blendfactors.x = 1.0; + nvsf_blendfactors.yzw = saturate(0.25*(nvsf_cascade_spatial_size.yzw*24.0-nvsf_distance)/nvsf_cascade_spatial_size.yzw); + nvsf_blendfactors.yzw *= nvsf_blendfactors.yzw; + + // UVs + float2 nvsf_uv_world_cascade0 = nvsf_pos_world_undisplaced.xy * nvsf_g_UVScaleCascade0123.x; + float2 nvsf_uv_world_cascade1 = nvsf_pos_world_undisplaced.xy * nvsf_g_UVScaleCascade0123.y; + float2 nvsf_uv_world_cascade2 = nvsf_pos_world_undisplaced.xy * nvsf_g_UVScaleCascade0123.z; + float2 nvsf_uv_world_cascade3 = nvsf_pos_world_undisplaced.xy * nvsf_g_UVScaleCascade0123.w; + + // Displacement map + #if defined(GFSDK_WAVEWORKS_GL) + float3 nvsf_displacement; + if(nvsf_g_UseTextureArrays > 0) + { + nvsf_displacement = nvsf_blendfactors.x * SampleTex2Dlod(nvsf_g_textureArrayDisplacementMap, nvsf_g_samplerDisplacementMapTextureArray, vec3(nvsf_uv_world_cascade0, 0.0), 0).xyz; + nvsf_displacement += nvsf_blendfactors.y==0? float3(0,0,0) : nvsf_blendfactors.y * SampleTex2Dlod(nvsf_g_textureArrayDisplacementMap, nvsf_g_samplerDisplacementMapTextureArray, vec3(nvsf_uv_world_cascade1, 1.0), 0).xyz; + nvsf_displacement += nvsf_blendfactors.z==0? float3(0,0,0) : nvsf_blendfactors.z * SampleTex2Dlod(nvsf_g_textureArrayDisplacementMap, nvsf_g_samplerDisplacementMapTextureArray, vec3(nvsf_uv_world_cascade2, 2.0), 0).xyz; + nvsf_displacement += nvsf_blendfactors.w==0? float3(0,0,0) : nvsf_blendfactors.w * SampleTex2Dlod(nvsf_g_textureArrayDisplacementMap, nvsf_g_samplerDisplacementMapTextureArray, vec3(nvsf_uv_world_cascade3, 3.0), 0).xyz; + } + else + { + nvsf_displacement = nvsf_blendfactors.x * SampleTex2Dlod(nvsf_g_textureDisplacementMap0, nvsf_g_samplerDisplacementMap0, nvsf_uv_world_cascade0, 0).xyz; + nvsf_displacement += nvsf_blendfactors.y==0? float3(0,0,0) : nvsf_blendfactors.y * SampleTex2Dlod(nvsf_g_textureDisplacementMap1, nvsf_g_samplerDisplacementMap1, nvsf_uv_world_cascade1, 0).xyz; + nvsf_displacement += nvsf_blendfactors.z==0? float3(0,0,0) : nvsf_blendfactors.z * SampleTex2Dlod(nvsf_g_textureDisplacementMap2, nvsf_g_samplerDisplacementMap2, nvsf_uv_world_cascade2, 0).xyz; + nvsf_displacement += nvsf_blendfactors.w==0? float3(0,0,0) : nvsf_blendfactors.w * SampleTex2Dlod(nvsf_g_textureDisplacementMap3, nvsf_g_samplerDisplacementMap3, nvsf_uv_world_cascade3, 0).xyz; + } + #else + float3 nvsf_displacement = nvsf_blendfactors.x * SampleTex2Dlod(nvsf_g_textureDisplacementMap0, nvsf_g_samplerDisplacementMap0, nvsf_uv_world_cascade0, 0).xyz; + nvsf_displacement += nvsf_blendfactors.y==0? float3(0,0,0) : nvsf_blendfactors.y * SampleTex2Dlod(nvsf_g_textureDisplacementMap1, nvsf_g_samplerDisplacementMap1, nvsf_uv_world_cascade1, 0).xyz; + nvsf_displacement += nvsf_blendfactors.z==0? float3(0,0,0) : nvsf_blendfactors.z * SampleTex2Dlod(nvsf_g_textureDisplacementMap2, nvsf_g_samplerDisplacementMap2, nvsf_uv_world_cascade2, 0).xyz; + nvsf_displacement += nvsf_blendfactors.w==0? float3(0,0,0) : nvsf_blendfactors.w * SampleTex2Dlod(nvsf_g_textureDisplacementMap3, nvsf_g_samplerDisplacementMap3, nvsf_uv_world_cascade3, 0).xyz; + #endif + + float3 nvsf_pos_world = nvsf_pos_world_undisplaced + nvsf_displacement; + + // Output + GFSDK_WAVEWORKS_VERTEX_OUTPUT Output; + Output.interp.nvsf_eye_vec = nvsf_g_WorldEye - nvsf_pos_world; + Output.interp.nvsf_tex_coord_cascade01.xy = nvsf_uv_world_cascade0; + Output.interp.nvsf_tex_coord_cascade01.zw = nvsf_uv_world_cascade1; + Output.interp.nvsf_tex_coord_cascade23.xy = nvsf_uv_world_cascade2; + Output.interp.nvsf_tex_coord_cascade23.zw = nvsf_uv_world_cascade3; + Output.interp.nvsf_blend_factor_cascade0123 = nvsf_blendfactors; + Output.pos_world = nvsf_pos_world; + Output.pos_world_undisplaced = nvsf_pos_world_undisplaced; + Output.world_displacement = nvsf_displacement; + return Output; +} + +GFSDK_WAVEWORKS_VERTEX_OUTPUT GFSDK_WaveWorks_GetDisplacedVertexAfterTessellationQuad(float4 In0, float4 In1, float4 In2, float4 In3, float2 UV) +{ + // Get starting position + float3 nvsf_tessellated_ws_position = In2.xyz*UV.x*UV.y + + In0.xyz*(1.0-UV.x)*UV.y + + In1.xyz*(1.0-UV.x)*(1.0-UV.y) + + In3.xyz*UV.x*(1.0-UV.y); + float3 nvsf_pos_world_undisplaced = nvsf_tessellated_ws_position; + + // blend factors for cascades + float4 nvsf_blendfactors; + float nvsf_distance = length(nvsf_g_WorldEye - nvsf_pos_world_undisplaced); + float4 nvsf_cascade_spatial_size = 1.0/nvsf_g_UVScaleCascade0123.xyzw; + nvsf_blendfactors.x = 1.0; + nvsf_blendfactors.yzw = saturate(0.25*(nvsf_cascade_spatial_size.yzw*24.0-nvsf_distance)/nvsf_cascade_spatial_size.yzw); + nvsf_blendfactors.yzw *= nvsf_blendfactors.yzw; + + // UVs + float2 nvsf_uv_world_cascade0 = nvsf_pos_world_undisplaced.xy * nvsf_g_UVScaleCascade0123.x; + float2 nvsf_uv_world_cascade1 = nvsf_pos_world_undisplaced.xy * nvsf_g_UVScaleCascade0123.y; + float2 nvsf_uv_world_cascade2 = nvsf_pos_world_undisplaced.xy * nvsf_g_UVScaleCascade0123.z; + float2 nvsf_uv_world_cascade3 = nvsf_pos_world_undisplaced.xy * nvsf_g_UVScaleCascade0123.w; + + // Displacement map + #if defined(GFSDK_WAVEWORKS_GL) + float3 nvsf_displacement; + if(nvsf_g_UseTextureArrays > 0) + { + nvsf_displacement = nvsf_blendfactors.x * SampleTex2Dlod(nvsf_g_textureArrayDisplacementMap, nvsf_g_samplerDisplacementMapTextureArray, vec3(nvsf_uv_world_cascade0, 0.0), 0).xyz; + nvsf_displacement += nvsf_blendfactors.y==0? float3(0,0,0) : nvsf_blendfactors.y * SampleTex2Dlod(nvsf_g_textureArrayDisplacementMap, nvsf_g_samplerDisplacementMapTextureArray, vec3(nvsf_uv_world_cascade1, 1.0), 0).xyz; + nvsf_displacement += nvsf_blendfactors.z==0? float3(0,0,0) : nvsf_blendfactors.z * SampleTex2Dlod(nvsf_g_textureArrayDisplacementMap, nvsf_g_samplerDisplacementMapTextureArray, vec3(nvsf_uv_world_cascade2, 2.0), 0).xyz; + nvsf_displacement += nvsf_blendfactors.w==0? float3(0,0,0) : nvsf_blendfactors.w * SampleTex2Dlod(nvsf_g_textureArrayDisplacementMap, nvsf_g_samplerDisplacementMapTextureArray, vec3(nvsf_uv_world_cascade3, 3.0), 0).xyz; + } + else + { + nvsf_displacement = nvsf_blendfactors.x * SampleTex2Dlod(nvsf_g_textureDisplacementMap0, nvsf_g_samplerDisplacementMap0, nvsf_uv_world_cascade0, 0).xyz; + nvsf_displacement += nvsf_blendfactors.y==0? float3(0,0,0) : nvsf_blendfactors.y * SampleTex2Dlod(nvsf_g_textureDisplacementMap1, nvsf_g_samplerDisplacementMap1, nvsf_uv_world_cascade1, 0).xyz; + nvsf_displacement += nvsf_blendfactors.z==0? float3(0,0,0) : nvsf_blendfactors.z * SampleTex2Dlod(nvsf_g_textureDisplacementMap2, nvsf_g_samplerDisplacementMap2, nvsf_uv_world_cascade2, 0).xyz; + nvsf_displacement += nvsf_blendfactors.w==0? float3(0,0,0) : nvsf_blendfactors.w * SampleTex2Dlod(nvsf_g_textureDisplacementMap3, nvsf_g_samplerDisplacementMap3, nvsf_uv_world_cascade3, 0).xyz; + } + #else + float3 nvsf_displacement = nvsf_blendfactors.x * SampleTex2Dlod(nvsf_g_textureDisplacementMap0, nvsf_g_samplerDisplacementMap0, nvsf_uv_world_cascade0, 0).xyz; + nvsf_displacement += nvsf_blendfactors.y==0? float3(0,0,0) : nvsf_blendfactors.y * SampleTex2Dlod(nvsf_g_textureDisplacementMap1, nvsf_g_samplerDisplacementMap1, nvsf_uv_world_cascade1, 0).xyz; + nvsf_displacement += nvsf_blendfactors.z==0? float3(0,0,0) : nvsf_blendfactors.z * SampleTex2Dlod(nvsf_g_textureDisplacementMap2, nvsf_g_samplerDisplacementMap2, nvsf_uv_world_cascade2, 0).xyz; + nvsf_displacement += nvsf_blendfactors.w==0? float3(0,0,0) : nvsf_blendfactors.w * SampleTex2Dlod(nvsf_g_textureDisplacementMap3, nvsf_g_samplerDisplacementMap3, nvsf_uv_world_cascade3, 0).xyz; + #endif + + float3 nvsf_pos_world = nvsf_pos_world_undisplaced + nvsf_displacement; + + // Output + GFSDK_WAVEWORKS_VERTEX_OUTPUT Output; + Output.interp.nvsf_eye_vec = nvsf_g_WorldEye - nvsf_pos_world; + Output.interp.nvsf_tex_coord_cascade01.xy = nvsf_uv_world_cascade0; + Output.interp.nvsf_tex_coord_cascade01.zw = nvsf_uv_world_cascade1; + Output.interp.nvsf_tex_coord_cascade23.xy = nvsf_uv_world_cascade2; + Output.interp.nvsf_tex_coord_cascade23.zw = nvsf_uv_world_cascade3; + Output.interp.nvsf_blend_factor_cascade0123 = nvsf_blendfactors; + Output.pos_world = nvsf_pos_world; + Output.pos_world_undisplaced = nvsf_pos_world_undisplaced; + Output.world_displacement = nvsf_displacement; + return Output; +} + +struct GFSDK_WAVEWORKS_SURFACE_ATTRIBUTES +{ + float3 normal; + float3 eye_dir; + float foam_surface_folding; + float foam_turbulent_energy; + float foam_wave_hats; +}; + +GFSDK_WAVEWORKS_SURFACE_ATTRIBUTES GFSDK_WaveWorks_GetSurfaceAttributes(GFSDK_WAVEWORKS_INTERPOLATED_VERTEX_OUTPUT In) +{ + // Calculate eye vector. + // Beware: 'nvsf_eye_vec' is a large number, 32bit floating point required. + float3 nvsf_eye_dir = normalize(In.nvsf_eye_vec); + + // --------------- Water body color + + float4 nvsf_grad_fold0; + float4 nvsf_grad_fold1; + float4 nvsf_grad_fold2; + float4 nvsf_grad_fold3; + + #if defined(GFSDK_WAVEWORKS_GL) + float3 nvsf_displacement; + if(nvsf_g_UseTextureArrays > 0) + { + nvsf_grad_fold0 = SampleTex2D(nvsf_g_textureArrayGradientMap, nvsf_g_samplerGradientMapTextureArray, vec3(In.nvsf_tex_coord_cascade01.xy, 0.0)); + nvsf_grad_fold1 = SampleTex2D(nvsf_g_textureArrayGradientMap, nvsf_g_samplerGradientMapTextureArray, vec3(In.nvsf_tex_coord_cascade01.zw, 1.0)); + nvsf_grad_fold2 = SampleTex2D(nvsf_g_textureArrayGradientMap, nvsf_g_samplerGradientMapTextureArray, vec3(In.nvsf_tex_coord_cascade23.xy, 2.0)); + nvsf_grad_fold3 = SampleTex2D(nvsf_g_textureArrayGradientMap, nvsf_g_samplerGradientMapTextureArray, vec3(In.nvsf_tex_coord_cascade23.zw, 3.0)); + } + else + { + nvsf_grad_fold0 = SampleTex2D(nvsf_g_textureGradientMap0, nvsf_g_samplerGradientMap0, In.nvsf_tex_coord_cascade01.xy); + nvsf_grad_fold1 = SampleTex2D(nvsf_g_textureGradientMap1, nvsf_g_samplerGradientMap1, In.nvsf_tex_coord_cascade01.zw); + nvsf_grad_fold2 = SampleTex2D(nvsf_g_textureGradientMap2, nvsf_g_samplerGradientMap2, In.nvsf_tex_coord_cascade23.xy); + nvsf_grad_fold3 = SampleTex2D(nvsf_g_textureGradientMap3, nvsf_g_samplerGradientMap3, In.nvsf_tex_coord_cascade23.zw); + } + #else + + nvsf_grad_fold0 = SampleTex2D(nvsf_g_textureGradientMap0, nvsf_g_samplerGradientMap0, In.nvsf_tex_coord_cascade01.xy); + nvsf_grad_fold1 = SampleTex2D(nvsf_g_textureGradientMap1, nvsf_g_samplerGradientMap1, In.nvsf_tex_coord_cascade01.zw); + nvsf_grad_fold2 = SampleTex2D(nvsf_g_textureGradientMap2, nvsf_g_samplerGradientMap2, In.nvsf_tex_coord_cascade23.xy); + nvsf_grad_fold3 = SampleTex2D(nvsf_g_textureGradientMap3, nvsf_g_samplerGradientMap3, In.nvsf_tex_coord_cascade23.zw); + #endif + + float2 nvsf_grad; + nvsf_grad.xy = nvsf_grad_fold0.xy*In.nvsf_blend_factor_cascade0123.x + + nvsf_grad_fold1.xy*In.nvsf_blend_factor_cascade0123.y*nvsf_g_Cascade1TexelScale_PS + + nvsf_grad_fold2.xy*In.nvsf_blend_factor_cascade0123.z*nvsf_g_Cascade2TexelScale_PS + + nvsf_grad_fold3.xy*In.nvsf_blend_factor_cascade0123.w*nvsf_g_Cascade3TexelScale_PS; + + float nvsf_c2c_scale = 0.25; // larger cascaded cover larger areas, so foamed texels cover larger area, thus, foam intensity on these needs to be scaled down for uniform foam look + + float nvsf_foam_turbulent_energy = + // accumulated foam energy with blendfactors + 100.0*nvsf_grad_fold0.w * + lerp(nvsf_c2c_scale, nvsf_grad_fold1.w, In.nvsf_blend_factor_cascade0123.y)* + lerp(nvsf_c2c_scale, nvsf_grad_fold2.w, In.nvsf_blend_factor_cascade0123.z)* + lerp(nvsf_c2c_scale, nvsf_grad_fold3.w, In.nvsf_blend_factor_cascade0123.w); + + + float nvsf_foam_surface_folding = + // folding for foam "clumping" on folded areas + max(-100, + (1.0-nvsf_grad_fold0.z) + + (1.0-nvsf_grad_fold1.z) + + (1.0-nvsf_grad_fold2.z) + + (1.0-nvsf_grad_fold3.z)); + + // Calculate normal here. + float3 nvsf_normal = normalize(float3(nvsf_grad, nvsf_g_TexelLength_x2_PS)); + + float nvsf_hats_c2c_scale = 0.5; // the larger is the wave, the higher is the chance to start breaking at high folding, so folding for smaller cascade s is decreased + float nvsf_foam_wave_hats = + 10.0*(-0.55 + // this allows hats to appear on breaking places only. Can be tweaked to represent Beaufort scale better + (1.0-nvsf_grad_fold0.z) + + nvsf_hats_c2c_scale*(1.0-nvsf_grad_fold1.z) + + nvsf_hats_c2c_scale*nvsf_hats_c2c_scale*(1.0-nvsf_grad_fold2.z) + + nvsf_hats_c2c_scale*nvsf_hats_c2c_scale*nvsf_hats_c2c_scale*(1.0-nvsf_grad_fold3.z)); + + + // Output + GFSDK_WAVEWORKS_SURFACE_ATTRIBUTES Output; + Output.normal = nvsf_normal; + Output.eye_dir = nvsf_eye_dir; + Output.foam_surface_folding = nvsf_foam_surface_folding; + Output.foam_turbulent_energy = log(1.0 + nvsf_foam_turbulent_energy); + Output.foam_wave_hats = nvsf_foam_wave_hats; + return Output; +} + + +#endif /* _GFSDK_WAVEWORKS_ATTRIBUTES_FX */ diff --git a/src/shader/CalcGradient.fx b/src/shader/CalcGradient.fx new file mode 100644 index 0000000..e66e75f --- /dev/null +++ b/src/shader/CalcGradient.fx @@ -0,0 +1,117 @@ +// This code contains NVIDIA Confidential Information and is disclosed +// under the Mutual Non-Disclosure Agreement. +// +// Notice +// ALL NVIDIA DESIGN SPECIFICATIONS AND CODE ("MATERIALS") ARE PROVIDED "AS IS" NVIDIA MAKES +// NO REPRESENTATIONS, WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO +// THE MATERIALS, AND EXPRESSLY DISCLAIMS ANY IMPLIED WARRANTIES OF NONINFRINGEMENT, +// MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. +// +// NVIDIA Corporation assumes no responsibility for the consequences of use of such +// information or for any infringement of patents or other rights of third parties that may +// result from its use. No license is granted by implication or otherwise under any patent +// or patent rights of NVIDIA Corporation. No third party distribution is allowed unless +// expressly authorized by NVIDIA. Details are subject to change without notice. +// This code supersedes and replaces all information previously supplied. +// NVIDIA Corporation products are not authorized for use as critical +// components in life support devices or systems without express written approval of +// NVIDIA Corporation. +// +// Copyright � 2008- 2013 NVIDIA Corporation. All rights reserved. +// +// NVIDIA Corporation and its licensors retain all intellectual property and proprietary +// rights in and to this software and related documentation and any modifications thereto. +// Any use, reproduction, disclosure or distribution of this software and related +// documentation without an express license agreement from NVIDIA Corporation is +// strictly prohibited. +// + +#include "Common.fxh" + +#ifdef GFSDK_WAVEWORKS_GL +#define DECLARE_ATTR_CONSTANT(Type,Label,Regoff) uniform Type Label +#define DECLARE_ATTR_SAMPLER(Label,TextureLabel,Regoff) \ + uniform sampler2D TextureLabel +#else +#define DECLARE_ATTR_CONSTANT(Type,Label,Regoff) Type Label : register(c##Regoff) +#define DECLARE_ATTR_SAMPLER(Label,TextureLabel,Regoff) \ + Texture2D Label : register(t##Regoff); \ + SamplerState TextureLabel : register(s##Regoff) +#endif + +//------------------------------------------------------------------------------------ +// 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); +END_CBUFFER + +DECLARE_ATTR_SAMPLER(nvsf_g_textureDisplacementMap,nvsf_g_samplerDisplacementMap,0); + +#ifdef GFSDK_WAVEWORKS_GL +varying float2 nvsf_vInterpTexCoord; +#endif + +#ifndef GFSDK_WAVEWORKS_OMIT_VS + +#ifdef GFSDK_WAVEWORKS_GL +attribute float4 nvsf_vInPos; +attribute float2 nvsf_vInTexCoord; +#define nvsf_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) +) +#endif +{ + // No need to do matrix transform. + nvsf_vOutPos = nvsf_vInPos; + + // Pass through general texture coordinate. + nvsf_vInterpTexCoord = nvsf_vInTexCoord; +} + +#endif // !GFSDK_WAVEWORKS_OMIT_VS + + +#ifndef GFSDK_WAVEWORKS_OMIT_PS + +#ifdef GFSDK_WAVEWORKS_GL +#define nvsf_Output gl_FragColor +void main() +#else +void ps( + float2 nvsf_vInterpTexCoord SEMANTIC(TEXCOORD0), + out float4 nvsf_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; + + // -------- 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) }; + + // 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; + + // Output + nvsf_Output = float4(nvsf_gradient, nvsf_J, 0); +} + +#endif // !GFSDK_WAVEWORKS_OMIT_PS diff --git a/src/shader/CalcGradient_SM3.fx b/src/shader/CalcGradient_SM3.fx new file mode 100644 index 0000000..3c09164 --- /dev/null +++ b/src/shader/CalcGradient_SM3.fx @@ -0,0 +1,30 @@ +// This code contains NVIDIA Confidential Information and is disclosed +// under the Mutual Non-Disclosure Agreement. +// +// Notice +// ALL NVIDIA DESIGN SPECIFICATIONS AND CODE ("MATERIALS") ARE PROVIDED "AS IS" NVIDIA MAKES +// NO REPRESENTATIONS, WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO +// THE MATERIALS, AND EXPRESSLY DISCLAIMS ANY IMPLIED WARRANTIES OF NONINFRINGEMENT, +// MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. +// +// NVIDIA Corporation assumes no responsibility for the consequences of use of such +// information or for any infringement of patents or other rights of third parties that may +// result from its use. No license is granted by implication or otherwise under any patent +// or patent rights of NVIDIA Corporation. No third party distribution is allowed unless +// expressly authorized by NVIDIA. Details are subject to change without notice. +// This code supersedes and replaces all information previously supplied. +// NVIDIA Corporation products are not authorized for use as critical +// components in life support devices or systems without express written approval of +// NVIDIA Corporation. +// +// Copyright � 2008- 2013 NVIDIA Corporation. All rights reserved. +// +// NVIDIA Corporation and its licensors retain all intellectual property and proprietary +// rights in and to this software and related documentation and any modifications thereto. +// Any use, reproduction, disclosure or distribution of this software and related +// documentation without an express license agreement from NVIDIA Corporation is +// strictly prohibited. +// + +#define GFSDK_WAVEWORKS_SM3 +#include "CalcGradient_nvsf.fx" diff --git a/src/shader/CalcGradient_SM4.fx b/src/shader/CalcGradient_SM4.fx new file mode 100644 index 0000000..7a6e93f --- /dev/null +++ b/src/shader/CalcGradient_SM4.fx @@ -0,0 +1,30 @@ +// This code contains NVIDIA Confidential Information and is disclosed +// under the Mutual Non-Disclosure Agreement. +// +// Notice +// ALL NVIDIA DESIGN SPECIFICATIONS AND CODE ("MATERIALS") ARE PROVIDED "AS IS" NVIDIA MAKES +// NO REPRESENTATIONS, WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO +// THE MATERIALS, AND EXPRESSLY DISCLAIMS ANY IMPLIED WARRANTIES OF NONINFRINGEMENT, +// MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. +// +// NVIDIA Corporation assumes no responsibility for the consequences of use of such +// information or for any infringement of patents or other rights of third parties that may +// result from its use. No license is granted by implication or otherwise under any patent +// or patent rights of NVIDIA Corporation. No third party distribution is allowed unless +// expressly authorized by NVIDIA. Details are subject to change without notice. +// This code supersedes and replaces all information previously supplied. +// NVIDIA Corporation products are not authorized for use as critical +// components in life support devices or systems without express written approval of +// NVIDIA Corporation. +// +// Copyright � 2008- 2013 NVIDIA Corporation. All rights reserved. +// +// NVIDIA Corporation and its licensors retain all intellectual property and proprietary +// rights in and to this software and related documentation and any modifications thereto. +// Any use, reproduction, disclosure or distribution of this software and related +// documentation without an express license agreement from NVIDIA Corporation is +// strictly prohibited. +// + +#define GFSDK_WAVEWORKS_SM4 +#include "CalcGradient_nvsf.fx" diff --git a/src/shader/CalcGradient_glsl.ps b/src/shader/CalcGradient_glsl.ps new file mode 100644 index 0000000..51064db --- /dev/null +++ b/src/shader/CalcGradient_glsl.ps @@ -0,0 +1,31 @@ +// This code contains NVIDIA Confidential Information and is disclosed +// under the Mutual Non-Disclosure Agreement. +// +// Notice +// ALL NVIDIA DESIGN SPECIFICATIONS AND CODE ("MATERIALS") ARE PROVIDED "AS IS" NVIDIA MAKES +// NO REPRESENTATIONS, WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO +// THE MATERIALS, AND EXPRESSLY DISCLAIMS ANY IMPLIED WARRANTIES OF NONINFRINGEMENT, +// MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. +// +// NVIDIA Corporation assumes no responsibility for the consequences of use of such +// information or for any infringement of patents or other rights of third parties that may +// result from its use. No license is granted by implication or otherwise under any patent +// or patent rights of NVIDIA Corporation. No third party distribution is allowed unless +// expressly authorized by NVIDIA. Details are subject to change without notice. +// This code supersedes and replaces all information previously supplied. +// NVIDIA Corporation products are not authorized for use as critical +// components in life support devices or systems without express written approval of +// NVIDIA Corporation. +// +// Copyright � 2008- 2013 NVIDIA Corporation. All rights reserved. +// +// NVIDIA Corporation and its licensors retain all intellectual property and proprietary +// rights in and to this software and related documentation and any modifications thereto. +// Any use, reproduction, disclosure or distribution of this software and related +// documentation without an express license agreement from NVIDIA Corporation is +// strictly prohibited. +// + +#define GFSDK_WAVEWORKS_GL +#define GFSDK_WAVEWORKS_OMIT_VS +#include "CalcGradient_nvsf.fx" diff --git a/src/shader/CalcGradient_glsl.vs b/src/shader/CalcGradient_glsl.vs new file mode 100644 index 0000000..497d1f0 --- /dev/null +++ b/src/shader/CalcGradient_glsl.vs @@ -0,0 +1,31 @@ +// This code contains NVIDIA Confidential Information and is disclosed +// under the Mutual Non-Disclosure Agreement. +// +// Notice +// ALL NVIDIA DESIGN SPECIFICATIONS AND CODE ("MATERIALS") ARE PROVIDED "AS IS" NVIDIA MAKES +// NO REPRESENTATIONS, WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO +// THE MATERIALS, AND EXPRESSLY DISCLAIMS ANY IMPLIED WARRANTIES OF NONINFRINGEMENT, +// MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. +// +// NVIDIA Corporation assumes no responsibility for the consequences of use of such +// information or for any infringement of patents or other rights of third parties that may +// result from its use. No license is granted by implication or otherwise under any patent +// or patent rights of NVIDIA Corporation. No third party distribution is allowed unless +// expressly authorized by NVIDIA. Details are subject to change without notice. +// This code supersedes and replaces all information previously supplied. +// NVIDIA Corporation products are not authorized for use as critical +// components in life support devices or systems without express written approval of +// NVIDIA Corporation. +// +// Copyright � 2008- 2013 NVIDIA Corporation. All rights reserved. +// +// NVIDIA Corporation and its licensors retain all intellectual property and proprietary +// rights in and to this software and related documentation and any modifications thereto. +// Any use, reproduction, disclosure or distribution of this software and related +// documentation without an express license agreement from NVIDIA Corporation is +// strictly prohibited. +// + +#define GFSDK_WAVEWORKS_GL +#define GFSDK_WAVEWORKS_OMIT_PS +#include "CalcGradient_nvsf.fx" diff --git a/src/shader/CalcGradient_gnm.fx b/src/shader/CalcGradient_gnm.fx new file mode 100644 index 0000000..9a88f79 --- /dev/null +++ b/src/shader/CalcGradient_gnm.fx @@ -0,0 +1,30 @@ +// This code contains NVIDIA Confidential Information and is disclosed +// under the Mutual Non-Disclosure Agreement. +// +// Notice +// ALL NVIDIA DESIGN SPECIFICATIONS AND CODE ("MATERIALS") ARE PROVIDED "AS IS" NVIDIA MAKES +// NO REPRESENTATIONS, WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO +// THE MATERIALS, AND EXPRESSLY DISCLAIMS ANY IMPLIED WARRANTIES OF NONINFRINGEMENT, +// MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. +// +// NVIDIA Corporation assumes no responsibility for the consequences of use of such +// information or for any infringement of patents or other rights of third parties that may +// result from its use. No license is granted by implication or otherwise under any patent +// or patent rights of NVIDIA Corporation. No third party distribution is allowed unless +// expressly authorized by NVIDIA. Details are subject to change without notice. +// This code supersedes and replaces all information previously supplied. +// NVIDIA Corporation products are not authorized for use as critical +// components in life support devices or systems without express written approval of +// NVIDIA Corporation. +// +// Copyright � 2008- 2013 NVIDIA Corporation. All rights reserved. +// +// NVIDIA Corporation and its licensors retain all intellectual property and proprietary +// rights in and to this software and related documentation and any modifications thereto. +// Any use, reproduction, disclosure or distribution of this software and related +// documentation without an express license agreement from NVIDIA Corporation is +// strictly prohibited. +// + +#define GFSDK_WAVEWORKS_GNM +#include "CalcGradient_nvsf.fx" diff --git a/src/shader/Common.fxh b/src/shader/Common.fxh new file mode 100644 index 0000000..c100c8b --- /dev/null +++ b/src/shader/Common.fxh @@ -0,0 +1,79 @@ +/* + * This code contains NVIDIA Confidential Information and is disclosed + * under the Mutual Non-Disclosure Agreement. + * + * Notice + * ALL NVIDIA DESIGN SPECIFICATIONS AND CODE ("MATERIALS") ARE PROVIDED "AS IS" NVIDIA MAKES + * NO REPRESENTATIONS, WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO + * THE MATERIALS, AND EXPRESSLY DISCLAIMS ANY IMPLIED WARRANTIES OF NONINFRINGEMENT, + * MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. + * + * NVIDIA Corporation assumes no responsibility for the consequences of use of such + * information or for any infringement of patents or other rights of third parties that may + * result from its use. No license is granted by implication or otherwise under any patent + * or patent rights of NVIDIA Corporation. No third party distribution is allowed unless + * expressly authorized by NVIDIA. Details are subject to change without notice. + * This code supersedes and replaces all information previously supplied. + * NVIDIA Corporation products are not authorized for use as critical + * components in life support devices or systems without express written approval of + * NVIDIA Corporation. + * + * Copyright � 2008- 2013 NVIDIA Corporation. All rights reserved. + * + * NVIDIA Corporation and its licensors retain all intellectual property and proprietary + * rights in and to this software and related documentation and any modifications thereto. + * Any use, reproduction, disclosure or distribution of this software and related + * documentation without an express license agreement from NVIDIA Corporation is + * strictly prohibited. + */ + +#ifndef _GFSDK_WAVEWORKS_COMMON_FX +#define _GFSDK_WAVEWORKS_COMMON_FX +/* + * + * + */ +#if defined(GFSDK_WAVEWORKS_SM4) || defined(GFSDK_WAVEWORKS_SM5) + #define SampleTex2D(nvsf_texture,nvsf_sampler,nvsf_coords) nvsf_texture.Sample(nvsf_sampler,nvsf_coords) + #define SampleTex2Dlod(nvsf_texture,nvsf_sampler,nvsf_coords,nvsf_lod) nvsf_texture.SampleLevel(nvsf_sampler,nvsf_coords,nvsf_lod) + #define BEGIN_CBUFFER(name,slot) cbuffer name : register(b##slot) { + #define END_CBUFFER }; + #define SEMANTIC(x) : x +#elif defined(GFSDK_WAVEWORKS_SM3) + #define SampleTex2D(nvsf_texture,nvsf_sampler,nvsf_coords) tex2D(nvsf_sampler,nvsf_coords) + #define SampleTex2Dlod(nvsf_texture,nvsf_sampler,nvsf_coords,nvsf_lod) tex2Dlod(nvsf_sampler,float4(nvsf_coords,0,nvsf_lod)) + #define BEGIN_CBUFFER(name,slot) + #define END_CBUFFER + #define SV_Target COLOR + #define SV_Position POSITION + #define SEMANTIC(x) : x +#elif defined(GFSDK_WAVEWORKS_GNM) + #define SampleTex2D(nvsf_texture,nvsf_sampler,nvsf_coords) nvsf_texture.Sample(nvsf_sampler,nvsf_coords) + #define SampleTex2Dlod(nvsf_texture,nvsf_sampler,nvsf_coords,nvsf_lod) nvsf_texture.SampleLOD(nvsf_sampler,nvsf_coords,nvsf_lod) + #define BEGIN_CBUFFER(name,slot) ConstantBuffer name : register(b##slot) { + #define END_CBUFFER }; + #define SV_Target S_TARGET_OUTPUT + #define SV_Position S_POSITION + #define SEMANTIC(x) : x +#elif defined(GFSDK_WAVEWORKS_GL) + #define SampleTex2D(nvsf_texture,nvsf_sampler,nvsf_coords) texture(nvsf_sampler,nvsf_coords) + #define SampleTex2Dlod(nvsf_texture,nvsf_sampler,nvsf_coords,nvsf_lod) textureLod(nvsf_sampler,nvsf_coords,nvsf_lod) + #define BEGIN_CBUFFER(name,slot) + #define END_CBUFFER + #define SEMANTIC(x) + #define float2 vec2 + #define float3 vec3 + #define float4 vec4 + #define float4x3 mat3x4 + //vec3 mul(vec4 v, mat3x4 m) { return v * m; } + #define mul(v,m) ((v)*(m)) + #define lerp mix + #define saturate(x) clamp(x,0.0,1.0) +#else + #error Shader model not defined (expected GFSDK_WAVEWORKS_SM3, GFSDK_WAVEWORKS_SM4, GFSDK_WAVEWORKS_SM5, GFSDK_WAVEWORKS_GNM or GFSDK_WAVEWORKS_GL) +#endif +/* + * + * + */ +#endif /* _GFSDK_WAVEWORKS_COMMON_FX */ diff --git a/src/shader/FoamGeneration.fx b/src/shader/FoamGeneration.fx new file mode 100644 index 0000000..496916f --- /dev/null +++ b/src/shader/FoamGeneration.fx @@ -0,0 +1,121 @@ +// This code contains NVIDIA Confidential Information and is disclosed +// under the Mutual Non-Disclosure Agreement. +// +// Notice +// ALL NVIDIA DESIGN SPECIFICATIONS AND CODE ("MATERIALS") ARE PROVIDED "AS IS" NVIDIA MAKES +// NO REPRESENTATIONS, WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO +// THE MATERIALS, AND EXPRESSLY DISCLAIMS ANY IMPLIED WARRANTIES OF NONINFRINGEMENT, +// MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. +// +// NVIDIA Corporation assumes no responsibility for the consequences of use of such +// information or for any infringement of patents or other rights of third parties that may +// result from its use. No license is granted by implication or otherwise under any patent +// or patent rights of NVIDIA Corporation. No third party distribution is allowed unless +// expressly authorized by NVIDIA. Details are subject to change without notice. +// This code supersedes and replaces all information previously supplied. +// NVIDIA Corporation products are not authorized for use as critical +// components in life support devices or systems without express written approval of +// NVIDIA Corporation. +// +// Copyright � 2008- 2013 NVIDIA Corporation. All rights reserved. +// +// NVIDIA Corporation and its licensors retain all intellectual property and proprietary +// rights in and to this software and related documentation and any modifications thereto. +// Any use, reproduction, disclosure or distribution of this software and related +// documentation without an express license agreement from NVIDIA Corporation is +// strictly prohibited. +// + +#include "Common.fxh" + +#ifdef GFSDK_WAVEWORKS_GL +#define DECLARE_ATTR_CONSTANT(Type,Label,Regoff) uniform Type Label +#define DECLARE_ATTR_SAMPLER(Label,TextureLabel,Regoff) \ + uniform sampler2D TextureLabel +#else +#define DECLARE_ATTR_CONSTANT(Type,Label,Regoff) Type Label : register(c##Regoff) +#define DECLARE_ATTR_SAMPLER(Label,TextureLabel,Regoff) \ + Texture2D Label : register(t##Regoff); \ + SamplerState TextureLabel : register(s##Regoff) +#endif + +//------------------------------------------------------------------------------------ +// 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 +END_CBUFFER + +DECLARE_ATTR_SAMPLER(nvsf_g_textureEnergyMap,nvsf_g_samplerEnergyMap,0); + +#ifdef GFSDK_WAVEWORKS_GL +varying float2 nvsf_vInterpTexCoord; +#endif + +#ifndef GFSDK_WAVEWORKS_OMIT_VS + +#ifdef GFSDK_WAVEWORKS_GL +attribute float4 nvsf_vInPos; +attribute float2 nvsf_vInTexCoord; +#define nvsf_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) +) +#endif +{ + // No need to do matrix transform. + nvsf_vOutPos = nvsf_vInPos; + + // Pass through general texture coordinate. + nvsf_vInterpTexCoord = nvsf_vInTexCoord; +} + +#endif // !GFSDK_WAVEWORKS_OMIT_VS + +// 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 + +#ifndef GFSDK_WAVEWORKS_OMIT_PS + +#ifdef GFSDK_WAVEWORKS_GL +#define nvsf_Output gl_FragColor +void main() +#else +void ps( + float2 nvsf_vInterpTexCoord SEMANTIC(TEXCOORD0), + out float4 nvsf_Output SEMANTIC(SV_Target) +) +#endif +{ + + float2 nvsf_UVoffset = nvsf_g_UVOffsets.xy*nvsf_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 nvsf_folding = max(0,SampleTex2D(nvsf_g_textureEnergyMap, nvsf_g_samplerEnergyMap, nvsf_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); + + nvsf_energy = min(1.0,nvsf_energy); + + // Output + nvsf_Output = float4(nvsf_energy,nvsf_energy,nvsf_energy,nvsf_energy); +} + +#endif // !GFSDK_WAVEWORKS_OMIT_PS
\ No newline at end of file diff --git a/src/shader/FoamGeneration_SM3.fx b/src/shader/FoamGeneration_SM3.fx new file mode 100644 index 0000000..f160637 --- /dev/null +++ b/src/shader/FoamGeneration_SM3.fx @@ -0,0 +1,30 @@ +// This code contains NVIDIA Confidential Information and is disclosed +// under the Mutual Non-Disclosure Agreement. +// +// Notice +// ALL NVIDIA DESIGN SPECIFICATIONS AND CODE ("MATERIALS") ARE PROVIDED "AS IS" NVIDIA MAKES +// NO REPRESENTATIONS, WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO +// THE MATERIALS, AND EXPRESSLY DISCLAIMS ANY IMPLIED WARRANTIES OF NONINFRINGEMENT, +// MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. +// +// NVIDIA Corporation assumes no responsibility for the consequences of use of such +// information or for any infringement of patents or other rights of third parties that may +// result from its use. No license is granted by implication or otherwise under any patent +// or patent rights of NVIDIA Corporation. No third party distribution is allowed unless +// expressly authorized by NVIDIA. Details are subject to change without notice. +// This code supersedes and replaces all information previously supplied. +// NVIDIA Corporation products are not authorized for use as critical +// components in life support devices or systems without express written approval of +// NVIDIA Corporation. +// +// Copyright � 2008- 2013 NVIDIA Corporation. All rights reserved. +// +// NVIDIA Corporation and its licensors retain all intellectual property and proprietary +// rights in and to this software and related documentation and any modifications thereto. +// Any use, reproduction, disclosure or distribution of this software and related +// documentation without an express license agreement from NVIDIA Corporation is +// strictly prohibited. +// + +#define GFSDK_WAVEWORKS_SM3 +#include "FoamGeneration_nvsf.fx" diff --git a/src/shader/FoamGeneration_SM4.fx b/src/shader/FoamGeneration_SM4.fx new file mode 100644 index 0000000..154d43d --- /dev/null +++ b/src/shader/FoamGeneration_SM4.fx @@ -0,0 +1,30 @@ +// This code contains NVIDIA Confidential Information and is disclosed +// under the Mutual Non-Disclosure Agreement. +// +// Notice +// ALL NVIDIA DESIGN SPECIFICATIONS AND CODE ("MATERIALS") ARE PROVIDED "AS IS" NVIDIA MAKES +// NO REPRESENTATIONS, WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO +// THE MATERIALS, AND EXPRESSLY DISCLAIMS ANY IMPLIED WARRANTIES OF NONINFRINGEMENT, +// MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. +// +// NVIDIA Corporation assumes no responsibility for the consequences of use of such +// information or for any infringement of patents or other rights of third parties that may +// result from its use. No license is granted by implication or otherwise under any patent +// or patent rights of NVIDIA Corporation. No third party distribution is allowed unless +// expressly authorized by NVIDIA. Details are subject to change without notice. +// This code supersedes and replaces all information previously supplied. +// NVIDIA Corporation products are not authorized for use as critical +// components in life support devices or systems without express written approval of +// NVIDIA Corporation. +// +// Copyright � 2008- 2013 NVIDIA Corporation. All rights reserved. +// +// NVIDIA Corporation and its licensors retain all intellectual property and proprietary +// rights in and to this software and related documentation and any modifications thereto. +// Any use, reproduction, disclosure or distribution of this software and related +// documentation without an express license agreement from NVIDIA Corporation is +// strictly prohibited. +// + +#define GFSDK_WAVEWORKS_SM4 +#include "FoamGeneration_nvsf.fx" diff --git a/src/shader/FoamGeneration_glsl.ps b/src/shader/FoamGeneration_glsl.ps new file mode 100644 index 0000000..7581a1f --- /dev/null +++ b/src/shader/FoamGeneration_glsl.ps @@ -0,0 +1,31 @@ +// This code contains NVIDIA Confidential Information and is disclosed +// under the Mutual Non-Disclosure Agreement. +// +// Notice +// ALL NVIDIA DESIGN SPECIFICATIONS AND CODE ("MATERIALS") ARE PROVIDED "AS IS" NVIDIA MAKES +// NO REPRESENTATIONS, WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO +// THE MATERIALS, AND EXPRESSLY DISCLAIMS ANY IMPLIED WARRANTIES OF NONINFRINGEMENT, +// MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. +// +// NVIDIA Corporation assumes no responsibility for the consequences of use of such +// information or for any infringement of patents or other rights of third parties that may +// result from its use. No license is granted by implication or otherwise under any patent +// or patent rights of NVIDIA Corporation. No third party distribution is allowed unless +// expressly authorized by NVIDIA. Details are subject to change without notice. +// This code supersedes and replaces all information previously supplied. +// NVIDIA Corporation products are not authorized for use as critical +// components in life support devices or systems without express written approval of +// NVIDIA Corporation. +// +// Copyright � 2008- 2013 NVIDIA Corporation. All rights reserved. +// +// NVIDIA Corporation and its licensors retain all intellectual property and proprietary +// rights in and to this software and related documentation and any modifications thereto. +// Any use, reproduction, disclosure or distribution of this software and related +// documentation without an express license agreement from NVIDIA Corporation is +// strictly prohibited. +// + +#define GFSDK_WAVEWORKS_GL +#define GFSDK_WAVEWORKS_OMIT_VS +#include "FoamGeneration_nvsf.fx" diff --git a/src/shader/FoamGeneration_glsl.vs b/src/shader/FoamGeneration_glsl.vs new file mode 100644 index 0000000..7be28d6 --- /dev/null +++ b/src/shader/FoamGeneration_glsl.vs @@ -0,0 +1,31 @@ +// This code contains NVIDIA Confidential Information and is disclosed +// under the Mutual Non-Disclosure Agreement. +// +// Notice +// ALL NVIDIA DESIGN SPECIFICATIONS AND CODE ("MATERIALS") ARE PROVIDED "AS IS" NVIDIA MAKES +// NO REPRESENTATIONS, WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO +// THE MATERIALS, AND EXPRESSLY DISCLAIMS ANY IMPLIED WARRANTIES OF NONINFRINGEMENT, +// MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. +// +// NVIDIA Corporation assumes no responsibility for the consequences of use of such +// information or for any infringement of patents or other rights of third parties that may +// result from its use. No license is granted by implication or otherwise under any patent +// or patent rights of NVIDIA Corporation. No third party distribution is allowed unless +// expressly authorized by NVIDIA. Details are subject to change without notice. +// This code supersedes and replaces all information previously supplied. +// NVIDIA Corporation products are not authorized for use as critical +// components in life support devices or systems without express written approval of +// NVIDIA Corporation. +// +// Copyright � 2008- 2013 NVIDIA Corporation. All rights reserved. +// +// NVIDIA Corporation and its licensors retain all intellectual property and proprietary +// rights in and to this software and related documentation and any modifications thereto. +// Any use, reproduction, disclosure or distribution of this software and related +// documentation without an express license agreement from NVIDIA Corporation is +// strictly prohibited. +// + +#define GFSDK_WAVEWORKS_GL +#define GFSDK_WAVEWORKS_OMIT_PS +#include "FoamGeneration_nvsf.fx" diff --git a/src/shader/FoamGeneration_gnm.fx b/src/shader/FoamGeneration_gnm.fx new file mode 100644 index 0000000..c81afad --- /dev/null +++ b/src/shader/FoamGeneration_gnm.fx @@ -0,0 +1,30 @@ +// This code contains NVIDIA Confidential Information and is disclosed +// under the Mutual Non-Disclosure Agreement. +// +// Notice +// ALL NVIDIA DESIGN SPECIFICATIONS AND CODE ("MATERIALS") ARE PROVIDED "AS IS" NVIDIA MAKES +// NO REPRESENTATIONS, WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO +// THE MATERIALS, AND EXPRESSLY DISCLAIMS ANY IMPLIED WARRANTIES OF NONINFRINGEMENT, +// MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. +// +// NVIDIA Corporation assumes no responsibility for the consequences of use of such +// information or for any infringement of patents or other rights of third parties that may +// result from its use. No license is granted by implication or otherwise under any patent +// or patent rights of NVIDIA Corporation. No third party distribution is allowed unless +// expressly authorized by NVIDIA. Details are subject to change without notice. +// This code supersedes and replaces all information previously supplied. +// NVIDIA Corporation products are not authorized for use as critical +// components in life support devices or systems without express written approval of +// NVIDIA Corporation. +// +// Copyright � 2008- 2013 NVIDIA Corporation. All rights reserved. +// +// NVIDIA Corporation and its licensors retain all intellectual property and proprietary +// rights in and to this software and related documentation and any modifications thereto. +// Any use, reproduction, disclosure or distribution of this software and related +// documentation without an express license agreement from NVIDIA Corporation is +// strictly prohibited. +// + +#define GFSDK_WAVEWORKS_GNM +#include "FoamGeneration_nvsf.fx" diff --git a/src/shader/Quadtree.fxh b/src/shader/Quadtree.fxh new file mode 100644 index 0000000..b06e437 --- /dev/null +++ b/src/shader/Quadtree.fxh @@ -0,0 +1,178 @@ +/* + * This code contains NVIDIA Confidential Information and is disclosed + * under the Mutual Non-Disclosure Agreement. + * + * Notice + * ALL NVIDIA DESIGN SPECIFICATIONS AND CODE ("MATERIALS") ARE PROVIDED "AS IS" NVIDIA MAKES + * NO REPRESENTATIONS, WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO + * THE MATERIALS, AND EXPRESSLY DISCLAIMS ANY IMPLIED WARRANTIES OF NONINFRINGEMENT, + * MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. + * + * NVIDIA Corporation assumes no responsibility for the consequences of use of such + * information or for any infringement of patents or other rights of third parties that may + * result from its use. No license is granted by implication or otherwise under any patent + * or patent rights of NVIDIA Corporation. No third party distribution is allowed unless + * expressly authorized by NVIDIA. Details are subject to change without notice. + * This code supersedes and replaces all information previously supplied. + * NVIDIA Corporation products are not authorized for use as critical + * components in life support devices or systems without express written approval of + * NVIDIA Corporation. + * + * Copyright � 2008- 2013 NVIDIA Corporation. All rights reserved. + * + * NVIDIA Corporation and its licensors retain all intellectual property and proprietary + * rights in and to this software and related documentation and any modifications thereto. + * Any use, reproduction, disclosure or distribution of this software and related + * documentation without an express license agreement from NVIDIA Corporation is + * strictly prohibited. + */ + +#include "GFSDK_WaveWorks_Common.fxh" + +/* + * + * + */ + +#if defined(GFSDK_WAVEWORKS_SM3) || defined(GFSDK_WAVEWORKS_GL) + #define GFSDK_WAVEWORKS_BEGIN_GEOM_VS_CBUFFER(Label) + #define GFSDK_WAVEWORKS_END_GEOM_VS_CBUFFER +#endif + +#if defined( GFSDK_WAVEWORKS_USE_TESSELLATION ) + GFSDK_WAVEWORKS_BEGIN_GEOM_HS_CBUFFER(nvsf_eyepos_buffer) + GFSDK_WAVEWORKS_DECLARE_GEOM_HS_CONSTANT(float4, nvsf_g_hsWorldEye, 0) + GFSDK_WAVEWORKS_DECLARE_GEOM_HS_CONSTANT(float4, nvsf_g_tessellationParams, 1) + GFSDK_WAVEWORKS_END_GEOM_HS_CBUFFER +#endif + +GFSDK_WAVEWORKS_BEGIN_GEOM_VS_CBUFFER(nvsf_geom_buffer) +GFSDK_WAVEWORKS_DECLARE_GEOM_VS_CONSTANT(float4x3, nvsf_g_matLocalWorld, 0) +GFSDK_WAVEWORKS_DECLARE_GEOM_VS_CONSTANT(float4, nvsf_g_vsEyePos, 3) +GFSDK_WAVEWORKS_DECLARE_GEOM_VS_CONSTANT(float4, nvsf_g_MorphParam, 4) +GFSDK_WAVEWORKS_END_GEOM_VS_CBUFFER + + +struct GFSDK_WAVEWORKS_VERTEX_INPUT +{ + float4 nvsf_vPos SEMANTIC(POSITION); +}; + +#if !defined(GFSDK_WAVEWORKS_USE_TESSELLATION) +float3 GFSDK_WaveWorks_GetUndisplacedVertexWorldPosition(GFSDK_WAVEWORKS_VERTEX_INPUT In) +{ + float2 nvsf_vpos = In.nvsf_vPos.xy; + + // Use multiple levels of geo-morphing to smooth away LOD boundaries + float nvsf_geomorph_scale = 0.25f; + + float2 nvsf_geomorph_offset = float2(nvsf_g_MorphParam.w,nvsf_g_MorphParam.w); + float2 nvsf_vpos_src = nvsf_vpos; + float2 nvsf_vpos_target = nvsf_vpos_src; + float nvsf_geomorph_amount = 0.f; + + for(int nvsf_geomorph_level = 0; nvsf_geomorph_level != 4; ++nvsf_geomorph_level) { + + float2 nvsf_intpart; + float2 nvsf_rempart = modf(nvsf_geomorph_scale*nvsf_vpos_src.xy,nvsf_intpart); + + float2 nvsf_mirror = float2(1.0f, 1.0f); + + if(nvsf_rempart.x > 0.5f) + { + nvsf_rempart.x = 1.0f - nvsf_rempart.x; + nvsf_mirror.x = -nvsf_mirror.x; + } + if(nvsf_rempart.y > 0.5f) + { + nvsf_rempart.y = 1.0f - nvsf_rempart.y; + nvsf_mirror.y = -nvsf_mirror.y; + } + + + if(0.25f == nvsf_rempart.x && 0.25f == nvsf_rempart.y) nvsf_vpos_target.xy = nvsf_vpos_src.xy - nvsf_geomorph_offset*nvsf_mirror; + else if(0.25f == nvsf_rempart.x) nvsf_vpos_target.x = nvsf_vpos_src.x + nvsf_geomorph_offset.x*nvsf_mirror.x; + else if(0.25f == nvsf_rempart.y) nvsf_vpos_target.y = nvsf_vpos_src.y + nvsf_geomorph_offset.y*nvsf_mirror.y; + + float3 nvsf_eyevec = mul(float4(nvsf_vpos_target,0.f,1.f), nvsf_g_matLocalWorld) - nvsf_g_vsEyePos.xyz; + float nvsf_d = length(nvsf_eyevec); + float nvsf_geomorph_target_level = log2(nvsf_d * nvsf_g_MorphParam.x) + 1.f; + nvsf_geomorph_amount = saturate(2.0*(nvsf_geomorph_target_level - float(nvsf_geomorph_level))); + if(nvsf_geomorph_amount < 1.f) + { + break; + } + else + { + nvsf_vpos_src = nvsf_vpos_target; + nvsf_geomorph_scale *= 0.5f; + nvsf_geomorph_offset *= -2.f; + } + } + + nvsf_vpos.xy = lerp(nvsf_vpos_src, nvsf_vpos_target, nvsf_geomorph_amount); + return mul(float4(nvsf_vpos,In.nvsf_vPos.zw), nvsf_g_matLocalWorld); +} +#endif + + +#if defined(GFSDK_WAVEWORKS_USE_TESSELLATION) +float3 GFSDK_WaveWorks_GetUndisplacedVertexWorldPosition(GFSDK_WAVEWORKS_VERTEX_INPUT In) +{ + float2 nvsf_vpos = In.nvsf_vPos.xy; + // Use multiple levels of geo-morphing to smooth away LOD boundaries + float nvsf_geomorph_scale = 0.5f; + float nvsf_geomorph_offset = abs(nvsf_g_MorphParam.w); + float2 nvsf_vpos_src = nvsf_vpos; + float2 nvsf_vpos_target = nvsf_vpos_src; + float nvsf_geomorph_amount = 0.f; + + //nvsf_vpos_target.x += 0.25*nvsf_geomorph_offset; + //nvsf_vpos_src.x += 0.25*nvsf_geomorph_offset; + + for(int nvsf_geomorph_level = 0; nvsf_geomorph_level != 4; ++nvsf_geomorph_level) { + + float2 nvsf_intpart; + float2 nvsf_rempart = modf(nvsf_geomorph_scale*nvsf_vpos_src.xy,nvsf_intpart); + if(0.5f == nvsf_rempart.x) + { + nvsf_vpos_target.x = nvsf_vpos_src.x + nvsf_geomorph_offset; + } + + if(0.5f == nvsf_rempart.y) + { + nvsf_vpos_target.y = nvsf_vpos_src.y + nvsf_geomorph_offset; + } + + float3 nvsf_eyevec = mul(float4(nvsf_vpos_target,0.f,1.f), nvsf_g_matLocalWorld) - nvsf_g_vsEyePos.xyz; + float nvsf_d = length(nvsf_eyevec); + float nvsf_geomorph_target_level = log2(nvsf_d * nvsf_g_MorphParam.x) + 1.f; + nvsf_geomorph_amount = saturate(3.0*(nvsf_geomorph_target_level - float(nvsf_geomorph_level))); + if(nvsf_geomorph_amount < 1.f) { + break; + } else { + nvsf_vpos_src = nvsf_vpos_target; + nvsf_geomorph_scale *= 0.5f; + nvsf_geomorph_offset *= 2.f; + } + } + nvsf_vpos.xy = lerp(nvsf_vpos_src, nvsf_vpos_target, nvsf_geomorph_amount); + return mul(float4(nvsf_vpos,In.nvsf_vPos.zw), nvsf_g_matLocalWorld); +} + +float GFSDK_WaveWorks_GetEdgeTessellationFactor(float4 vertex1, float4 vertex2) +{ + float3 nvsf_edge_center = 0.5*(vertex1.xyz + vertex2.xyz); + float nvsf_edge_length = length (vertex1.xyz - vertex2.xyz); + float nvsf_edge_distance = length(nvsf_g_hsWorldEye.xyz - nvsf_edge_center.xyz); + return nvsf_g_tessellationParams.x * nvsf_edge_length / nvsf_edge_distance; +} + +float GFSDK_WaveWorks_GetVertexTargetTessellatedEdgeLength(float3 vertex) +{ + float nvsf_vertex_distance = length(nvsf_g_hsWorldEye.xyz - vertex.xyz); + return nvsf_vertex_distance / nvsf_g_tessellationParams.x; +} + +#endif + diff --git a/src/shader/Quadtree_GNM_sig.fx b/src/shader/Quadtree_GNM_sig.fx new file mode 100644 index 0000000..110b805 --- /dev/null +++ b/src/shader/Quadtree_GNM_sig.fx @@ -0,0 +1,43 @@ +// This code contains NVIDIA Confidential Information and is disclosed +// under the Mutual Non-Disclosure Agreement. +// +// Notice +// ALL NVIDIA DESIGN SPECIFICATIONS AND CODE ("MATERIALS") ARE PROVIDED "AS IS" NVIDIA MAKES +// NO REPRESENTATIONS, WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO +// THE MATERIALS, AND EXPRESSLY DISCLAIMS ANY IMPLIED WARRANTIES OF NONINFRINGEMENT, +// MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. +// +// NVIDIA Corporation assumes no responsibility for the consequences of use of such +// information or for any infringement of patents or other rights of third parties that may +// result from its use. No license is granted by implication or otherwise under any patent +// or patent rights of NVIDIA Corporation. No third party distribution is allowed unless +// expressly authorized by NVIDIA. Details are subject to change without notice. +// This code supersedes and replaces all information previously supplied. +// NVIDIA Corporation products are not authorized for use as critical +// components in life support devices or systems without express written approval of +// NVIDIA Corporation. +// +// Copyright � 2008- 2013 NVIDIA Corporation. All rights reserved. +// +// NVIDIA Corporation and its licensors retain all intellectual property and proprietary +// rights in and to this software and related documentation and any modifications thereto. +// Any use, reproduction, disclosure or distribution of this software and related +// documentation without an express license agreement from NVIDIA Corporation is +// strictly prohibited. +// + +#define GFSDK_WAVEWORKS_GNM +#define GFSDK_WAVEWORKS_DECLARE_GEOM_VS_CONSTANT(Type,Label,Regoff) Type Label; +#define GFSDK_WAVEWORKS_BEGIN_GEOM_VS_CBUFFER(Label,Regoff) ConstantBuffer Label { +#define GFSDK_WAVEWORKS_END_GEOM_VS_CBUFFER }; + +#define GFSDK_WAVEWORKS_DECLARE_GEOM_HS_CONSTANT(Type,Label,Regoff) Type Label; +#define GFSDK_WAVEWORKS_BEGIN_GEOM_HS_CBUFFER(Label,Regoff) ConstantBuffer Label { +#define GFSDK_WAVEWORKS_END_GEOM_HS_CBUFFER }; + +#include "GFSDK_WaveWorks_Quadtree.fxh" + +float4 GFSDK_WAVEWORKS_VERTEX_INPUT_Sig(GFSDK_WAVEWORKS_VERTEX_INPUT In) : VS_OUTPUT +{ + return In.nv_waveworks_quad7; +} diff --git a/src/shader/Quadtree_SM4_sig.fx b/src/shader/Quadtree_SM4_sig.fx new file mode 100644 index 0000000..b1b0884 --- /dev/null +++ b/src/shader/Quadtree_SM4_sig.fx @@ -0,0 +1,39 @@ +// This code contains NVIDIA Confidential Information and is disclosed +// under the Mutual Non-Disclosure Agreement. +// +// Notice +// ALL NVIDIA DESIGN SPECIFICATIONS AND CODE ("MATERIALS") ARE PROVIDED "AS IS" NVIDIA MAKES +// NO REPRESENTATIONS, WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO +// THE MATERIALS, AND EXPRESSLY DISCLAIMS ANY IMPLIED WARRANTIES OF NONINFRINGEMENT, +// MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. +// +// NVIDIA Corporation assumes no responsibility for the consequences of use of such +// information or for any infringement of patents or other rights of third parties that may +// result from its use. No license is granted by implication or otherwise under any patent +// or patent rights of NVIDIA Corporation. No third party distribution is allowed unless +// expressly authorized by NVIDIA. Details are subject to change without notice. +// This code supersedes and replaces all information previously supplied. +// NVIDIA Corporation products are not authorized for use as critical +// components in life support devices or systems without express written approval of +// NVIDIA Corporation. +// +// Copyright � 2008- 2013 NVIDIA Corporation. All rights reserved. +// +// NVIDIA Corporation and its licensors retain all intellectual property and proprietary +// rights in and to this software and related documentation and any modifications thereto. +// Any use, reproduction, disclosure or distribution of this software and related +// documentation without an express license agreement from NVIDIA Corporation is +// strictly prohibited. +// + +#define GFSDK_WAVEWORKS_SM4 +#define GFSDK_WAVEWORKS_DECLARE_GEOM_VS_CONSTANT(Type,Label,Regoff) Type Label; +#define GFSDK_WAVEWORKS_BEGIN_GEOM_VS_CBUFFER(Label) cbuffer Label { +#define GFSDK_WAVEWORKS_END_GEOM_VS_CBUFFER }; + +#include "GFSDK_WaveWorks_Quadtree.fxh" + +float4 GFSDK_WAVEWORKS_VERTEX_INPUT_Sig(GFSDK_WAVEWORKS_VERTEX_INPUT In) : SV_Position +{ + return In.nv_waveworks_quad7; +} diff --git a/src/shader/Quadtree_SM5_sig.fx b/src/shader/Quadtree_SM5_sig.fx new file mode 100644 index 0000000..89a2e51 --- /dev/null +++ b/src/shader/Quadtree_SM5_sig.fx @@ -0,0 +1,45 @@ +// This code contains NVIDIA Confidential Information and is disclosed +// under the Mutual Non-Disclosure Agreement. +// +// Notice +// ALL NVIDIA DESIGN SPECIFICATIONS AND CODE ("MATERIALS") ARE PROVIDED "AS IS" NVIDIA MAKES +// NO REPRESENTATIONS, WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO +// THE MATERIALS, AND EXPRESSLY DISCLAIMS ANY IMPLIED WARRANTIES OF NONINFRINGEMENT, +// MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. +// +// NVIDIA Corporation assumes no responsibility for the consequences of use of such +// information or for any infringement of patents or other rights of third parties that may +// result from its use. No license is granted by implication or otherwise under any patent +// or patent rights of NVIDIA Corporation. No third party distribution is allowed unless +// expressly authorized by NVIDIA. Details are subject to change without notice. +// This code supersedes and replaces all information previously supplied. +// NVIDIA Corporation products are not authorized for use as critical +// components in life support devices or systems without express written approval of +// NVIDIA Corporation. +// +// Copyright � 2008- 2013 NVIDIA Corporation. All rights reserved. +// +// NVIDIA Corporation and its licensors retain all intellectual property and proprietary +// rights in and to this software and related documentation and any modifications thereto. +// Any use, reproduction, disclosure or distribution of this software and related +// documentation without an express license agreement from NVIDIA Corporation is +// strictly prohibited. +// + +#define GFSDK_WAVEWORKS_SM5 +#define GFSDK_WAVEWORKS_USE_TESSELLATION + +#define GFSDK_WAVEWORKS_DECLARE_GEOM_VS_CONSTANT(Type,Label,Regoff) Type Label; +#define GFSDK_WAVEWORKS_BEGIN_GEOM_VS_CBUFFER(Label) cbuffer Label { +#define GFSDK_WAVEWORKS_END_GEOM_VS_CBUFFER }; + +#define GFSDK_WAVEWORKS_DECLARE_GEOM_HS_CONSTANT(Type,Label,Regoff) Type Label; +#define GFSDK_WAVEWORKS_BEGIN_GEOM_HS_CBUFFER(Label) cbuffer Label { +#define GFSDK_WAVEWORKS_END_GEOM_HS_CBUFFER }; + +#include "GFSDK_WaveWorks_Quadtree.fxh" + +float4 GFSDK_WAVEWORKS_VERTEX_INPUT_Sig(GFSDK_WAVEWORKS_VERTEX_INPUT In) : SV_Position +{ + return In.nv_waveworks_quad7; +} |