source: GTP/trunk/App/Demos/Illum/EnvMap/Media/UI/Annotated woodSingle.fx @ 1488

Revision 1488, 7.3 KB checked in by szirmay, 18 years ago (diff)
Line 
1
2//////////////////////////////////////////////////////////////////////////////
3// Effect parameters /////////////////////////////////////////////////////////
4//////////////////////////////////////////////////////////////////////////////
5// Global wood desctiption
6// Wood Parameters
7
8string XFile = "TexTeapot.x";
9float ringscale < string UIName = "Ring Scale";
10             string UIWidget = "Numeric";
11             float UIStep = 5.0;
12             string UIHelp = "Ring Density";     
13        > = 5.0f;
14float point_scale < string UIName = "Point Scale";
15             string UIWidget = "Numeric";
16             float UIStep = 0.05;
17             string UIHelp = "Point Scale";     
18        > = 0.05f,
19    turbulence < string UIName = "Turbulence";
20             string UIWidget = "Numeric";
21             float UIStep = 0.05;
22             string UIHelp = "Turbulence";     
23        > = 0.3f;
24
25//string XFile = "bust.x";
26//float ringscale = 30.0f;
27//float point_scale = 0.1f, turbulence = 0.8f;
28
29
30//string XFile = "sphere.x";
31//float ringscale = 15.0f;
32//float point_scale = 1.0f, turbulence = 1.0f;
33
34
35//float3 lightwood = {0.3f, 0.12f, 0.03f};
36//float3 darkwood  = {0.05f, 0.01f, 0.005f};
37
38float3 lightwood < string UIName = "Light Wood Color";
39             string UIWidget = "Color";
40             float UIStep = 0.05;
41             string UIHelp = "The color of the wood between the rings";     
42        > = {0.75f, 0.4f, 0.15f};
43float3 darkwood < string UIName = "Dark Wood Color";
44             string UIWidget = "Color";
45             float UIStep = 0.05;
46             string UIHelp = "The color of the rings";     
47        > = {0.05f, 0.05f, 0.05f};
48
49float3 wood_ambient_color < string UIName = "Ambient Color";
50             string UIWidget = "Color";
51             float UIStep = 0.05;
52             string UIHelp = "Ambient Color of the wood";     
53        > = {0.3f, 0.3f, 0.3f};
54float3 wood_diffuse_color < string UIName = "Diffuse Color";
55             string UIWidget = "Color";
56             float UIStep = 0.05;
57             string UIHelp = "Diffuse Color of the wood";     
58        > = {1.0f, 1.0f, 1.0f};//{0.9f, 0.6f, 0.1f};
59
60
61string t0 = "HLSL Wood";
62
63float4 BCLR = {0.4f, 0.4f, 0.4f, 1.0f};    // Background Color
64
65// GLOBALS for lighting
66// Single Directional Diffuse Light
67float3 g_lhtDir
68<
69    string UIDirectional = "Light Direction";
70> = {-0.5f, -1.0f, 1.0f};    //light Direction
71
72float3 g_lhtCol
73<
74    string UIColor3 = "Light Color";
75> = {0.65f, 0.65f, 0.65f}; // Light Diffuse
76
77float3x3 g_mWld : World;    // World
78float4x4 g_mTot : WorldViewProjection;    // Total
79
80// Viewer constant
81float3  g_ViewDir       = {0.0f,0.0f,-1.0f};   // viewer direction
82
83//////////////////////////////////////////////////////////////////////////////
84// Procedural Texture Vertex Shader  /////////////////////////////////////////
85//////////////////////////////////////////////////////////////////////////////
86
87struct VS_INPUT
88{
89    float3  Pos     : POSITION;
90    float3  Normal  : NORMAL;
91    float3  Tex0    : TEXCOORD0;
92};
93
94struct VS_OUTPUT
95{
96    float4  Pos     : POSITION;
97    float4  noise3d : TEXCOORD0;               
98    float4  noisePos: TEXCOORD1;           
99    float3  Normal  : TEXCOORD2;       
100};
101
102VS_OUTPUT ProcTexTransformGeometry(VS_INPUT i)
103{
104    float4      tmp = {0.0f, 0.0f, 0.0f, 1.0f};
105    float3      ShadowColor, color;
106    float3      wNormal;
107    VS_OUTPUT   o=(VS_OUTPUT)0;
108
109    // Project
110    tmp.xyz     = i.Pos;
111    o.Pos       = mul( tmp, g_mTot);
112    o.noisePos  = tmp * point_scale;
113    o.noise3d   = tmp * point_scale * turbulence;       
114    wNormal     = mul( i.Normal, g_mWld );
115   
116    // normalize normals?
117//    wNormal = normalize(wNormal);
118    o.Normal  = wNormal;
119
120    return o;
121}
122
123//////////////////////////////////////////////////////
124texture tNSEVol
125<
126 string name = "noisevol.dds";
127 string type = "volume";
128>;
129
130uniform sampler   noiseVol_sampler =
131sampler_state
132{
133    texture = <tNSEVol>;
134    MinFilter = Linear;
135    MagFilter = Linear;
136    MipFilter = Point;
137
138    AddressU = Wrap;
139    AddressV = Wrap;
140    AddressW = Wrap;
141};
142
143
144
145//////////////////////////////////////////////////////////////////////////////
146// Wood Shader ///////////////////////////////////////////////////////////////
147//////////////////////////////////////////////////////////////////////////////
148
149struct PS_INPUT
150{
151    float4  noise3d  : TEXCOORD0;           
152    float4  noisePos : TEXCOORD1;           
153    float3  Normal   : TEXCOORD2;           
154};
155
156struct PS_OUTPUT
157{
158    float4 Col   : COLOR;
159};
160
161float3 LambertDiffuse(float3 Normal, float3 lhtDir, float3 lhtCol)
162{
163    float   cosang;
164   
165    // N.L Clamped
166    cosang = max(0.0f, dot(Normal, -lhtDir.xyz));   
167       
168    // propogate scalar result to vector
169    return (cosang * lhtCol);
170}
171
172float3 RoughSpecular(float3 Normal, float3 lhtDir, float3 lhtCol, float roughness, float specpow)
173{
174    float   cosang;
175    float3  H = g_ViewDir -lhtDir.xyz;
176    H = normalize(H);
177   
178    // N.H
179    cosang = dot(Normal, H);   
180   
181    // raise to a power
182    cosang = pow(cosang, specpow);   
183 
184    // Use Light diff color as specular color too
185    return (roughness * cosang * lhtCol);
186}
187
188float3 RoughSpookySpecular(float3 Normal, float3 lhtDir, float3 lhtCol, float roughness, float specpow)
189{
190    float   cosang;
191    float3  H = g_ViewDir -lhtDir.xyz;
192    H = normalize(H);
193   
194    // N.H
195    cosang = dot(Normal, H);   
196   
197    // raise to a power
198    cosang = pow(cosang, specpow);   
199 
200    // Use Light diff color as specular color too
201    return ((1.0f/roughness) * cosang * lhtCol);
202}
203
204PS_OUTPUT Wood(const PS_INPUT v, uniform float spookyness)
205{   
206    PS_OUTPUT o;   
207    float4    colRes;
208    float3    ppNormal = normalize(v.Normal);
209
210    /* Perturb P to add irregularity */
211    float3 PP = v.noisePos;
212    PP += tex3D(noiseVol_sampler, v.noise3d) * 0.1f;
213
214    /* Compute radial distance r from PP to axis of tree */
215    float r = sqrt(PP.y * PP.y + PP.z * PP.z);
216
217   
218    /* Map radial distance r into ring position [0,1] */
219    r *= ringscale;
220    r += abs(v.noise3d.z);
221    r  = frac(r);
222
223    colRes.w = 1.0f;
224       
225    /* Shade using r to vary brightness of wood grain */
226    colRes.rgb = (wood_ambient_color + wood_diffuse_color * LambertDiffuse(ppNormal, g_lhtDir, g_lhtCol) )
227                * lerp(darkwood, lightwood, r);
228    if (spookyness==1.0f)
229       colRes.rgb = colRes.rgb + RoughSpookySpecular(ppNormal, g_lhtDir, g_lhtCol, abs(r), 16);
230    else
231        colRes.rgb = colRes.rgb + RoughSpecular(ppNormal, g_lhtDir, g_lhtCol, abs(r), 64);
232
233//    colRes.rgb = v.noise3d;
234    o.Col = colRes;   
235
236    return o;
237
238
239   
240//////////////////////////////////////////////////////////////////////////////
241// Techniques                      ///////////////////////////////////////////
242//////////////////////////////////////////////////////////////////////////////
243
244technique t0
245{
246    pass p0
247    {       
248        VertexShader = compile vs_2_0 ProcTexTransformGeometry();
249       
250        PixelShader = compile ps_2_0 Wood(0.0f);
251    }
252}
253
254technique t1
255{
256    pass p0
257    {       
258        VertexShader = compile vs_2_0 ProcTexTransformGeometry();
259       
260        PixelShader = compile ps_2_0 Wood(1.0f);
261    }
262}
263
Note: See TracBrowser for help on using the repository browser.