| 1 | float3 expand(float3 v) |
|---|
| 2 | { |
|---|
| 3 | return v;//(v - 0.5) * 2; |
|---|
| 4 | } |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | void Blinn_vp ( |
|---|
| 8 | float2 uv : TEXCOORD0, |
|---|
| 9 | float4 position : POSITION, |
|---|
| 10 | float3 normal : NORMAL, |
|---|
| 11 | float4 vertCol : COLOR, |
|---|
| 12 | |
|---|
| 13 | //vert shader input |
|---|
| 14 | uniform float4 lightPosition, |
|---|
| 15 | uniform float3 eyePosition, |
|---|
| 16 | |
|---|
| 17 | //both in object space |
|---|
| 18 | uniform float4x4 worldviewproj, |
|---|
| 19 | out float4 oClipPos : POSITION, |
|---|
| 20 | |
|---|
| 21 | //pass to clipping |
|---|
| 22 | out float4 oPos : TEXCOORD0, |
|---|
| 23 | out float3 oNorm : TEXCOORD1, |
|---|
| 24 | out float4 oLightPos: TEXCOORD2, |
|---|
| 25 | out float3 oEyePos : TEXCOORD3, |
|---|
| 26 | |
|---|
| 27 | //support for texture with the per pixel lighting |
|---|
| 28 | out float2 oUv : TEXCOORD4, |
|---|
| 29 | |
|---|
| 30 | // Vertex coloring |
|---|
| 31 | out float4 oVertCol : COLOR |
|---|
| 32 | ) |
|---|
| 33 | { |
|---|
| 34 | oClipPos = mul(worldviewproj, position); |
|---|
| 35 | |
|---|
| 36 | oPos = position; |
|---|
| 37 | oNorm = normal; |
|---|
| 38 | oLightPos = lightPosition; |
|---|
| 39 | oEyePos = eyePosition; |
|---|
| 40 | |
|---|
| 41 | //support for texture with the per pixel lighting |
|---|
| 42 | oUv = uv; |
|---|
| 43 | oVertCol = vertCol; |
|---|
| 44 | |
|---|
| 45 | //Remarks: |
|---|
| 46 | //since we want exact calculations in every case, |
|---|
| 47 | //calculate light and eye directions in frag shader, |
|---|
| 48 | //don't let the rasterizer interpolate them from here |
|---|
| 49 | |
|---|
| 50 | //more costy than doing directions here, per-vertex, but |
|---|
| 51 | //produces accurate lighting in VERY low tessellation cases, |
|---|
| 52 | //light close to surface (for.ex. closer than poly size) |
|---|
| 53 | } |
|---|
| 54 | |
|---|
| 55 | |
|---|
| 56 | void Blinn_4UV_vp ( |
|---|
| 57 | float2 uv : TEXCOORD0, |
|---|
| 58 | float2 uv1 : TEXCOORD1, |
|---|
| 59 | float2 uv2 : TEXCOORD2, |
|---|
| 60 | float2 uv3 : TEXCOORD3, |
|---|
| 61 | float4 position : POSITION, |
|---|
| 62 | float3 normal : NORMAL, |
|---|
| 63 | float4 vertCol : COLOR, |
|---|
| 64 | |
|---|
| 65 | //vert shader input |
|---|
| 66 | uniform float4 lightPosition, |
|---|
| 67 | uniform float3 eyePosition, |
|---|
| 68 | |
|---|
| 69 | //both in object space |
|---|
| 70 | uniform float4x4 worldviewproj, |
|---|
| 71 | out float4 oClipPos : POSITION, |
|---|
| 72 | |
|---|
| 73 | //pass to clipping |
|---|
| 74 | out float4 oPos : TEXCOORD0, |
|---|
| 75 | out float3 oNorm : TEXCOORD1, |
|---|
| 76 | out float4 oLightPos: TEXCOORD2, |
|---|
| 77 | out float3 oEyePos : TEXCOORD3, |
|---|
| 78 | |
|---|
| 79 | //support for texture with the per pixel lighting |
|---|
| 80 | out float2 oUv : TEXCOORD4, |
|---|
| 81 | out float2 oUv1 : TEXCOORD5, |
|---|
| 82 | out float2 oUv2 : TEXCOORD6, |
|---|
| 83 | out float2 oUv3 : TEXCOORD7, |
|---|
| 84 | out float4 oVertCol : COLOR |
|---|
| 85 | ) |
|---|
| 86 | { |
|---|
| 87 | oClipPos = mul(worldviewproj, position); |
|---|
| 88 | |
|---|
| 89 | oPos = position; |
|---|
| 90 | oNorm = normal; |
|---|
| 91 | oLightPos = lightPosition; |
|---|
| 92 | oEyePos = eyePosition; |
|---|
| 93 | |
|---|
| 94 | //support for texture with the per pixel lighting |
|---|
| 95 | oUv = uv; |
|---|
| 96 | oUv1 = uv1; |
|---|
| 97 | oUv2 = uv2; |
|---|
| 98 | oUv3 = uv3; |
|---|
| 99 | |
|---|
| 100 | oVertCol = vertCol; |
|---|
| 101 | |
|---|
| 102 | //Remarks: |
|---|
| 103 | //since we want exact calculations in every case, |
|---|
| 104 | //calculate light and eye directions in frag shader, |
|---|
| 105 | //don't let the rasterizer interpolate them from here |
|---|
| 106 | |
|---|
| 107 | //more costy than doing directions here, per-vertex, but |
|---|
| 108 | //produces accurate lighting in VERY low tessellation cases, |
|---|
| 109 | //light close to surface (for.ex. closer than poly size) |
|---|
| 110 | } |
|---|
| 111 | |
|---|
| 112 | void Blinn_pure_fp ( |
|---|
| 113 | float4 pos : TEXCOORD0, |
|---|
| 114 | float3 normal : TEXCOORD1, |
|---|
| 115 | float4 lightpos : TEXCOORD2, |
|---|
| 116 | float3 eyepos : TEXCOORD3, |
|---|
| 117 | float4 vertCol : COLOR, |
|---|
| 118 | |
|---|
| 119 | |
|---|
| 120 | uniform float4 lightDiffuse, |
|---|
| 121 | uniform float4 lightSpecular, |
|---|
| 122 | uniform float4 sceneAmbient, |
|---|
| 123 | uniform float4 ambientColor, |
|---|
| 124 | uniform float4 diffuseColor, |
|---|
| 125 | uniform float4 specularColor, |
|---|
| 126 | uniform float specularLevel, |
|---|
| 127 | uniform float glossLevel, |
|---|
| 128 | uniform float opacity, |
|---|
| 129 | |
|---|
| 130 | out float4 oColor : COLOR |
|---|
| 131 | ) |
|---|
| 132 | { |
|---|
| 133 | float4 shadeColor = float4(0,0,0,1); |
|---|
| 134 | float3 N = normalize(normal); |
|---|
| 135 | |
|---|
| 136 | //Remarks: |
|---|
| 137 | |
|---|
| 138 | //we could do this normalize() in vert shader, or skip it |
|---|
| 139 | float3 EyeDir = normalize(eyepos - pos.xyz); |
|---|
| 140 | |
|---|
| 141 | // When doing Blinn-Phong shading we only use the half angle |
|---|
| 142 | float3 LightDir = normalize(lightpos.xyz - (pos * lightpos.w).xyz); |
|---|
| 143 | float3 HalfAngle = normalize(LightDir + EyeDir); |
|---|
| 144 | float NdotL = dot(LightDir, N); |
|---|
| 145 | float NdotH = dot(HalfAngle, N); |
|---|
| 146 | |
|---|
| 147 | // Max Style Specularity |
|---|
| 148 | float exponent = clamp(NdotH,0,1); |
|---|
| 149 | exponent = pow(exponent, glossLevel) * specularLevel *1.5; |
|---|
| 150 | |
|---|
| 151 | // calculate lighting components |
|---|
| 152 | float4 ambient = sceneAmbient * ambientColor; |
|---|
| 153 | float4 diffuse = lightDiffuse * diffuseColor * clamp(dot(N,LightDir),0,1); |
|---|
| 154 | float4 specular= lightSpecular * specularColor * exponent; |
|---|
| 155 | |
|---|
| 156 | //Do the Blinn per pixel lighting |
|---|
| 157 | shadeColor = ambient; |
|---|
| 158 | shadeColor += diffuse; |
|---|
| 159 | shadeColor += specular; |
|---|
| 160 | shadeColor.a = opacity; |
|---|
| 161 | |
|---|
| 162 | oColor = vertCol * shadeColor; |
|---|
| 163 | } |
|---|
| 164 | |
|---|
| 165 | ///////////////////////////////////////////// |
|---|
| 166 | void Vertex_Color_vp ( |
|---|
| 167 | float4 position: POSITION, |
|---|
| 168 | float4 vertCol : COLOR, |
|---|
| 169 | //both in object space |
|---|
| 170 | uniform float4x4 worldviewproj, |
|---|
| 171 | out float4 oClipPos : POSITION, |
|---|
| 172 | out float4 oVertCol: COLOR |
|---|
| 173 | ) |
|---|
| 174 | { |
|---|
| 175 | oClipPos = mul(worldviewproj, position); |
|---|
| 176 | oVertCol = vertCol; |
|---|
| 177 | } |
|---|
| 178 | |
|---|
| 179 | void Vertex_Color_fp ( |
|---|
| 180 | float4 vertCol : COLOR, |
|---|
| 181 | out float4 oColor : COLOR |
|---|
| 182 | ) |
|---|
| 183 | { |
|---|
| 184 | oColor = vertCol; |
|---|
| 185 | } |
|---|
| 186 | |
|---|
| 187 | |
|---|
| 188 | void Blinn_DiffuseMap_fp ( |
|---|
| 189 | float4 pos : TEXCOORD0, |
|---|
| 190 | float3 normal : TEXCOORD1, |
|---|
| 191 | float4 lightpos : TEXCOORD2, |
|---|
| 192 | float3 eyepos : TEXCOORD3, |
|---|
| 193 | float4 vertCol : COLOR, |
|---|
| 194 | |
|---|
| 195 | //Support for texture with the per pixel lighting |
|---|
| 196 | float2 uv : TEXCOORD4, |
|---|
| 197 | |
|---|
| 198 | uniform float4 lightDiffuse, |
|---|
| 199 | uniform float4 lightSpecular, |
|---|
| 200 | uniform float4 sceneAmbient, |
|---|
| 201 | uniform float4 ambientColor, |
|---|
| 202 | uniform float4 diffuseColor, |
|---|
| 203 | uniform float4 specularColor, |
|---|
| 204 | uniform float specularLevel, |
|---|
| 205 | uniform float glossLevel, |
|---|
| 206 | uniform float opacity, |
|---|
| 207 | uniform float amount, |
|---|
| 208 | |
|---|
| 209 | uniform sampler2D diffuseMap, |
|---|
| 210 | |
|---|
| 211 | out float4 oColor : COLOR |
|---|
| 212 | ) |
|---|
| 213 | { |
|---|
| 214 | float4 shadeColor = float4(0,0,0,1); |
|---|
| 215 | float3 N = normalize(normal); |
|---|
| 216 | |
|---|
| 217 | //Remarks: |
|---|
| 218 | |
|---|
| 219 | //we could do this normalize() in vert shader, or skip it |
|---|
| 220 | float3 EyeDir = normalize(eyepos - pos.xyz); |
|---|
| 221 | |
|---|
| 222 | // When doing Blinn-Phong shading we only use the half angle |
|---|
| 223 | float3 LightDir = normalize(lightpos.xyz - (pos * lightpos.w).xyz); |
|---|
| 224 | float3 HalfAngle = normalize(LightDir + EyeDir); |
|---|
| 225 | float NdotL = dot(LightDir, N); |
|---|
| 226 | float NdotH = dot(HalfAngle, N); |
|---|
| 227 | |
|---|
| 228 | // Max Style Specularity |
|---|
| 229 | float exponent = clamp(NdotH,0,1); |
|---|
| 230 | exponent = pow(exponent, glossLevel) * specularLevel *1.5; |
|---|
| 231 | |
|---|
| 232 | //support for texture with the per pixel lighting |
|---|
| 233 | float3 textColour = expand(tex2D(diffuseMap, uv).xyz); |
|---|
| 234 | |
|---|
| 235 | // calculate lighting components |
|---|
| 236 | float4 ambient = sceneAmbient * ambientColor; |
|---|
| 237 | float4 diffuse = lightDiffuse * diffuseColor * clamp(dot(N,LightDir),0,1); |
|---|
| 238 | float4 specular= lightSpecular * specularColor * exponent; |
|---|
| 239 | float4 texture = float4(textColour.xyz, 1) * clamp(dot(N,LightDir),0,1); |
|---|
| 240 | |
|---|
| 241 | //Do the Blinn per pixel lighting |
|---|
| 242 | shadeColor = ambient; |
|---|
| 243 | shadeColor += diffuse; |
|---|
| 244 | // Blend texture onto surface |
|---|
| 245 | shadeColor = shadeColor *(1-amount) + (amount * texture); |
|---|
| 246 | shadeColor += specular; |
|---|
| 247 | |
|---|
| 248 | shadeColor.a = opacity; |
|---|
| 249 | |
|---|
| 250 | oColor = vertCol * shadeColor; |
|---|
| 251 | } |
|---|
| 252 | |
|---|
| 253 | void Blinn_SpecularColor_fp ( |
|---|
| 254 | float4 pos : TEXCOORD0, |
|---|
| 255 | float3 normal : TEXCOORD1, |
|---|
| 256 | float4 lightpos : TEXCOORD2, |
|---|
| 257 | float3 eyepos : TEXCOORD3, |
|---|
| 258 | float4 vertCol : COLOR, |
|---|
| 259 | |
|---|
| 260 | //Support for texture with the per pixel lighting |
|---|
| 261 | float2 uv : TEXCOORD4, |
|---|
| 262 | |
|---|
| 263 | uniform float4 lightDiffuse, |
|---|
| 264 | uniform float4 lightSpecular, |
|---|
| 265 | uniform float4 sceneAmbient, |
|---|
| 266 | uniform float4 ambientColor, |
|---|
| 267 | uniform float4 diffuseColor, |
|---|
| 268 | uniform float4 specularColor, |
|---|
| 269 | uniform float specularLevel, |
|---|
| 270 | uniform float glossLevel, |
|---|
| 271 | uniform float opacity, |
|---|
| 272 | uniform float amount, |
|---|
| 273 | |
|---|
| 274 | uniform sampler2D specularMap, |
|---|
| 275 | |
|---|
| 276 | out float4 oColor : COLOR |
|---|
| 277 | ) |
|---|
| 278 | { |
|---|
| 279 | float4 shadeColor = float4(0,0,0,1); |
|---|
| 280 | float3 N = normalize(normal); |
|---|
| 281 | amount = clamp(amount,0.0,1.0); |
|---|
| 282 | |
|---|
| 283 | //Remarks: |
|---|
| 284 | |
|---|
| 285 | //we could do this normalize() in vert shader, or skip it |
|---|
| 286 | float3 EyeDir = normalize(eyepos - pos.xyz); |
|---|
| 287 | |
|---|
| 288 | // When doing Blinn-Phong shading we only use the half angle |
|---|
| 289 | float3 LightDir = normalize(lightpos.xyz - (pos * lightpos.w).xyz); |
|---|
| 290 | float3 HalfAngle = normalize(LightDir + EyeDir); |
|---|
| 291 | float NdotL = dot(LightDir, N); |
|---|
| 292 | float NdotH = dot(HalfAngle, N); |
|---|
| 293 | |
|---|
| 294 | // Max Style Specularity |
|---|
| 295 | float exponent = clamp(NdotH,0,1); |
|---|
| 296 | exponent = pow(exponent, glossLevel) * specularLevel *1.5; |
|---|
| 297 | |
|---|
| 298 | //support for texture with the per pixel lighting |
|---|
| 299 | float3 specColour = expand(tex2D(specularMap, uv).xyz); |
|---|
| 300 | |
|---|
| 301 | // calculate lighting components |
|---|
| 302 | float4 ambient = sceneAmbient * ambientColor; |
|---|
| 303 | float4 diffuse = lightDiffuse * diffuseColor * clamp(dot(N,LightDir),0,1); |
|---|
| 304 | float4 specular= lightSpecular * specularColor * exponent; |
|---|
| 305 | |
|---|
| 306 | //Do the Blinn per pixel lighting |
|---|
| 307 | shadeColor = ambient; |
|---|
| 308 | shadeColor += diffuse; |
|---|
| 309 | // Blend amounts |
|---|
| 310 | shadeColor += specular * (1-amount) + amount * clamp( float4(specColour.xyz,1)* exponent, 0.0, 1.0); |
|---|
| 311 | shadeColor.a = opacity; |
|---|
| 312 | |
|---|
| 313 | oColor = vertCol * shadeColor; |
|---|
| 314 | } |
|---|
| 315 | |
|---|
| 316 | |
|---|
| 317 | void Blinn_SpecularLevel_fp ( |
|---|
| 318 | float4 pos : TEXCOORD0, |
|---|
| 319 | float3 normal : TEXCOORD1, |
|---|
| 320 | float4 lightpos : TEXCOORD2, |
|---|
| 321 | float3 eyepos : TEXCOORD3, |
|---|
| 322 | float4 vertCol : COLOR, |
|---|
| 323 | |
|---|
| 324 | //Support for texture with the per pixel lighting |
|---|
| 325 | float2 uv : TEXCOORD4, |
|---|
| 326 | |
|---|
| 327 | uniform float4 lightDiffuse, |
|---|
| 328 | uniform float4 lightSpecular, |
|---|
| 329 | uniform float4 sceneAmbient, |
|---|
| 330 | uniform float4 ambientColor, |
|---|
| 331 | uniform float4 diffuseColor, |
|---|
| 332 | uniform float4 specularColor, |
|---|
| 333 | uniform float specularLevel, |
|---|
| 334 | uniform float glossLevel, |
|---|
| 335 | uniform float opacity, |
|---|
| 336 | uniform float amount, |
|---|
| 337 | |
|---|
| 338 | uniform sampler2D specularMap, |
|---|
| 339 | |
|---|
| 340 | out float4 oColor : COLOR |
|---|
| 341 | ) |
|---|
| 342 | { |
|---|
| 343 | float4 shadeColor = float4(0,0,0,1); |
|---|
| 344 | float3 N = normalize(normal); |
|---|
| 345 | amount = clamp(amount,0.0,1.0); |
|---|
| 346 | |
|---|
| 347 | //Remarks: |
|---|
| 348 | |
|---|
| 349 | //we could do this normalize() in vert shader, or skip it |
|---|
| 350 | float3 EyeDir = normalize(eyepos - pos.xyz); |
|---|
| 351 | |
|---|
| 352 | // When doing Blinn-Phong shading we only use the half angle |
|---|
| 353 | float3 LightDir = normalize(lightpos.xyz - (pos * lightpos.w).xyz); |
|---|
| 354 | float3 HalfAngle = normalize(LightDir + EyeDir); |
|---|
| 355 | float NdotL = dot(LightDir, N); |
|---|
| 356 | float NdotH = dot(HalfAngle, N); |
|---|
| 357 | |
|---|
| 358 | // Max Style Specularity |
|---|
| 359 | float exponent = clamp(NdotH,0,1); |
|---|
| 360 | exponent = pow(exponent, glossLevel) * specularLevel *1.5; |
|---|
| 361 | |
|---|
| 362 | //support for texture with the per pixel lighting |
|---|
| 363 | float3 specIntensity = expand(tex2D(specularMap, uv).xyz); |
|---|
| 364 | |
|---|
| 365 | // convert into grey scale for intensity ---THIS WE MIGHT IGNORE--- |
|---|
| 366 | |
|---|
| 367 | specIntensity = (specIntensity.x+specIntensity.y+specIntensity.z)/3; |
|---|
| 368 | |
|---|
| 369 | // calculate lighting components |
|---|
| 370 | float4 ambient = sceneAmbient * ambientColor; |
|---|
| 371 | float4 diffuse = lightDiffuse * diffuseColor * clamp(dot(N,LightDir),0,1); |
|---|
| 372 | float4 specular= lightSpecular * specularColor * exponent; |
|---|
| 373 | |
|---|
| 374 | //Do the Blinn per pixel lighting |
|---|
| 375 | shadeColor = ambient; |
|---|
| 376 | shadeColor += diffuse; |
|---|
| 377 | // Blend amounts |
|---|
| 378 | shadeColor += specular * (1-amount) + amount * clamp( float4(specIntensity.xyz,1)* exponent, 0.0, 1.0); |
|---|
| 379 | shadeColor.a = opacity; |
|---|
| 380 | |
|---|
| 381 | oColor = vertCol * shadeColor; |
|---|
| 382 | } |
|---|
| 383 | |
|---|
| 384 | |
|---|
| 385 | void Blinn_SelfIllumination_fp ( |
|---|
| 386 | float4 pos : TEXCOORD0, |
|---|
| 387 | float3 normal : TEXCOORD1, |
|---|
| 388 | float4 lightpos : TEXCOORD2, |
|---|
| 389 | float3 eyepos : TEXCOORD3, |
|---|
| 390 | float4 vertCol : COLOR, |
|---|
| 391 | |
|---|
| 392 | //Support for texture with the per pixel lighting |
|---|
| 393 | float2 uv : TEXCOORD4, |
|---|
| 394 | float2 uv1 : TEXCOORD5, |
|---|
| 395 | float2 uv2 : TEXCOORD6, |
|---|
| 396 | float2 uv3 : TEXCOORD7, |
|---|
| 397 | |
|---|
| 398 | uniform float4 lightDiffuse, |
|---|
| 399 | uniform float4 lightSpecular, |
|---|
| 400 | uniform float4 sceneAmbient, |
|---|
| 401 | uniform float4 ambientColor, |
|---|
| 402 | uniform float4 diffuseColor, |
|---|
| 403 | uniform float4 specularColor, |
|---|
| 404 | uniform float specularLevel, |
|---|
| 405 | uniform float glossLevel, |
|---|
| 406 | uniform float opacity, |
|---|
| 407 | uniform float amount, |
|---|
| 408 | uniform float uvIndex, |
|---|
| 409 | |
|---|
| 410 | uniform sampler2D illumMap, |
|---|
| 411 | |
|---|
| 412 | out float4 oColor : COLOR |
|---|
| 413 | ) |
|---|
| 414 | { |
|---|
| 415 | float4 shadeColor = float4(0,0,0,1); |
|---|
| 416 | float3 N = normalize(normal); |
|---|
| 417 | //amount = clamp(amount,0.0,1.0); |
|---|
| 418 | |
|---|
| 419 | //Remarks: |
|---|
| 420 | |
|---|
| 421 | //we could do this normalize() in vert shader, or skip it |
|---|
| 422 | float3 EyeDir = normalize(eyepos - pos.xyz); |
|---|
| 423 | |
|---|
| 424 | // When doing Blinn-Phong shading we only use the half angle |
|---|
| 425 | float3 LightDir = normalize(lightpos.xyz - (pos * lightpos.w).xyz); |
|---|
| 426 | float3 HalfAngle = normalize(LightDir + EyeDir); |
|---|
| 427 | float NdotL = dot(LightDir, N); |
|---|
| 428 | float NdotH = dot(HalfAngle, N); |
|---|
| 429 | |
|---|
| 430 | // Max Style Specularity |
|---|
| 431 | float exponent = clamp(NdotH,0,1); |
|---|
| 432 | exponent = pow(exponent, glossLevel) * specularLevel *1.5; |
|---|
| 433 | |
|---|
| 434 | //support for texture with the per pixel lighting |
|---|
| 435 | float3 illumFactor = expand(tex2D(illumMap, uv).xyz); |
|---|
| 436 | if(uvIndex == 1.0) |
|---|
| 437 | illumFactor = expand(tex2D(illumMap, uv1).xyz); |
|---|
| 438 | if(uvIndex == 2.0) |
|---|
| 439 | illumFactor = expand(tex2D(illumMap, uv2).xyz); |
|---|
| 440 | if(uvIndex == 3.0) |
|---|
| 441 | illumFactor = expand(tex2D(illumMap, uv3).xyz); |
|---|
| 442 | |
|---|
| 443 | illumFactor *= amount; |
|---|
| 444 | |
|---|
| 445 | // calculate lighting components |
|---|
| 446 | float4 ambient = sceneAmbient * ambientColor; |
|---|
| 447 | float4 diffuse = diffuseColor * float4(illumFactor.xyz,1); |
|---|
| 448 | float4 specular= lightSpecular * specularColor * exponent; |
|---|
| 449 | |
|---|
| 450 | //Do the Blinn per pixel lighting |
|---|
| 451 | shadeColor = ambient; |
|---|
| 452 | shadeColor += diffuse; |
|---|
| 453 | // Blend amounts |
|---|
| 454 | shadeColor += specular; |
|---|
| 455 | shadeColor.a = opacity; |
|---|
| 456 | |
|---|
| 457 | oColor = vertCol * shadeColor; |
|---|
| 458 | } |
|---|
| 459 | |
|---|
| 460 | void Blinn_DiffuseAndOpacityMap_fp ( |
|---|
| 461 | float4 pos : TEXCOORD0, |
|---|
| 462 | float3 normal : TEXCOORD1, |
|---|
| 463 | float4 lightpos : TEXCOORD2, |
|---|
| 464 | float3 eyepos : TEXCOORD3, |
|---|
| 465 | float4 vertCol : COLOR, |
|---|
| 466 | |
|---|
| 467 | //Support for texture with the per pixel lighting |
|---|
| 468 | float2 uv : TEXCOORD4, |
|---|
| 469 | |
|---|
| 470 | uniform float4 lightDiffuse, |
|---|
| 471 | uniform float4 lightSpecular, |
|---|
| 472 | uniform float4 sceneAmbient, |
|---|
| 473 | uniform float4 ambientColor, |
|---|
| 474 | uniform float4 diffuseColor, |
|---|
| 475 | uniform float4 specularColor, |
|---|
| 476 | uniform float specularLevel, |
|---|
| 477 | uniform float glossLevel, |
|---|
| 478 | uniform float opacity, |
|---|
| 479 | uniform float amount, |
|---|
| 480 | |
|---|
| 481 | uniform sampler2D diffuseMap, |
|---|
| 482 | uniform sampler2D opacityMap, |
|---|
| 483 | |
|---|
| 484 | out float4 oColor : COLOR |
|---|
| 485 | ) |
|---|
| 486 | { |
|---|
| 487 | float4 shadeColor = float4(0,0,0,1); |
|---|
| 488 | float3 N = normalize(normal); |
|---|
| 489 | |
|---|
| 490 | //Remarks: |
|---|
| 491 | |
|---|
| 492 | //we could do this normalize() in vert shader, or skip it |
|---|
| 493 | float3 EyeDir = normalize(eyepos - pos.xyz); |
|---|
| 494 | |
|---|
| 495 | // When doing Blinn-Phong shading we only use the half angle |
|---|
| 496 | float3 LightDir = normalize(lightpos.xyz - (pos * lightpos.w).xyz); |
|---|
| 497 | float3 HalfAngle = normalize(LightDir + EyeDir); |
|---|
| 498 | float NdotL = dot(LightDir, N); |
|---|
| 499 | float NdotH = dot(HalfAngle, N); |
|---|
| 500 | |
|---|
| 501 | // Max Style Specularity |
|---|
| 502 | float exponent = clamp(NdotH,0,1); |
|---|
| 503 | exponent = pow(exponent, glossLevel) * specularLevel *1.5; |
|---|
| 504 | |
|---|
| 505 | //support for texture with the per pixel lighting |
|---|
| 506 | float3 textColour = expand(tex2D(diffuseMap, uv).xyz); |
|---|
| 507 | float4 opacityColour = tex2D(opacityMap, uv); |
|---|
| 508 | |
|---|
| 509 | // calculate lighting components |
|---|
| 510 | float4 ambient = sceneAmbient * ambientColor; |
|---|
| 511 | float4 diffuse = lightDiffuse * diffuseColor * clamp(dot(N,LightDir),0,1); |
|---|
| 512 | float4 specular= lightSpecular * specularColor * exponent; |
|---|
| 513 | float4 texture = float4(textColour.xyz, 1) * clamp(dot(N,LightDir),0,1); |
|---|
| 514 | |
|---|
| 515 | //Do the Blinn per pixel lighting |
|---|
| 516 | shadeColor = ambient; |
|---|
| 517 | shadeColor += diffuse; |
|---|
| 518 | // Blend texture onto surface |
|---|
| 519 | shadeColor = shadeColor *(1-amount) + (amount * texture); |
|---|
| 520 | shadeColor += specular; |
|---|
| 521 | |
|---|
| 522 | shadeColor.a = opacityColour.a * opacity; |
|---|
| 523 | |
|---|
| 524 | oColor = vertCol * shadeColor; |
|---|
| 525 | } |
|---|
| 526 | |
|---|