Some experimental cg stuff (not actually used currently)

This commit is contained in:
cholleme 2003-02-03 14:16:17 +00:00
parent 580de5cd15
commit f867791fd3
2 changed files with 88 additions and 0 deletions

42
cg/tangentlight.cg Normal file
View file

@ -0,0 +1,42 @@
/**
* Basic tenebrae vertex program.
* This compiles under the arbvp and vp20 vertex program profiles.
* compile with "-profile vp20 -posinv"
*/
struct appdata {
float4 position : POSITION;
float4 texcoord : TEXCOORD0; //texture coords of color/bump map
float4 normal : NORMAL; //tangent space basis vectors
float4 tangent : TEXCOORD1;
float4 binormal : TEXCOORD2;
};
struct v2f {
float4 HPOS : POSITION;
float4 TEX0 : TEXCOORD0; //color map texture coordinates
float4 TEX1 : TEXCOORD1; //tangent space light vector unnormalized
float4 TEX2 : TEXCOORD2; //bump map texture coordinates
float4 TEX3 : TEXCOORD3; //world space vertex position (for attenuation)
};
v2f main(appdata I,uniform float4x4 objviewproj : _GL_MVP, uniform float4x4 texture_matrix : c0)
{
v2f O;
// transform vertices into projection space using the pre-multiplied matrix
O.HPOS = mul(objviewproj, I.position);
//copy stuff to output
O.TEX0 = I.texcoord;
O.TEX2 = I.texcoord;
//transform into tangent space
O.TEX1.x = dot(I.position,I.tangent);
O.TEX1.y = dot(I.position,I.binormal);
O.TEX1.z = dot(I.position,I.normal);
//transform with texture matrix
O.TEX3 = mul(texture_matrix, I.position);
return O;
} // main

46
cg/tenedot.cg Normal file
View file

@ -0,0 +1,46 @@
/**
* Geforce 4 diffuse bumpmapping program
* This compiles under the fp20 profile.
* compile with "-profile fp20"
*/
struct inputVertex {
float4 lightVec : COLOR0;
float4 texCoord0 : TEXCOORD0;
float4 texCoord1 : TEXCOORD1;
float4 texCoord2 : TEXCOORD2;
float4 texCoord3 : TEXCOORD3;
};
float4 main(inputVertex I, uniform sampler2D colorMap, uniform sampler2D normalMap, uniform samplerCUBE filter, uniform sampler3D atten) : COLOR
{
//normalize light vector (talyor series around 1)
float3 lightVector = 2 * (I.lightVec.xyz - 0.5);
float3 normLight = 1-(lightVector-1)/2;
// Get the normal from normal map lookup
float4 normal = 2 * (tex2D(normalMap, I.texCoord1.xy) - 0.5);
// Lookup the colorMap texture
float4 texColor = tex2D(colorMap, I.texCoord0.xy);
// N dot L
float4 dot_result = saturate(dot(normLight, normal.xyz).xxxx);
//selfshadow term, ok we just do a mul with 8 but the compiler doesn't recognize that
//so we teach it a bit of math :)
float selfShadow = (lightVector.z*4)+(lightVector.z*4);
//Lookup the attenuation factor
float4 attenv = tex3D(atten, I.texCoord2.xyz);
//Lookup the filter color
float3 filterv = texCUBE(filter, I.texCoord3.xyz).xyz;
// Modulate color with N dot L
float4 res;
res.xyz = dot_result.xyz * texColor.xyz * attenv.xyz * filterv.xyz * selfShadow * attenv.xyz * texColor.xyz;
res.w = attenv.w * selfShadow;
return res;
}