Navigation überspringen

Harald Markus Wirth


Seiteninhalt:

06 Lighting

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////119:/
// VERTEX SHADER
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////119:/
attribute vec4 aVertexPosition;
attribute vec3 aVertexNormal;
attribute vec2 aTextureCoord;

uniform mat4 uNormalMatrix;
uniform mat4 uModelViewMatrix;
uniform mat4 uProjectionMatrix;

varying highp vec2 vTextureCoord;
varying highp vec3 vLighting;

void main () {
	gl_Position = uProjectionMatrix * uModelViewMatrix * aVertexPosition;
	vTextureCoord = aTextureCoord;

	highp vec3 ambient_light = vec3( 0.3, 0.3, 0.3 );
	highp vec3 directional_light_color = vec3( 1, 1, 1 );
	highp vec3 directional_vector = normalize( vec3( 0.85, 0.8, 0.75 ) );

	highp vec4 transformed_normal = uNormalMatrix * vec4( aVertexNormal, 1.0 );

	highp float directional = max( dot( transformed_normal.xyz, directional_vector ), 0.0 );
	vLighting = ambient_light + (directional_light_color * directional);
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////119:/
// FRAGMENT SHADER
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////119:/
varying highp vec2 vTextureCoord;
varying highp vec3 vLighting;

uniform sampler2D uSampler;

void main () {
	highp vec4 texel_color = texture2D( uSampler, vTextureCoord );
	gl_FragColor = vec4( texel_color.rgb * vLighting, texel_color.a );
}


https://developer.mozilla.org/en-US/docs/Web/API/WebGL_API/Tutorial/Using_textures_in_WebGL



Content Management:

μCMS α1.6