I've been reading tuts on internet about HLSL and i still dont catch the way that shaders works, so im here requesting some help from the shaders masters.
Vertex Shader:
Code: Select all
uniform mat4 matWorldInverse;
varying vec2 Texcoord;
varying vec2 Texcoord2;
varying vec3 ViewDirection;
varying vec3 LightDirection1;
float getLengthSQR( vec3 vec )
{
return dot( vec, vec );
}
void main( void )
{
mat4 LightTransform = gl_ModelViewMatrix;
LightTransform = LightTransform * matWorldInverse;
gl_Position = ftransform();
Texcoord = gl_MultiTexCoord0.xy;
Texcoord2 = gl_MultiTexCoord1.xy;
vec4 fvObjectPosition = gl_ModelViewMatrix * gl_Vertex;
vec3 fvViewDirection = -fvObjectPosition.xyz;
vec3 fvNormal = gl_NormalMatrix * gl_Normal;
vec3 fvTangent = -vec3( abs( gl_Normal.y ) + abs( gl_Normal.z ), abs( gl_Normal.x ), 0 );
vec3 fvBinormal = cross( fvTangent, gl_Normal );
fvTangent = gl_NormalMatrix * cross( fvBinormal, gl_Normal );
fvBinormal = gl_NormalMatrix * fvBinormal;
ViewDirection.x = dot( fvTangent, fvViewDirection );
ViewDirection.y = dot( fvBinormal, fvViewDirection );
ViewDirection.z = dot( fvNormal, fvViewDirection );
}
Code: Select all
uniform vec4 fvAmbient;
uniform vec4 fvLight1Color;
uniform float fSpecularPower;
uniform float fSpecularStrength;
uniform sampler2D baseMap;
uniform sampler2D lightMap;
uniform sampler2D bumpMap;
varying vec2 Texcoord;
varying vec2 Texcoord2;
varying vec3 ViewDirection;
void main( void )
{
vec3 normal = normalize( texture2D( bumpMap, Texcoord.xy ).xyz * 2.0 - 1.0 );
vec3 camera_dir = normalize( ViewDirection );
vec4 base = texture2D( baseMap, Texcoord.xy );
gl_FragColor = texture2D( lightMap, Texcoord2.xy ) * ( base + pow( clamp( dot( reflect( -camera_dir, normal ),camera_dir ), 0.0, 1.0 ), fSpecularPower ) * fSpecularStrength );
}