resetting manifest requested domain to floor
[platform/upstream/libbullet.git] / Demos / DX11ClothDemo / cloth_renderer.fx
1 //--------------------------------------------------------------------------------------\r
2 // File: BasicHLSL.fx\r
3 //\r
4 // The effect file for the BasicHLSL sample.  \r
5 // \r
6 // Copyright (c) Microsoft Corporation. All rights reserved.\r
7 //--------------------------------------------------------------------------------------\r
8 \r
9 \r
10 //--------------------------------------------------------------------------------------\r
11 // Global variables\r
12 //--------------------------------------------------------------------------------------\r
13 float4 g_MaterialAmbientColor;      // Material's ambient color\r
14 float4 g_MaterialDiffuseColor;      // Material's diffuse color\r
15 int g_nNumLights;\r
16 \r
17 float3 g_LightDir;               // Light's direction in world space\r
18 float4 g_LightDiffuse;           // Light's diffuse color\r
19 float4 g_LightAmbient;              // Light's ambient color\r
20 \r
21 texture g_MeshTexture;              // Color texture for mesh\r
22 \r
23 float    g_fTime;                   // App's time in seconds\r
24 float4x4 g_mWorld;                  // World matrix for object\r
25 float4x4 g_mWorldViewProjection;    // World * View * Projection matrix\r
26 \r
27 \r
28 \r
29 //--------------------------------------------------------------------------------------\r
30 // Texture samplers\r
31 //--------------------------------------------------------------------------------------\r
32 sampler MeshTextureSampler = \r
33 sampler_state\r
34 {\r
35     Texture = <g_MeshTexture>;\r
36     MipFilter = LINEAR;\r
37     MinFilter = LINEAR;\r
38     MagFilter = LINEAR;\r
39 };\r
40 \r
41 \r
42 //--------------------------------------------------------------------------------------\r
43 // Vertex shader output structure\r
44 //--------------------------------------------------------------------------------------\r
45 struct VS_OUTPUT\r
46 {\r
47     float4 Position   : POSITION;   // vertex position \r
48     float4 Diffuse    : COLOR0;     // vertex diffuse color (note that COLOR0 is clamped from 0..1)\r
49     float2 TextureUV  : TEXCOORD0;  // vertex texture coords \r
50 };\r
51 \r
52 \r
53 //--------------------------------------------------------------------------------------\r
54 // This shader computes standard transform and lighting\r
55 //--------------------------------------------------------------------------------------\r
56 VS_OUTPUT RenderSceneVS( float4 vPos : POSITION, \r
57                          float3 vNormal : NORMAL,\r
58                          float2 vTexCoord0 : TEXCOORD0,\r
59                          uniform int nNumLights,\r
60                          uniform bool bTexture,\r
61                          uniform bool bAnimate )\r
62 {\r
63 \r
64     VS_OUTPUT Output;\r
65     float3 vNormalWorldSpace;\r
66    \r
67     // Transform the position from object space to homogeneous projection space\r
68     Output.Position = mul(vPos, g_mWorldViewProjection);\r
69     \r
70     // Transform the normal from object space to world space    \r
71     vNormalWorldSpace = normalize(mul(vNormal, (float3x3)g_mWorld)); // normal (world space)\r
72     \r
73     // Compute simple directional lighting equation\r
74     float3 vTotalLightDiffuse = float3(0,0,0);\r
75     for(int i=0; i<nNumLights; i++ )\r
76         vTotalLightDiffuse += g_LightDiffuse * max(0,dot(vNormalWorldSpace, g_LightDir));\r
77         \r
78     Output.Diffuse.rgb = g_MaterialDiffuseColor * vTotalLightDiffuse + \r
79                          g_MaterialAmbientColor * g_LightAmbient;   \r
80     Output.Diffuse.a = 1.0f; \r
81     \r
82     // Just copy the texture coordinate through\r
83     if( bTexture ) \r
84         Output.TextureUV = vTexCoord0; \r
85     else\r
86         Output.TextureUV = 0; \r
87     \r
88     return Output;    \r
89 }\r
90 \r
91 \r
92 //--------------------------------------------------------------------------------------\r
93 // Pixel shader output structure\r
94 //--------------------------------------------------------------------------------------\r
95 struct PS_OUTPUT\r
96 {\r
97     float4 RGBColor : COLOR0;  // Pixel color    \r
98 };\r
99 \r
100 \r
101 //--------------------------------------------------------------------------------------\r
102 // This shader outputs the pixel's color by modulating the texture's\r
103 //       color with diffuse material color\r
104 //--------------------------------------------------------------------------------------\r
105 PS_OUTPUT RenderScenePS( VS_OUTPUT In,\r
106                          uniform bool bTexture ) \r
107\r
108     PS_OUTPUT Output;\r
109 \r
110     // Lookup mesh texture and modulate it with diffuse\r
111     if( bTexture )\r
112         Output.RGBColor = tex2D(MeshTextureSampler, In.TextureUV) * In.Diffuse;\r
113     else\r
114         Output.RGBColor = In.Diffuse;\r
115 \r
116     return Output;\r
117 }\r
118 \r
119 \r
120 //--------------------------------------------------------------------------------------\r
121 // Renders scene to render target\r
122 //--------------------------------------------------------------------------------------\r
123 technique RenderSceneWithTexture1Light\r
124 {\r
125     pass P0\r
126     {          \r
127         VertexShader = compile vs_2_0 RenderSceneVS( 1, true, true );\r
128         PixelShader  = compile ps_2_0 RenderScenePS( true ); // trivial pixel shader (could use FF instead if desired)\r
129     }\r
130 }\r
131 \r
132 technique RenderSceneWithTexture2Light\r
133 {\r
134     pass P0\r
135     {          \r
136         VertexShader = compile vs_2_0 RenderSceneVS( 2, true, true );\r
137         PixelShader  = compile ps_2_0 RenderScenePS( true ); // trivial pixel shader (could use FF instead if desired)\r
138     }\r
139 }\r
140 \r
141 technique RenderSceneWithTexture3Light\r
142 {\r
143     pass P0\r
144     {          \r
145         VertexShader = compile vs_2_0 RenderSceneVS( 3, true, true );\r
146         PixelShader  = compile ps_2_0 RenderScenePS( true ); // trivial pixel shader (could use FF instead if desired)\r
147     }\r
148 }\r
149 \r
150 technique RenderSceneNoTexture\r
151 {\r
152     pass P0\r
153     {          \r
154         VertexShader = compile vs_2_0 RenderSceneVS( 1, false, false );\r
155         PixelShader  = compile ps_2_0 RenderScenePS( false ); // trivial pixel shader (could use FF instead if desired)\r
156     }\r
157 }\r