2424 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
2525 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
2626 DEALINGS IN THE SOFTWARE.
27- */
27+ */
2828#ifdef OPENGL_ES
29- #ifdef GL_FRAGMENT_PRECISION_HIGH
30- // Default precision
31- precision highp float ;
32- #else
33- precision mediump float ;
34- #endif
29+ #ifdef GL_FRAGMENT_PRECISION_HIGH
30+ // Default precision
31+ precision highp float ;
32+ #else
33+ precision mediump float ;
34+ #endif
3535#endif
3636
3737uniform vec3 uCamViewVec; // Camera 'at' vector in world space
3838uniform vec4 uAmbientColor; // Ambient color
39- uniform vec4 uSpecularColor; // Specular color
39+ uniform vec4 uSpecularColor; // Specular color
4040uniform vec4 uDiffuseColor; // Diffuse color
4141uniform float uSpecularPower; // Specular power
4242uniform vec3 uLightDirWorld; // Directional light (world space).
4343uniform float uTransparency;
4444uniform sampler1D uTX0;
45+ uniform float uCMInvert;
46+ uniform float uCMShift;
47+ uniform float uCMResolution;
4548
4649// Lighting in world space. Generally, it's better to light in eye space if you
4750// are dealing with point lights. Since we are only dealing with directional
@@ -51,31 +54,43 @@ varying float vFieldData;
5154
5255void main()
5356{
54- // Remember to always negate the light direction for these lighting
55- // calculations. The dot product takes on its greatest values when the angle
56- // between the two vectors diminishes.
57- vec3 invLightDir = - uLightDirWorld;
58- vec3 normal = normalize (vNormal);
59- float diffuse = max (0.0 , dot (normal, invLightDir));
60-
61- // Note, the following is a hack due to legacy meshes still being supported.
62- // We light the object as if it was double sided. We choose the normal based
63- // on the normal that yields the largest diffuse component.
64- float diffuseInv = max (0.0 , dot (- normal, invLightDir));
65-
66- if (diffuse < diffuseInv)
67- {
68- diffuse = diffuseInv;
69- normal = - normal;
70- }
71-
72- vec3 reflection = reflect (invLightDir, normal);
73- float spec = max (0.0 , dot (reflection, uCamViewVec));
74-
75- vec4 diffuseColor = texture1D ( uTX0, vFieldData );
76- // diffuseColor.a = uTransparency;
77-
78- spec = pow (spec, uSpecularPower);
79- gl_FragColor = vec4 ((diffuse * spec * uSpecularColor + diffuse * diffuseColor + uAmbientColor).rgb, uTransparency);
57+ // Remember to always negate the light direction for these lighting
58+ // calculations. The dot product takes on its greatest values when the angle
59+ // between the two vectors diminishes.
60+ vec3 invLightDir = - uLightDirWorld;
61+ vec3 normal = normalize (vNormal);
62+ float diffuse = max (0.0 , dot (normal, invLightDir));
63+
64+ // Note, the following is a hack due to legacy meshes still being supported.
65+ // We light the object as if it was double sided. We choose the normal based
66+ // on the normal that yields the largest diffuse component.
67+ float diffuseInv = max (0.0 , dot (- normal, invLightDir));
68+
69+ if (diffuse < diffuseInv)
70+ {
71+ diffuse = diffuseInv;
72+ normal = - normal;
73+ }
74+
75+ vec3 reflection = reflect (invLightDir, normal);
76+ float spec = max (0.0 , dot (reflection, uCamViewVec));
77+
78+ float param = vFieldData;
79+ float shift = uCMShift;
80+ if (uCMInvert != 0 .) {
81+ param = 1 . - param;
82+ shift = shift * - 1 .;
83+ }
84+ // apply the resolution
85+ int res = int (uCMResolution);
86+ param = float (int (param * (float (res)))) / float (res - 1 );
87+ // the shift is a gamma.
88+ float bp = 1 . / tan ((3.14159265359 / 2 .) * ( 0.5 - shift * 0.5 ));
89+ param = pow (param,bp);
90+
91+ vec4 diffuseColor = texture1D ( uTX0, param );
92+
93+ spec = pow (spec, uSpecularPower);
94+ gl_FragColor = vec4 ((diffuse * spec * uSpecularColor + diffuse * diffuseColor + uAmbientColor).rgb, uTransparency);
8095}
8196
0 commit comments