summaryrefslogtreecommitdiff
path: root/tests/hlsl/dxsdk/BasicHLSL11
diff options
context:
space:
mode:
authorTim Foley <tfoley@nvidia.com>2017-06-09 11:34:21 -0700
committerTim Foley <tfoley@nvidia.com>2017-06-09 13:44:59 -0700
commitfcf83dbf9effab3bd98bad2b83b2468b7eb05cfd (patch)
tree41047c94883b86ec085a81597391ce3ef557cd43 /tests/hlsl/dxsdk/BasicHLSL11
parent52e8d4b9a27ab0060f874c3a63ab531847be35c0 (diff)
Initial import of code.
Diffstat (limited to 'tests/hlsl/dxsdk/BasicHLSL11')
-rw-r--r--tests/hlsl/dxsdk/BasicHLSL11/BasicHLSL.fx158
-rw-r--r--tests/hlsl/dxsdk/BasicHLSL11/BasicHLSL11_PS.hlsl51
-rw-r--r--tests/hlsl/dxsdk/BasicHLSL11/BasicHLSL11_VS.hlsl49
3 files changed, 258 insertions, 0 deletions
diff --git a/tests/hlsl/dxsdk/BasicHLSL11/BasicHLSL.fx b/tests/hlsl/dxsdk/BasicHLSL11/BasicHLSL.fx
new file mode 100644
index 000000000..bd28f862b
--- /dev/null
+++ b/tests/hlsl/dxsdk/BasicHLSL11/BasicHLSL.fx
@@ -0,0 +1,158 @@
+//TEST_IGNORE_FILE:
+//--------------------------------------------------------------------------------------
+// File: BasicHLSL.fx
+//
+// The effect file for the BasicHLSL sample.
+//
+// Copyright (c) Microsoft Corporation. All rights reserved.
+//--------------------------------------------------------------------------------------
+
+
+//--------------------------------------------------------------------------------------
+// Global variables
+//--------------------------------------------------------------------------------------
+float4 g_MaterialAmbientColor; // Material's ambient color
+float4 g_MaterialDiffuseColor; // Material's diffuse color
+int g_nNumLights;
+
+float3 g_LightDir; // Light's direction in world space
+float4 g_LightDiffuse; // Light's diffuse color
+float4 g_LightAmbient; // Light's ambient color
+
+texture g_MeshTexture; // Color texture for mesh
+
+float g_fTime; // App's time in seconds
+float4x4 g_mWorld; // World matrix for object
+float4x4 g_mWorldViewProjection; // World * View * Projection matrix
+
+
+
+//--------------------------------------------------------------------------------------
+// Texture samplers
+//--------------------------------------------------------------------------------------
+sampler MeshTextureSampler =
+sampler_state
+{
+ Texture = <g_MeshTexture>;
+ MipFilter = LINEAR;
+ MinFilter = LINEAR;
+ MagFilter = LINEAR;
+};
+
+
+//--------------------------------------------------------------------------------------
+// Vertex shader output structure
+//--------------------------------------------------------------------------------------
+struct VS_OUTPUT
+{
+ float4 Position : POSITION; // vertex position
+ float4 Diffuse : COLOR0; // vertex diffuse color (note that COLOR0 is clamped from 0..1)
+ float2 TextureUV : TEXCOORD0; // vertex texture coords
+};
+
+
+//--------------------------------------------------------------------------------------
+// This shader computes standard transform and lighting
+//--------------------------------------------------------------------------------------
+VS_OUTPUT RenderSceneVS( float4 vPos : POSITION,
+ float3 vNormal : NORMAL,
+ float2 vTexCoord0 : TEXCOORD0,
+ uniform int nNumLights,
+ uniform bool bTexture,
+ uniform bool bAnimate )
+{
+
+ VS_OUTPUT Output;
+ float3 vNormalWorldSpace;
+
+ // Transform the position from object space to homogeneous projection space
+ Output.Position = mul(vPos, g_mWorldViewProjection);
+
+ // Transform the normal from object space to world space
+ vNormalWorldSpace = normalize(mul(vNormal, (float3x3)g_mWorld)); // normal (world space)
+
+ // Compute simple directional lighting equation
+ float3 vTotalLightDiffuse = float3(0,0,0);
+ for(int i=0; i<nNumLights; i++ )
+ vTotalLightDiffuse += g_LightDiffuse * max(0,dot(vNormalWorldSpace, g_LightDir));
+
+ Output.Diffuse.rgb = g_MaterialDiffuseColor * vTotalLightDiffuse +
+ g_MaterialAmbientColor * g_LightAmbient;
+ Output.Diffuse.a = 1.0f;
+
+ // Just copy the texture coordinate through
+ if( bTexture )
+ Output.TextureUV = vTexCoord0;
+ else
+ Output.TextureUV = 0;
+
+ return Output;
+}
+
+
+//--------------------------------------------------------------------------------------
+// Pixel shader output structure
+//--------------------------------------------------------------------------------------
+struct PS_OUTPUT
+{
+ float4 RGBColor : COLOR0; // Pixel color
+};
+
+
+//--------------------------------------------------------------------------------------
+// This shader outputs the pixel's color by modulating the texture's
+// color with diffuse material color
+//--------------------------------------------------------------------------------------
+PS_OUTPUT RenderScenePS( VS_OUTPUT In,
+ uniform bool bTexture )
+{
+ PS_OUTPUT Output;
+
+ // Lookup mesh texture and modulate it with diffuse
+ if( bTexture )
+ Output.RGBColor = tex2D(MeshTextureSampler, In.TextureUV) * In.Diffuse;
+ else
+ Output.RGBColor = In.Diffuse;
+
+ return Output;
+}
+
+
+//--------------------------------------------------------------------------------------
+// Renders scene to render target
+//--------------------------------------------------------------------------------------
+technique RenderSceneWithTexture1Light
+{
+ pass P0
+ {
+ VertexShader = compile vs_2_0 RenderSceneVS( 1, true, true );
+ PixelShader = compile ps_2_0 RenderScenePS( true ); // trivial pixel shader (could use FF instead if desired)
+ }
+}
+
+technique RenderSceneWithTexture2Light
+{
+ pass P0
+ {
+ VertexShader = compile vs_2_0 RenderSceneVS( 2, true, true );
+ PixelShader = compile ps_2_0 RenderScenePS( true ); // trivial pixel shader (could use FF instead if desired)
+ }
+}
+
+technique RenderSceneWithTexture3Light
+{
+ pass P0
+ {
+ VertexShader = compile vs_2_0 RenderSceneVS( 3, true, true );
+ PixelShader = compile ps_2_0 RenderScenePS( true ); // trivial pixel shader (could use FF instead if desired)
+ }
+}
+
+technique RenderSceneNoTexture
+{
+ pass P0
+ {
+ VertexShader = compile vs_2_0 RenderSceneVS( 1, false, false );
+ PixelShader = compile ps_2_0 RenderScenePS( false ); // trivial pixel shader (could use FF instead if desired)
+ }
+}
diff --git a/tests/hlsl/dxsdk/BasicHLSL11/BasicHLSL11_PS.hlsl b/tests/hlsl/dxsdk/BasicHLSL11/BasicHLSL11_PS.hlsl
new file mode 100644
index 000000000..78fff9eeb
--- /dev/null
+++ b/tests/hlsl/dxsdk/BasicHLSL11/BasicHLSL11_PS.hlsl
@@ -0,0 +1,51 @@
+//TEST:COMPARE_HLSL: -target dxbc-assembly -profile ps_4_0 -entry PSMain
+//--------------------------------------------------------------------------------------
+// File: BasicHLSL11_PS.hlsl
+//
+// The pixel shader file for the BasicHLSL11 sample.
+//
+// Copyright (c) Microsoft Corporation. All rights reserved.
+//--------------------------------------------------------------------------------------
+
+//--------------------------------------------------------------------------------------
+// Globals
+//--------------------------------------------------------------------------------------
+cbuffer cbPerObject : register( b0 )
+{
+ float4 g_vObjectColor : packoffset( c0 );
+};
+
+cbuffer cbPerFrame : register( b1 )
+{
+ float3 g_vLightDir : packoffset( c0 );
+ float g_fAmbient : packoffset( c0.w );
+};
+
+//--------------------------------------------------------------------------------------
+// Textures and Samplers
+//--------------------------------------------------------------------------------------
+Texture2D g_txDiffuse : register( t0 );
+SamplerState g_samLinear : register( s0 );
+
+//--------------------------------------------------------------------------------------
+// Input / Output structures
+//--------------------------------------------------------------------------------------
+struct PS_INPUT
+{
+ float3 vNormal : NORMAL;
+ float2 vTexcoord : TEXCOORD0;
+};
+
+//--------------------------------------------------------------------------------------
+// Pixel Shader
+//--------------------------------------------------------------------------------------
+float4 PSMain( PS_INPUT Input ) : SV_TARGET
+{
+ float4 vDiffuse = g_txDiffuse.Sample( g_samLinear, Input.vTexcoord );
+
+ float fLighting = saturate( dot( g_vLightDir, Input.vNormal ) );
+ fLighting = max( fLighting, g_fAmbient );
+
+ return vDiffuse * fLighting;
+}
+
diff --git a/tests/hlsl/dxsdk/BasicHLSL11/BasicHLSL11_VS.hlsl b/tests/hlsl/dxsdk/BasicHLSL11/BasicHLSL11_VS.hlsl
new file mode 100644
index 000000000..cb2c1b950
--- /dev/null
+++ b/tests/hlsl/dxsdk/BasicHLSL11/BasicHLSL11_VS.hlsl
@@ -0,0 +1,49 @@
+//TEST:COMPARE_HLSL: -target dxbc-assembly -profile vs_4_0 -entry VSMain
+//--------------------------------------------------------------------------------------
+// File: BasicHLSL11_VS.hlsl
+//
+// The vertex shader file for the BasicHLSL11 sample.
+//
+// Copyright (c) Microsoft Corporation. All rights reserved.
+//--------------------------------------------------------------------------------------
+
+//--------------------------------------------------------------------------------------
+// Globals
+//--------------------------------------------------------------------------------------
+cbuffer cbPerObject : register( b0 )
+{
+ matrix g_mWorldViewProjection : packoffset( c0 );
+ matrix g_mWorld : packoffset( c4 );
+};
+
+//--------------------------------------------------------------------------------------
+// Input / Output structures
+//--------------------------------------------------------------------------------------
+struct VS_INPUT
+{
+ float4 vPosition : POSITION;
+ float3 vNormal : NORMAL;
+ float2 vTexcoord : TEXCOORD0;
+};
+
+struct VS_OUTPUT
+{
+ float3 vNormal : NORMAL;
+ float2 vTexcoord : TEXCOORD0;
+ float4 vPosition : SV_POSITION;
+};
+
+//--------------------------------------------------------------------------------------
+// Vertex Shader
+//--------------------------------------------------------------------------------------
+VS_OUTPUT VSMain( VS_INPUT Input )
+{
+ VS_OUTPUT Output;
+
+ Output.vPosition = mul( Input.vPosition, g_mWorldViewProjection );
+ Output.vNormal = mul( Input.vNormal, (float3x3)g_mWorld );
+ Output.vTexcoord = Input.vTexcoord;
+
+ return Output;
+}
+