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/SimpleSample11 | |
| parent | 52e8d4b9a27ab0060f874c3a63ab531847be35c0 (diff) | |
Initial import of code.
Diffstat (limited to 'tests/hlsl/dxsdk/SimpleSample11')
| -rw-r--r-- | tests/hlsl/dxsdk/SimpleSample11/SimpleSample.fx | 112 | ||||
| -rw-r--r-- | tests/hlsl/dxsdk/SimpleSample11/SimpleSample.hlsl | 86 |
2 files changed, 198 insertions, 0 deletions
diff --git a/tests/hlsl/dxsdk/SimpleSample11/SimpleSample.fx b/tests/hlsl/dxsdk/SimpleSample11/SimpleSample.fx new file mode 100644 index 000000000..00883ce70 --- /dev/null +++ b/tests/hlsl/dxsdk/SimpleSample11/SimpleSample.fx @@ -0,0 +1,112 @@ +//TEST_IGNORE_FILE: +//-------------------------------------------------------------------------------------- +// File: SimpleSample.fx +// +// The effect file for the SimpleSample sample. +// +// Copyright (c) Microsoft Corporation. All rights reserved. +//-------------------------------------------------------------------------------------- + + +//-------------------------------------------------------------------------------------- +// Global variables +//-------------------------------------------------------------------------------------- +float4 g_MaterialAmbientColor; // Material's ambient color +float4 g_MaterialDiffuseColor; // Material's diffuse color +float3 g_LightDir; // Light's direction in world space +float4 g_LightDiffuse; // Light's diffuse 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 ) +{ + 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) + + // Calc diffuse color + Output.Diffuse.rgb = g_MaterialDiffuseColor * g_LightDiffuse * max(0,dot(vNormalWorldSpace, g_LightDir)) + + g_MaterialAmbientColor; + Output.Diffuse.a = 1.0f; + + // Just copy the texture coordinate through + Output.TextureUV = vTexCoord0; + + 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 ) +{ + PS_OUTPUT Output; + + // Lookup mesh texture and modulate it with diffuse + Output.RGBColor = tex2D(MeshTextureSampler, In.TextureUV) * In.Diffuse; + + return Output; +} + + +//-------------------------------------------------------------------------------------- +// Renders scene +//-------------------------------------------------------------------------------------- +technique RenderScene +{ + pass P0 + { + VertexShader = compile vs_2_0 RenderSceneVS(); + PixelShader = compile ps_2_0 RenderScenePS(); + } +} diff --git a/tests/hlsl/dxsdk/SimpleSample11/SimpleSample.hlsl b/tests/hlsl/dxsdk/SimpleSample11/SimpleSample.hlsl new file mode 100644 index 000000000..12f368f86 --- /dev/null +++ b/tests/hlsl/dxsdk/SimpleSample11/SimpleSample.hlsl @@ -0,0 +1,86 @@ +//TEST_IGNORE_FILE: Currently failing due to Spire compiler issues. +//TEST:COMPARE_HLSL: -target dxbc-assembly -profile vs_4_0 -entry RenderSceneVS -profile ps_4_0 -entry RenderScenePS +//-------------------------------------------------------------------------------------- +// File: SimpleSample.hlsl +// +// The HLSL file for the SimpleSample sample for the Direct3D 11 device +// +// Copyright (c) Microsoft Corporation. All rights reserved. +//-------------------------------------------------------------------------------------- + + +//-------------------------------------------------------------------------------------- +// Constant Buffers +//-------------------------------------------------------------------------------------- +cbuffer cbPerObject : register( b0 ) +{ + matrix g_mWorldViewProjection : packoffset( c0 ); + matrix g_mWorld : packoffset( c4 ); + float4 g_MaterialAmbientColor : packoffset( c8 ); + float4 g_MaterialDiffuseColor : packoffset( c9 ); +} + +cbuffer cbPerFrame : register( b1 ) +{ + float3 g_vLightDir : packoffset( c0 ); + float g_fTime : packoffset( c0.w ); + float4 g_LightDiffuse : packoffset( c1 ); +}; + +//----------------------------------------------------------------------------------------- +// Textures and Samplers +//----------------------------------------------------------------------------------------- +Texture2D g_txDiffuse : register( t0 ); +SamplerState g_samLinear : register( s0 ); + +//-------------------------------------------------------------------------------------- +// shader input/output structure +//-------------------------------------------------------------------------------------- +struct VS_INPUT +{ + float4 Position : POSITION; // vertex position + float3 Normal : NORMAL; // this normal comes in per-vertex + float2 TextureUV : TEXCOORD0;// vertex texture coords +}; + +struct VS_OUTPUT +{ + float4 Position : SV_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( VS_INPUT input ) +{ + VS_OUTPUT Output; + float3 vNormalWorldSpace; + + // Transform the position from object space to homogeneous projection space + Output.Position = mul( input.Position, g_mWorldViewProjection ); + + // Transform the normal from object space to world space + vNormalWorldSpace = normalize(mul(input.Normal, (float3x3)g_mWorld)); // normal (world space) + + // Calc diffuse color + Output.Diffuse.rgb = g_MaterialDiffuseColor * g_LightDiffuse * max(0,dot(vNormalWorldSpace, g_vLightDir)) + + g_MaterialAmbientColor; + Output.Diffuse.a = 1.0f; + + // Just copy the texture coordinate through + Output.TextureUV = input.TextureUV; + + return Output; +} + +//-------------------------------------------------------------------------------------- +// This shader outputs the pixel's color by modulating the texture's +// color with diffuse material color +//-------------------------------------------------------------------------------------- +float4 RenderScenePS( VS_OUTPUT In ) : SV_TARGET +{ + // Lookup mesh texture and modulate it with diffuse + return g_txDiffuse.Sample( g_samLinear, In.TextureUV ) * In.Diffuse; +} |
