diff options
| author | Tim Foley <tfoley@nvidia.com> | 2017-06-09 11:34:21 -0700 |
|---|---|---|
| committer | Tim Foley <tfoley@nvidia.com> | 2017-06-09 13:44:59 -0700 |
| commit | fcf83dbf9effab3bd98bad2b83b2468b7eb05cfd (patch) | |
| tree | 41047c94883b86ec085a81597391ce3ef557cd43 /tests/hlsl/dxsdk/Direct3D11TutorialsFX11 | |
| parent | 52e8d4b9a27ab0060f874c3a63ab531847be35c0 (diff) | |
Initial import of code.
Diffstat (limited to 'tests/hlsl/dxsdk/Direct3D11TutorialsFX11')
4 files changed, 731 insertions, 0 deletions
diff --git a/tests/hlsl/dxsdk/Direct3D11TutorialsFX11/Tutorial11/Tutorial11.fx b/tests/hlsl/dxsdk/Direct3D11TutorialsFX11/Tutorial11/Tutorial11.fx new file mode 100644 index 000000000..a647a9079 --- /dev/null +++ b/tests/hlsl/dxsdk/Direct3D11TutorialsFX11/Tutorial11/Tutorial11.fx @@ -0,0 +1,117 @@ +//TEST_IGNORE_FILE: +//-------------------------------------------------------------------------------------- +// File: Tutorial11.fx +// +// Copyright (c) Microsoft Corporation. All rights reserved. +//-------------------------------------------------------------------------------------- + + +//-------------------------------------------------------------------------------------- +// Constant Buffer Variables +//-------------------------------------------------------------------------------------- +Texture2D g_txDiffuse; +SamplerState samLinear +{ + Filter = MIN_MAG_MIP_LINEAR; + AddressU = Wrap; + AddressV = Wrap; +}; + +cbuffer cbConstant +{ + float3 vLightDir = float3(-0.577,0.577,-0.577); +}; + +cbuffer cbChangesEveryFrame +{ + matrix World; + matrix View; + matrix Projection; + float Time; +}; + +cbuffer cbUserChanges +{ + float Waviness; +}; + +struct VS_INPUT +{ + float3 Pos : POSITION; + float3 Norm : NORMAL; + float2 Tex : TEXCOORD0; +}; + +struct PS_INPUT +{ + float4 Pos : SV_POSITION; + float3 Norm : TEXCOORD0; + float2 Tex : TEXCOORD1; +}; + +//-------------------------------------------------------------------------------------- +// DepthStates +//-------------------------------------------------------------------------------------- +DepthStencilState EnableDepth +{ + DepthEnable = TRUE; + DepthWriteMask = ALL; + DepthFunc = LESS_EQUAL; +}; + +BlendState NoBlending +{ + AlphaToCoverageEnable = FALSE; + BlendEnable[0] = FALSE; +}; + + +//-------------------------------------------------------------------------------------- +// Vertex Shader +//-------------------------------------------------------------------------------------- +PS_INPUT VS( VS_INPUT input ) +{ + PS_INPUT output = (PS_INPUT)0; + + output.Pos = mul( float4(input.Pos,1), World ); + + output.Pos.x += sin( output.Pos.y*0.1f + Time )*Waviness; + + output.Pos = mul( output.Pos, View ); + output.Pos = mul( output.Pos, Projection ); + output.Norm = mul( input.Norm, World ); + output.Tex = input.Tex; + + return output; +} + + +//-------------------------------------------------------------------------------------- +// Pixel Shader +//-------------------------------------------------------------------------------------- +float4 PS( PS_INPUT input) : SV_Target +{ + // Calculate lighting assuming light color is <1,1,1,1> + float fLighting = saturate( dot( input.Norm, vLightDir ) ); + float4 outputColor = g_txDiffuse.Sample( samLinear, input.Tex ) * fLighting; + outputColor.a = 1; + return outputColor; +} + + +//-------------------------------------------------------------------------------------- +// Technique +//-------------------------------------------------------------------------------------- +technique11 Render +{ + pass P0 + { + SetVertexShader( CompileShader( vs_4_0, VS() ) ); + SetGeometryShader( NULL ); + SetPixelShader( CompileShader( ps_4_0, PS() ) ); + + SetDepthStencilState( EnableDepth, 0 ); + SetBlendState( NoBlending, float4( 0.0f, 0.0f, 0.0f, 0.0f ), 0xFFFFFFFF ); + } +} + diff --git a/tests/hlsl/dxsdk/Direct3D11TutorialsFX11/Tutorial12/Tutorial12.fx b/tests/hlsl/dxsdk/Direct3D11TutorialsFX11/Tutorial12/Tutorial12.fx new file mode 100644 index 000000000..aae7f9a87 --- /dev/null +++ b/tests/hlsl/dxsdk/Direct3D11TutorialsFX11/Tutorial12/Tutorial12.fx @@ -0,0 +1,129 @@ +//TEST_IGNORE_FILE: +// +// Constant Buffer Variables +// + +Texture2D g_txDiffuse; +SamplerState samLinear +{ + Filter = MIN_MAG_MIP_LINEAR; + AddressU = Wrap; + AddressV = Wrap; +}; + +TextureCube g_txEnvMap; +SamplerState samLinearClamp +{ + Filter = MIN_MAG_MIP_LINEAR; + AddressU = Clamp; + AddressV = Clamp; +}; + +cbuffer cbConstant +{ + float3 vLightDir = float3(-0.577,0.577,-0.577); +}; + +cbuffer cbChangesEveryFrame +{ + matrix World; + matrix View; + matrix Projection; + float Time; +}; + +cbuffer cbUserChanges +{ + float Waviness; +}; + +struct VS_INPUT +{ + float3 Pos : POSITION; //position + float3 Norm : NORMAL; //normal + float2 Tex : TEXCOORD0; //texture coordinate +}; + +struct PS_INPUT +{ + float4 Pos : SV_POSITION; + float3 Norm : TEXCOORD0; + float2 Tex : TEXCOORD1; + float3 ViewR : TEXCOORD2; +}; + +//-------------------------------------------------------------------------------------- +// DepthStates +//-------------------------------------------------------------------------------------- +DepthStencilState EnableDepth +{ + DepthEnable = TRUE; + DepthWriteMask = ALL; + DepthFunc = LESS_EQUAL; +}; + +BlendState NoBlending +{ + AlphaToCoverageEnable = FALSE; + BlendEnable[0] = FALSE; +}; + +// +// Vertex Shader +// +PS_INPUT VS( VS_INPUT input ) +{ + PS_INPUT output = (PS_INPUT)0; + + output.Pos = mul( float4(input.Pos,1), World ); + + output.Pos.x += sin( output.Pos.y*0.1f + Time )*Waviness; + + output.Pos = mul( output.Pos, View ); + output.Pos = mul( output.Pos, Projection ); + output.Norm = mul( input.Norm, (float3x3)World ); + output.Tex = input.Tex; + + // Calculate the reflection vector + float3 viewNorm = mul( output.Norm, (float3x3)View ); + output.ViewR = reflect( viewNorm, float3(0,0,-1.0) ); + + return output; +} + + +// +// Pixel Shader +// +float4 PS( PS_INPUT input) : SV_Target +{ + // Calculate lighting assuming light color is <1,1,1,1> + float fLighting = saturate( dot( input.Norm, vLightDir ) ); + + // Load the environment map texture + float4 cReflect = g_txEnvMap.Sample( samLinearClamp, input.ViewR ); + + // Load the diffuse texture and multiply by the lighting amount + float4 cDiffuse = g_txDiffuse.Sample( samLinear, input.Tex ) * fLighting; + + // Add diffuse to reflection and go + float4 cTotal = cDiffuse + cReflect; + cTotal.a = 1; + return cTotal; +} + +// +// Technique +// +technique11 Render +{ + pass P0 + { + SetVertexShader( CompileShader( vs_4_0, VS() ) ); + SetGeometryShader( NULL ); + SetPixelShader( CompileShader( ps_4_0, PS() ) ); + + SetDepthStencilState( EnableDepth, 0 ); + SetBlendState( NoBlending, float4( 0.0f, 0.0f, 0.0f, 0.0f ), 0xFFFFFFFF ); + } +} diff --git a/tests/hlsl/dxsdk/Direct3D11TutorialsFX11/Tutorial13/Tutorial13.fx b/tests/hlsl/dxsdk/Direct3D11TutorialsFX11/Tutorial13/Tutorial13.fx new file mode 100644 index 000000000..a6f09ecc7 --- /dev/null +++ b/tests/hlsl/dxsdk/Direct3D11TutorialsFX11/Tutorial13/Tutorial13.fx @@ -0,0 +1,191 @@ +//TEST_IGNORE_FILE: +//-------------------------------------------------------------------------------------- +// File: Tutorial13.fx +// +// Copyright (c) Microsoft Corporation. All rights reserved. +//-------------------------------------------------------------------------------------- + + +//-------------------------------------------------------------------------------------- +// Constant Buffer Variables +//-------------------------------------------------------------------------------------- +Texture2D g_txDiffuse; +SamplerState samLinear +{ + Filter = MIN_MAG_MIP_LINEAR; + AddressU = Wrap; + AddressV = Wrap; +}; + +TextureCube g_txEnvMap; +SamplerState samLinearClamp +{ + Filter = MIN_MAG_MIP_LINEAR; + AddressU = Clamp; + AddressV = Clamp; +}; + +cbuffer cbConstant +{ + float3 vLightDir = float3(-0.577,0.577,-0.577); +}; + +cbuffer cbChangesEveryFrame +{ + matrix World; + matrix View; + matrix Projection; + float Time; +}; + +cbuffer cbUserChanges +{ + float Explode; +}; + +struct VS_INPUT +{ + float3 Pos : POSITION; + float3 Norm : NORMAL; + float2 Tex : TEXCOORD0; +}; + +struct GSPS_INPUT +{ + float4 Pos : SV_POSITION; + float3 Norm : TEXCOORD0; + float2 Tex : TEXCOORD1; +}; + +//-------------------------------------------------------------------------------------- +// DepthStates +//-------------------------------------------------------------------------------------- +DepthStencilState EnableDepth +{ + DepthEnable = TRUE; + DepthWriteMask = ALL; + DepthFunc = LESS_EQUAL; +}; + +BlendState NoBlending +{ + AlphaToCoverageEnable = FALSE; + BlendEnable[0] = FALSE; +}; + + +//-------------------------------------------------------------------------------------- +// Vertex Shader +//-------------------------------------------------------------------------------------- +GSPS_INPUT VS( VS_INPUT input ) +{ + GSPS_INPUT output = (GSPS_INPUT)0; + + output.Pos = mul( float4(input.Pos,1), World ); + output.Norm = mul( input.Norm, (float3x3)World ); + output.Tex = input.Tex; + + return output; +} + + +//-------------------------------------------------------------------------------------- +// Geometry Shader +//-------------------------------------------------------------------------------------- +[maxvertexcount(12)] +void GS( triangle GSPS_INPUT input[3], inout TriangleStream<GSPS_INPUT> TriStream ) +{ + GSPS_INPUT output; + + // + // Calculate the face normal + // + float3 faceEdgeA = input[1].Pos - input[0].Pos; + float3 faceEdgeB = input[2].Pos - input[0].Pos; + float3 faceNormal = normalize( cross(faceEdgeA, faceEdgeB) ); + float3 ExplodeAmt = faceNormal*Explode; + + // + // Calculate the face center + // + float3 centerPos = (input[0].Pos.xyz + input[1].Pos.xyz + input[2].Pos.xyz)/3.0; + float2 centerTex = (input[0].Tex + input[1].Tex + input[2].Tex)/3.0; + centerPos += faceNormal*Explode; + + // + // Output the pyramid + // + for( int i=0; i<3; i++ ) + { + output.Pos = input[i].Pos + float4(ExplodeAmt,0); + output.Pos = mul( output.Pos, View ); + output.Pos = mul( output.Pos, Projection ); + output.Norm = input[i].Norm; + output.Tex = input[i].Tex; + TriStream.Append( output ); + + int iNext = (i+1)%3; + output.Pos = input[iNext].Pos + float4(ExplodeAmt,0); + output.Pos = mul( output.Pos, View ); + output.Pos = mul( output.Pos, Projection ); + output.Norm = input[iNext].Norm; + output.Tex = input[iNext].Tex; + TriStream.Append( output ); + + output.Pos = float4(centerPos,1) + float4(ExplodeAmt,0); + output.Pos = mul( output.Pos, View ); + output.Pos = mul( output.Pos, Projection ); + output.Norm = faceNormal; + output.Tex = centerTex; + TriStream.Append( output ); + + TriStream.RestartStrip(); + } + + for( int i=2; i>=0; i-- ) + { + output.Pos = input[i].Pos + float4(ExplodeAmt,0); + output.Pos = mul( output.Pos, View ); + output.Pos = mul( output.Pos, Projection ); + output.Norm = -input[i].Norm; + output.Tex = input[i].Tex; + TriStream.Append( output ); + } + TriStream.RestartStrip(); +} + + +//-------------------------------------------------------------------------------------- +// Pixel Shader +//-------------------------------------------------------------------------------------- +float4 PS( GSPS_INPUT input) : SV_Target +{ + // Calculate lighting assuming light color is <1,1,1,1> + float fLighting = saturate( dot( input.Norm, vLightDir ) ); + + // Load the diffuse texture and multiply by the lighting amount + float4 cDiffuse = g_txDiffuse.Sample( samLinear, input.Tex ) * fLighting; + cDiffuse.a = 1; + + // return diffuse + return cDiffuse; +} + + +//-------------------------------------------------------------------------------------- +// Technique +//-------------------------------------------------------------------------------------- +technique11 Render +{ + pass P0 + { + SetVertexShader( CompileShader( vs_4_0, VS() ) ); + SetGeometryShader( CompileShader( gs_4_0, GS() ) ); + SetPixelShader( CompileShader( ps_4_0, PS() ) ); + + SetBlendState( NoBlending, float4( 0.0f, 0.0f, 0.0f, 0.0f ), 0xFFFFFFFF ); + SetDepthStencilState( EnableDepth, 0 ); + } +} + + diff --git a/tests/hlsl/dxsdk/Direct3D11TutorialsFX11/Tutorial14/Tutorial14.fx b/tests/hlsl/dxsdk/Direct3D11TutorialsFX11/Tutorial14/Tutorial14.fx new file mode 100644 index 000000000..b1e45b842 --- /dev/null +++ b/tests/hlsl/dxsdk/Direct3D11TutorialsFX11/Tutorial14/Tutorial14.fx @@ -0,0 +1,294 @@ +//TEST_IGNORE_FILE: +//-------------------------------------------------------------------------------------- +// File: Tutorial14.fx +// +// Copyright (c) Microsoft Corporation. All rights reserved. +//-------------------------------------------------------------------------------------- + + +//-------------------------------------------------------------------------------------- +// Constant Buffer Variables +//-------------------------------------------------------------------------------------- +Texture2D g_txDiffuse; +SamplerState samLinear +{ + Filter = MIN_MAG_MIP_LINEAR; + AddressU = Wrap; + AddressV = Wrap; +}; + +cbuffer cbConstant +{ + float3 vLightDir = float3(-0.577,0.577,-0.577); +}; + +cbuffer cbChangesEveryFrame +{ + matrix World; + matrix View; + matrix Projection; +}; + +struct VS_INPUT +{ + float3 Pos : POSITION; //position + float3 Norm : NORMAL; //normal + float2 Tex : TEXCOORD0; //texture coordinate +}; + +struct PS_INPUT +{ + float4 Pos : SV_POSITION; + float3 Norm : TEXCOORD0; + float2 Tex : TEXCOORD1; +}; + +struct QUADVS_INPUT +{ + float4 Pos : POSITION; + float2 Tex : TEXCOORD0; +}; + +struct QUADVS_OUTPUT +{ + float4 Pos : SV_POSITION; // Transformed position + float2 Tex : TEXCOORD0; +}; + +//-------------------------------------------------------------------------------------- +// Blending States +//-------------------------------------------------------------------------------------- +BlendState NoBlending +{ + BlendEnable[0] = FALSE; +}; + +BlendState SrcAlphaBlendingAdd +{ + BlendEnable[0] = TRUE; + SrcBlend = SRC_ALPHA; + DestBlend = ONE; + BlendOp = ADD; + SrcBlendAlpha = ZERO; + DestBlendAlpha = ZERO; + BlendOpAlpha = ADD; + RenderTargetWriteMask[0] = 0x0F; +}; + +BlendState SrcAlphaBlendingSub +{ + BlendEnable[0] = TRUE; + SrcBlend = SRC_ALPHA; + DestBlend = ONE; + BlendOp = SUBTRACT; + SrcBlendAlpha = ZERO; + DestBlendAlpha = ZERO; + BlendOpAlpha = ADD; + RenderTargetWriteMask[0] = 0x0F; +}; + +BlendState SrcColorBlendingAdd +{ + BlendEnable[0] = TRUE; + SrcBlend = SRC_COLOR; + DestBlend = ONE; + BlendOp = ADD; + SrcBlendAlpha = ZERO; + DestBlendAlpha = ZERO; + BlendOpAlpha = ADD; + RenderTargetWriteMask[0] = 0x0F; +}; + +BlendState SrcColorBlendingSub +{ + BlendEnable[0] = TRUE; + SrcBlend = SRC_COLOR; + DestBlend = ONE; + BlendOp = SUBTRACT; + SrcBlendAlpha = ZERO; + DestBlendAlpha = ZERO; + BlendOpAlpha = ADD; + RenderTargetWriteMask[0] = 0x0F; +}; + +//-------------------------------------------------------------------------------------- +// Depth/Stencil States +//-------------------------------------------------------------------------------------- +DepthStencilState RenderWithStencilState +{ + DepthEnable = false; + DepthWriteMask = ZERO; + DepthFunc = Less; + + // Setup stencil states + StencilEnable = true; + StencilReadMask = 0xFF; + StencilWriteMask = 0x00; + + FrontFaceStencilFunc = Not_Equal; + FrontFaceStencilPass = Keep; + FrontFaceStencilFail = Zero; + + BackFaceStencilFunc = Not_Equal; + BackFaceStencilPass = Keep; + BackFaceStencilFail = Zero; +}; + + + +//-------------------------------------------------------------------------------------- +// Scene Vertex Shader +//-------------------------------------------------------------------------------------- +PS_INPUT VS( VS_INPUT input ) +{ + PS_INPUT output = (PS_INPUT)0; + + output.Pos = mul( float4(input.Pos,1), World ); + output.Pos = mul( output.Pos, View ); + output.Pos = mul( output.Pos, Projection ); + output.Norm = mul( input.Norm, World ); + output.Tex = input.Tex; + + return output; +} + +//----------------------------------------------------------------------------- +// Quad Vertex Shaders +//----------------------------------------------------------------------------- +QUADVS_OUTPUT QuadVS( QUADVS_INPUT Input ) +{ + QUADVS_OUTPUT Output; + Output.Pos = mul( Input.Pos, World ); + Output.Pos = mul( Output.Pos, View ); + Output.Pos = mul( Output.Pos, Projection ); + Output.Tex = Input.Tex; + return Output; +} + +QUADVS_OUTPUT ScreenQuadVS( QUADVS_INPUT Input ) +{ + QUADVS_OUTPUT Output; + Output.Pos = Input.Pos; + Output.Tex = Input.Tex; + return Output; +} + +//-------------------------------------------------------------------------------------- +// Pixel Shader +//-------------------------------------------------------------------------------------- +float4 PS( PS_INPUT input) : SV_Target +{ + // Calculate lighting assuming light color is <1,1,1,1> + float fLighting = saturate( dot( input.Norm, vLightDir ) ); + float4 outputColor = g_txDiffuse.Sample( samLinear, input.Tex ) * fLighting; + outputColor.a = 1; + return outputColor; +} + +//-------------------------------------------------------------------------------------- +// Quad Pixel Shader +//-------------------------------------------------------------------------------------- +float4 QuadPS( QUADVS_OUTPUT input) : SV_Target +{ + return g_txDiffuse.Sample( samLinear, input.Tex ); +} + + +//-------------------------------------------------------------------------------------- +// Scene Techniques +//-------------------------------------------------------------------------------------- +technique11 RenderScene +{ + pass P0 + { + SetVertexShader( CompileShader( vs_4_0, VS() ) ); + SetGeometryShader( NULL ); + SetPixelShader( CompileShader( ps_4_0, PS() ) ); + SetBlendState( NoBlending, float4( 0.0f, 0.0f, 0.0f, 0.0f ), 0xFFFFFFFF ); + } +} + +//-------------------------------------------------------------------------------------- +// RenderWithStencil - set the depth stencil state inside of the technique +//-------------------------------------------------------------------------------------- +technique11 RenderWithStencil +{ + pass P0 + { + SetVertexShader( CompileShader( vs_4_0, ScreenQuadVS() ) ); + SetGeometryShader( NULL ); + SetPixelShader( CompileShader( ps_4_0, QuadPS() ) ); + + SetBlendState( NoBlending, float4( 0.0f, 0.0f, 0.0f, 0.0f ), 0xFFFFFFFF ); + SetDepthStencilState( RenderWithStencilState, 0 ); + } +} + +//-------------------------------------------------------------------------------------- +// Quad Techniques: Alpha blending state is set inside the technique +//-------------------------------------------------------------------------------------- +technique11 RenderQuadSolid +{ + pass P0 + { + SetVertexShader( CompileShader( vs_4_0, QuadVS() ) ); + SetGeometryShader( NULL ); + SetPixelShader( CompileShader( ps_4_0, QuadPS() ) ); + + SetBlendState( NoBlending, float4( 0.0f, 0.0f, 0.0f, 0.0f ), 0xFFFFFFFF ); + } +} + +//-------------------------------------------------------------------------------------- +technique11 RenderQuadSrcAlphaAdd +{ + pass P0 + { + SetVertexShader( CompileShader( vs_4_0, QuadVS() ) ); + SetGeometryShader( NULL ); + SetPixelShader( CompileShader( ps_4_0, QuadPS() ) ); + + SetBlendState( SrcAlphaBlendingAdd, float4( 0.0f, 0.0f, 0.0f, 0.0f ), 0xFFFFFFFF ); + } +} + +//-------------------------------------------------------------------------------------- +technique11 RenderQuadSrcAlphaSub +{ + pass P0 + { + SetVertexShader( CompileShader( vs_4_0, QuadVS() ) ); + SetGeometryShader( NULL ); + SetPixelShader( CompileShader( ps_4_0, QuadPS() ) ); + + SetBlendState( SrcAlphaBlendingSub, float4( 0.0f, 0.0f, 0.0f, 0.0f ), 0xFFFFFFFF ); + } +} + +//-------------------------------------------------------------------------------------- +technique11 RenderQuadSrcColorAdd +{ + pass P0 + { + SetVertexShader( CompileShader( vs_4_0, QuadVS() ) ); + SetGeometryShader( NULL ); + SetPixelShader( CompileShader( ps_4_0, QuadPS() ) ); + + SetBlendState( SrcColorBlendingAdd, float4( 0.0f, 0.0f, 0.0f, 0.0f ), 0xFFFFFFFF ); + } +} + +//-------------------------------------------------------------------------------------- +technique11 RenderQuadSrcColorSub +{ + pass P0 + { + SetVertexShader( CompileShader( vs_4_0, QuadVS() ) ); + SetGeometryShader( NULL ); + SetPixelShader( CompileShader( ps_4_0, QuadPS() ) ); + + SetBlendState( SrcColorBlendingSub, float4( 0.0f, 0.0f, 0.0f, 0.0f ), 0xFFFFFFFF ); + } +} + + |
