死体のあなたができる。ライトの位置は、次のようにオブジェクトシェーダーに渡す変数です。
uniform vec4 fvAmbient;
uniform vec4 fvSpecular;
uniform vec4 fvDiffuse;
uniform float fSpecularPower;
uniform sampler2D baseMap;
varying vec2 Texcoord;
varying vec3 ViewDirection;
varying vec3 LightDirection; <------ here is your light position
varying vec3 Normal;
void main( void )
{
vec3 fvLightDirection = normalize( LightDirection );
vec3 fvNormal = normalize( Normal );
float fNDotL = dot( fvNormal, fvLightDirection );
vec3 fvReflection = normalize( ( ( 2.0 * fvNormal ) * fNDotL ) - fvLightDirection );
vec3 fvViewDirection = normalize( ViewDirection );
float fRDotV = max( 0.0, dot( fvReflection, fvViewDirection ) );
vec4 fvBaseColor = texture2D( baseMap, Texcoord );
vec4 fvTotalAmbient = fvAmbient * fvBaseColor;
vec4 fvTotalDiffuse = fvDiffuse * fNDotL * fvBaseColor;
vec4 fvTotalSpecular = fvSpecular * ( pow( fRDotV, fSpecularPower ) );
gl_FragColor = ( fvTotalAmbient + fvTotalDiffuse + fvTotalSpecular );
}
テクスチャと1つの無限に離れたポインライトを備えたシェーダー。
オブジェクト間で光源を移動する必要がある場合は、変数値を変更するように簡単にレンダリングできます。