CGII/framework/shader/cgv_gl/glsl/textured_material.glfs

51 lines
1 KiB
Text
Raw Normal View History

2018-05-17 14:01:02 +00:00
#version 150 compatibility
// diffuse texture map
uniform sampler2D diffuse_map;
// whether to use the diffuse map
uniform bool use_diffuse_map;
// whether to use the bump map
uniform bool use_bump_map;
///
uniform bool use_color_material = true;
///
uniform bool two_sided = false;
// interpolated surface normal in eye space
in vec3 N;
// interpolated surface point in eye space
in vec3 s;
// interpolated texture coordinates
in vec2 tc;
in vec4 clr;
vec3 bump_map_normal(vec3 s, vec2 tc, vec3 N);
vec4 doLighting(vec3 position, vec3 normal, vec4 diffuseMaterial);
void main()
{
// compute bump mapped normal
vec4 diff = gl_FrontMaterial.diffuse;
if (use_color_material) {
diff = clr;
}
if (use_diffuse_map) {
diff = texture2D(diffuse_map, tc);
}
vec3 normal;
if (use_bump_map) {
normal = normalize(bump_map_normal(s,tc,N));
}
else {
normal = N;
}
if (two_sided) {
if (dot(s, normal) > 0.0) {
normal = -normal;
}
}
gl_FragColor = doLighting(s, normal, diff);
gl_FragColor.a = diff.a;
}