home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
GameStar 2005 April
/
Gamestar_72_2005-04_dvd.iso
/
Dema
/
Liquidator
/
Liquidator.tma
/
data
/
renderer
/
vertexlights.fx
< prev
next >
Wrap
Text File
|
2004-09-28
|
3KB
|
90 lines
//--------------------------------------------------------------------------
// TMShaders
// Copyright (c) 2002 by Tools-Media Corp., All Right Reserved.
// Programmer: Tima Tcvetkov
//
// vertexlights.fx
// Vertex Shaders for vertex lighting
//--------------------------------------------------------------------------
#ifndef __VERTEX_LIGHTS_FX__
#define __VERTEX_LIGHTS_FX__
void CalculateCubeLighting(){
#ifdef __USE_LOOPS__ // we use loops and coditinals for VS20 and higher
if( constBCubeLight ){
#endif
int3 Sample = ( g_fWorldNormal < 0.0f );
float3 Scale = g_fWorldNormal * g_fWorldNormal;
float3 c1 = vecCubeColors[Sample.x + 0] * Scale.x;
float3 c2 = vecCubeColors[Sample.y + 2] * Scale.y;
float3 c3 = vecCubeColors[Sample.z + 4] * Scale.z;
g_fVertexLightColor += (c1 + c2 + c3);
#ifdef __USE_LOOPS__ // we use loops coditinals for VS20 and higher
}
#endif
}
void CopyVertexLightColorTo( uniform bool bColorReg0 ){
if( bColorReg0 ){
g_fColor0.xyz += g_fVertexLightColor;
}
else{
g_fColor1.xyz += g_fVertexLightColor;
}
}
void AddAmbient2Diffuse(){
g_fVertexLightColor += vecAmbient;
}
void CalculatePointLightColorAttenuation( uniform int uiNumLights, float fAngleDot, float fAttenuation ){
float fAngleDotClamped = max(fAngleDot,0.0f) * fAttenuation;
g_fVertexLightColor += vecPointLightColor[uiNumLights] * fAngleDotClamped;
}
void CalculatePointLightSpecularColorAttenuation( uniform int uiNumLights, float3 Vertex2PointLight, float fAngleDot, float fAttenuation ){
float fAngleDotClamped = max(fAngleDot,0.0) * fAttenuation;
float3 fVertex2Eye = normalize((float3)-g_fWorldViewVertexPosition);
float3 fHalf = normalize(Vertex2PointLight + fVertex2Eye);
float4 fColor = lit(fAngleDot,dot(fHalf,g_fWorldViewNormal),vecPointLightColor[uiNumLights].w);
g_fVertexLightColor += (vecPointLightColor[uiNumLights] * fColor.y ) * fColor.z;
}
#ifndef __USE_LOOPS__ // we use loops for VS20 and higher
void CalculatePointLightVector( uniform int uiNumLights, uniform bool bSpecularPass ){
for( int i =0; i<uiNumLights; i++ ){
#else // old VS11 school
void CalculatePointLightVector( uniform bool bSpecularPass ){
for( int i =0; i<constINumLights; i++ ){
#endif
/*
float3 fVertex2Light = vecPointLightPosition[i] - g_fWorldViewVertexPosition;
float fDot = dot(fVertex2Light,fVertex2Light);
float RevDistance = rsqrt(fDot);
float3 fVertex2LightNormalized = fVertex2Light * RevDistance;
float fAttenuation = 1.0 - ( fDot * RevDistance ) * vecPointLightPosition[i].w;
float fAngle = dot(g_fWorldViewNormal,fVertex2LightNormalized);
*/
float3 fVertex2Light = vecPointLightPosition[i] - g_fWorldViewVertexPosition;
float3 fVertex2LightNormalized = normalize(fVertex2Light);
fVertex2Light = fVertex2Light * vecPointLightPosition[i].w;
float fAttenuation = clamp( 1.0 - dot(fVertex2Light,fVertex2Light),0.0f,1.0f );
float fAngle = dot(g_fWorldViewNormal,fVertex2LightNormalized);
if( bSpecularPass ){
CalculatePointLightSpecularColorAttenuation(i,fVertex2LightNormalized,fAngle,fAttenuation);
}//if
else {
CalculatePointLightColorAttenuation(i,fAngle,fAttenuation);
}//else
}// for
}
#endif //__VERTEX_LIGHTS_FX__