Added fragment programs for rendering eclipse shadows.

ver1_5_1
Chris Laurel 2004-03-12 08:34:22 +00:00
parent efabdafcf6
commit 32ff3ed3b9
7 changed files with 134 additions and 1 deletions

View File

@ -0,0 +1,29 @@
!!FP1.0
# Eclipse shadow shader--this shader computes a black circle centered
# at texcoord (0.5, 0.5) and multiplies this by texture zero and the
# diffuse color.
# Parameters:
# p[5] - ambient light color
# p[20] - shadow umbra/penumbra parameters (x = scale, y = bias)
# Compute the square of the distance from the center of the shadow
SUB R0, f[TEX0], { 0.5, 0.5, 0, 0 };
DP3 R1.w, R0, R0;
# Scale and bias the squared distance to get the right shadow umbra
# and penumbra sizes.
MAD_SAT R1.x, R1.w, p[20].x, p[20].y;
#MUL R0.xyz, R1.x, 2.0;
POW R0.xyz, R1.x, 0.5;
#TEX R0.xyz, R1.x, TEX0, 2D;
# Add the ambient light
ADDX_SAT R0.xyz, R0, p[5];
# Output it
MOVX o[COLR], R0;
END

View File

@ -0,0 +1,34 @@
!!FP1.0
# Eclipse shadow shader--this shader computes a black circle centered
# at texcoord (0.5, 0.5) and multiplies this by texture zero and the
# diffuse color.
# Parameters:
# p[5] - ambient light color
# p[20] - shadow umbra/penumbra parameters (x = scale, y = bias)
# p[21] - shadow umbra/penumbra parameters (x = scale, y = bias)
SUB R0, f[TEX0], { 0.5, 0.5, 0, 0 };
DP3 R1.x, R0, R0;
MAD_SAT R1.x, R1.x, p[20].x, p[20].y;
#POW R1.x, R1.x, 0.5;
RSQ R1.x, R1.x;
RCP R1.x, R1.x;
SUB R0, f[TEX1], { 0.5, 0.5, 0, 0 };
DP3 R1.y, R0, R0;
MAD_SAT R1.y, R1.y, p[21].x, p[21].y;
#POW R1.y, R1.y, 0.5;
RSQ R1.y, R1.y;
RCP R1.y, R1.y;
MINX R0.xyz, R1.x, R1.y;
# Add the ambient light
ADDX_SAT R0.xyz, R0, p[5];
# Output it
MOVX o[COLR], R0;
END

View File

@ -0,0 +1,45 @@
!!ARBvp1.0
# Vertex program use for applying up to four shadow textures. 2D texture
# coordinates are generated from vertex coordinates using the s and t
# texture planes.
ATTRIB iPos = vertex.position;
ATTRIB iTex0 = vertex.texcoord[0];
PARAM mvp[4] = { state.matrix.mvp };
PARAM lightDir = program.env[0];
PARAM texgen_s0 = program.env[10];
PARAM texgen_t0 = program.env[11];
PARAM texgen_s1 = program.env[12];
PARAM texgen_t1 = program.env[13];
PARAM texgen_s2 = program.env[14];
PARAM texgen_t2 = program.env[15];
PARAM texgen_s3 = program.env[16];
PARAM texgen_t3 = program.env[17];
PARAM halfW = { 0, 0, 0, 0.5 };
OUTPUT oPos = result.position;
OUTPUT oTex0 = result.texcoord[0];
OUTPUT oTex1 = result.texcoord[1];
OUTPUT oTex2 = result.texcoord[2];
OUTPUT oTex3 = result.texcoord[3];
TEMP t;
# Transform the vertex by the modelview matrix
DP4 oPos.x, mvp[0], iPos;
DP4 oPos.y, mvp[1], iPos;
DP4 oPos.z, mvp[2], iPos;
DP4 oPos.w, mvp[3], iPos;
# Generate texture coordinates
DP4 oTex0.x, texgen_s0, iPos;
DP4 oTex0.y, texgen_t0, iPos;
DP4 oTex1.x, texgen_s1, iPos;
DP4 oTex1.y, texgen_t1, iPos;
DP4 oTex2.x, texgen_s2, iPos;
DP4 oTex2.y, texgen_t2, iPos;
DP4 oTex3.x, texgen_s3, iPos;
DP4 oTex3.y, texgen_t3, iPos;
END

View File

@ -18,6 +18,8 @@ using namespace std;
unsigned int fp::sphereShadowOnRings = 0;
unsigned int fp::eclipseShadow1 = 0;
unsigned int fp::eclipseShadow2 = 0;
class FragmentProcessorNV : public FragmentProcessor
@ -118,6 +120,10 @@ FragmentProcessor* fp::initNV()
cout << "Initializing NV fragment programs . . .\n";
if (!LoadNvFragmentProgram("shaders/shadow_on_rings_nv.fp", sphereShadowOnRings))
return NULL;
if (!LoadNvFragmentProgram("shaders/eclipse1_nv.fp", eclipseShadow1))
return NULL;
if (!LoadNvFragmentProgram("shaders/eclipse2_nv.fp", eclipseShadow2))
return NULL;
cout << "All NV fragment programs loaded successfully.\n";
return new FragmentProcessorNV();

View File

@ -41,9 +41,12 @@ namespace fp
TexGen_S = 8,
TexGen_T = 9,
ShadowParams0 = 20,
ShadowParams1 = 21,
};
extern unsigned int sphereShadowOnRings;
extern unsigned int eclipseShadow1;
extern unsigned int eclipseShadow2;
};

View File

@ -23,6 +23,7 @@ unsigned int vp::diffuseHaze = 0;
unsigned int vp::diffuseBump = 0;
unsigned int vp::diffuseBumpHaze = 0;
unsigned int vp::shadowTexture = 0;
unsigned int vp::multiShadow = 0;
unsigned int vp::everything = 0;
unsigned int vp::diffuseTexOffset = 0;
unsigned int vp::ringIllum = 0;
@ -237,6 +238,8 @@ VertexProcessor* vp::initARB()
return NULL;
if (!LoadARBVertexProgram("shaders/shadowtex_arb.vp", shadowTexture))
return NULL;
if (!LoadARBVertexProgram("shaders/multishadow_arb.vp", multiShadow))
return NULL;
if (!LoadARBVertexProgram("shaders/diffuse_texoff_arb.vp", diffuseTexOffset))
return NULL;
if (!LoadARBVertexProgram("shaders/rings_arb.vp", ringIllum))
@ -363,7 +366,13 @@ static unsigned int parameterMappings[] =
90, // Constant0 - relevant for NV_vertex_program only
0, // Unused
41, // TexGen_S,
42, // TexGen_Y
42, // TexGen_T
0, // TexGen_S2
0, // TexGen_T2
0, // TexGen_S3
0, // TexGen_T3
0, // TexGen_S4
0, // TexGen_T4
};
VertexProcessorNV::VertexProcessorNV()

View File

@ -41,6 +41,12 @@ namespace vp
Constant0 = 8,
TexGen_S = 10,
TexGen_T = 11,
TexGen_S2 = 12,
TexGen_T2 = 13,
TexGen_S3 = 14,
TexGen_T3 = 15,
TexGen_S4 = 16,
TexGen_T4 = 17,
};
extern unsigned int specular;
@ -50,6 +56,7 @@ namespace vp
extern unsigned int diffuseBumpHaze;
extern unsigned int everything;
extern unsigned int shadowTexture;
extern unsigned int multiShadow;
extern unsigned int diffuseTexOffset;
extern unsigned int ringIllum;
extern unsigned int ringShadow;