50 lines
1.6 KiB
Plaintext
50 lines
1.6 KiB
Plaintext
!!VP1.0
|
|
|
|
# Vertex program used for applying ring shadow textures. Ray cast from a
|
|
# point on the object in the direction of the sun (assumed to be an
|
|
# infinitely distant light source here.) Compute the intersection of
|
|
# the ray with the ring plane. Then use the distance of the intersection
|
|
# point from the planet's center to compute a texture coordinate. Vertex
|
|
# programs are cool!
|
|
#
|
|
# c[0]..c[3] contains the concatenation of the modelview and projection
|
|
# matrices.
|
|
# c[16] contains the light direction in object space
|
|
# c[20] contains the color
|
|
# c[41] is [ inner ring radius, 1/ring width, 0, 0.5 ]
|
|
# c[42] is 1 / sunDir.y
|
|
# c[43] contains scaling vector [1 1-oblateness 1 0]
|
|
|
|
# Transform the vertex by the modelview matrix
|
|
DP4 o[HPOS].x, c[0], v[OPOS];
|
|
DP4 o[HPOS].y, c[1], v[OPOS];
|
|
DP4 o[HPOS].z, c[2], v[OPOS];
|
|
DP4 o[HPOS].w, c[3], v[OPOS];
|
|
|
|
# Scale by oblateness . . . off for now because it makes Saturn look
|
|
# weird, even though I think it's more realistic.
|
|
# MUL R2, v[OPOS], c[43];
|
|
MOV R2, v[OPOS];
|
|
|
|
MUL R1.x, R2.y, -c[42].x;
|
|
MAX R1.x, R1.x, c[42].w; # Clamp to zero--don't trace both directions
|
|
MAD R0, R1.x, c[16], R2;
|
|
|
|
# Compute the distance from the center. The s coordinate is the distance
|
|
# from the center, modified by the ring width and inner radius
|
|
DP3 R0.x, R0, R0;
|
|
RSQ R0.x, R0.x;
|
|
RCP R0.x, R0.x;
|
|
|
|
# Scale and bias by ring width and radius
|
|
MUL R0.x, R0.x, c[41].y;
|
|
ADD R0.x, R0.x, -c[41].x;
|
|
# Now we have our s coordinate . . .
|
|
MOV o[TEX0].x, R0.x;
|
|
# The t coordinate is always 0.5
|
|
MOV o[TEX0].y, c[41].w;
|
|
|
|
MOV o[COL0], c[20];
|
|
|
|
END
|