|
Last change
on this file since 12091 was
12091,
checked in by wiesep, 7 years ago
|
|
Updated programs and adjusted Material to work with GLSL>150
|
|
File size:
1.0 KB
|
| Line | |
|---|
| 1 | #version 100 |
|---|
| 2 | precision mediump int; |
|---|
| 3 | precision mediump float; |
|---|
| 4 | |
|---|
| 5 | // General functions |
|---|
| 6 | |
|---|
| 7 | // Expand a range-compressed vector |
|---|
| 8 | vec3 expand(vec3 v) |
|---|
| 9 | { |
|---|
| 10 | return (v - 0.5) * 2.0; |
|---|
| 11 | } |
|---|
| 12 | |
|---|
| 13 | uniform vec4 lightDiffuse; |
|---|
| 14 | uniform vec4 lightSpecular; |
|---|
| 15 | uniform sampler2D normalMap; |
|---|
| 16 | |
|---|
| 17 | varying vec4 oUv0; |
|---|
| 18 | varying vec3 oTSLightDir; |
|---|
| 19 | varying vec3 oTSHalfAngle; |
|---|
| 20 | |
|---|
| 21 | // NOTE: GLSL does not have the saturate function. But it is equivalent to clamp(val, 0.0, 1.0) |
|---|
| 22 | |
|---|
| 23 | /* Fragment program which supports specular component */ |
|---|
| 24 | void main() |
|---|
| 25 | { |
|---|
| 26 | // retrieve normalised light vector |
|---|
| 27 | vec3 lightVec = normalize(oTSLightDir); |
|---|
| 28 | |
|---|
| 29 | // retrieve half angle and normalise |
|---|
| 30 | vec3 halfAngle = normalize(oTSHalfAngle); |
|---|
| 31 | |
|---|
| 32 | // get bump map vector, again expand from range-compressed |
|---|
| 33 | vec3 bumpVec = expand(texture2D(normalMap, oUv0.xy).xyz); |
|---|
| 34 | |
|---|
| 35 | // Pre-raise the specular exponent to the eight power |
|---|
| 36 | float specFactor = pow(clamp(dot(bumpVec, halfAngle), 0.0, 1.0), 4.0); |
|---|
| 37 | |
|---|
| 38 | // Calculate dot product for diffuse |
|---|
| 39 | gl_FragColor = (lightDiffuse * clamp(dot(bumpVec, lightVec), 0.0, 1.0)) + |
|---|
| 40 | (lightSpecular * specFactor); |
|---|
| 41 | } |
|---|
Note: See
TracBrowser
for help on using the repository browser.