1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
|
// Shader from NVidia example documentation:
// ftp://download.nvidia.com/developer/SDK/Individual_Samples/
// MEDIA/docPix/docs/FX_Shadowing.pdf
texture CTex : RENDERCOLORTARGET <
float2 Dimensions = {256,256};
string Format = "x8b8g8r8" ;
string UIWidget = "None";
>;
sampler CSamp = sampler_state {
texture = <CTex>;
AddressU = CLAMP; AddressV = CLAMP;
MipFilter = NONE;
MinFilter = LINEAR;
MagFilter = LINEAR;
};
texture DTex : RENDERDEPTHSTENCILTARGET <
float2 Dimensions = {256,256};
string format = "D24S8_SHADOWMAP";
string UIWidget = "None";
>;
sampler DSamp = sampler_state {
texture = <DTex>;
AddressU = CLAMP; AddressV = CLAMP;
MipFilter = NONE;
MinFilter = LINEAR;
MagFilter = LINEAR;
};
float Script : STANDARDSGLOBAL <
string UIWidget = "none";
string ScriptClass = "sceneorobject";
string ScriptOrder = "standard";
string ScriptOutput = "color";
string Script = "Tech=Technique?Shadowed:Unshadowed;";
> = 0.8; // version #
// The following global variables are values to be used
// when clearing color and/or depth buffers
float4 ClearColor <
string UIWidget = "color";
string UIName = "background";
> = {0,0,0,0.0};
float ClearDepth <
string UIWidget = "none";
> = 1.0;
float4 ShadowClearColor <
string UIWidget = "none";
> = {1,1,1,0.0};
void lightingCalc(ShadowingVertexOutput IN,
out float3 litContrib,
out float3 ambiContrib) {
float3 Nn = normalize(IN.WNormal);
float3 Vn = normalize(IN.WView);
Nn = faceforward(Nn,-Vn,Nn);
float falloff = 1.0 / dot(IN.LightVec,IN.LightVec);
float3 Ln = normalize(IN.LightVec);
float3 Hn = normalize(Vn + Ln);
float hdn = dot(Hn,Nn);
float ldn = dot(Ln,Nn);
float4 litVec = lit(ldn,hdn,SpecExpon);
ldn = litVec.y * SpotLightIntensity;
ambiContrib = SurfColor * AmbiLightColor;
float3 diffContrib = SurfColor*(Kd * ldn * SpotLightColor);
float3 specContrib = ((ldn * litVec.z * Ks) * SpotLightColor);
float3 result = diffContrib + specContrib;
float cone = tex2Dproj(SpotSamp,IN.LProj);
litContrib = ((cone*falloff) * result);
}
float4 useShadowPS(ShadowingVertexOutput IN) : COLOR {
float3 litPart, ambiPart;
lightingCalc(IN,litPart,ambiPart);
float4 shadowed = tex2Dproj(ShadDepthSampler,IN.LProj);
return float4((shadowed.x*litPart)+ambiPart,1);
}
float4 unshadowedPS(ShadowingVertexOutput IN) : COLOR {
float3 litPart, ambiPart;
lightingCalc(IN,litPart,ambiPart);
}
technique Unshadowed <
string Script = "Pass=NoShadow;";
> {
pass NoShadow <
string Script =
"RenderColorTarget0=;"
"RenderDepthStencilTarget=;"
"RenderPort=;"
"ClearSetColor=ClearColor;"
"ClearSetDepth=ClearDepth;"
"ClearDepth=Color;"
"Clear=Depth;"
"Draw=geometry;";
> {
VertexShader = compile vs_2_0
shadowUseVS(WorldXf,
WorldITXf,
WorldViewProjXf,
ShadowViewProjXf,
ViewIXf,
ShadBiasXf,
SpotLightPos);
ZEnable = true;
ZWriteEnable = true;
ZFunc = LessEqual;
CullMode = None;
PixelShader = compile ps_2_a unshadowedPS();
}
}
technique Shadowed <
string Script = "Pass=MakeShadow;"
"Pass=UseShadow;";
> {
pass MakeShadow <
string Script =
"RenderColorTarget0=ColorShadMap;"
"RenderDepthStencilTarget=ShadDepthTarget;"
"RenderPort=light0;"
"ClearSetColor=ShadowClearColor;"
"ClearSetDepth=ClearDepth;"
"Clear=Color;"
"Clear=Depth;"
"Draw=geometry;";
> {
VertexShader = compile vs_2_0
shadowGenVS(WorldXf,
WorldITXf,
ShadowViewProjXf);
ZEnable = true;
ZWriteEnable = true;
ZFunc = LessEqual;
CullMode = None;
// no pixel shader needed!
}
pass UseShadow <
string Script =
"RenderColorTarget0=;"
"RenderDepthStencilTarget=;"
" RenderPort=;"
"ClearSetColor=ClearColor;"
"ClearSetDepth=ClearDepth;"
"Clear=Color;"
"Clear=Depth;"
"Draw=geometry;";
> {
VertexShader = compile vs_2_0
shadowUseVS(WorldXf,
WorldITXf,
WorldViewProjXf,
ShadowViewProjXf,
ViewIXf,
ShadBiasXf,
SpotLightPos);
ZEnable = true;
ZWriteEnable = true;
ZFunc = LessEqual;
CullMode = None;
PixelShader = compile ps_2_a useShadowPS();
}
}
|