Skip to content

Instantly share code, notes, and snippets.

@Triang3l
Last active November 18, 2018 10:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Triang3l/537bbfa37a79755457f0b091aafe0f25 to your computer and use it in GitHub Desktop.
Save Triang3l/537bbfa37a79755457f0b091aafe0f25 to your computer and use it in GitHub Desktop.
ps_3_0
dcl_cube s0
dcl_2d s1
dcl_2d s2
dcl_2d s3
dcl_2d s4
dcl_2d s5
//dcl_2d s6
dcl_texcoord0 v0
dcl_texcoord1 v1
dcl_texcoord2 v2
dcl_texcoord3 v3
dcl_texcoord4 v4
dcl_texcoord5 v5
dcl_texcoord6 v6
dcl_color v7
mov r11, CONSTANTS_BASE_PLUS_0
texld r3, v0, s0 // r3 = toLight
mad r3, r3, r11.yyyy, r11.xxxx //scaleTwo, subOne
mov r4, v0
//nrm r3, v0
// normalize the direction to the viewer
//dp3 r4, v6, v6 // r4 = toViewer
//rsq r4, r4.x
//mul r4, r4.x,v6
nrm r4, v6
// load the filtered normal map
texld r5, v1, s1 // r5 = localNormal
mov r5.x, r5.a
mad r5.xyz, r5, r11.yyyy, r11.xxxx //scaleTwo, subOne
// normalize the bumpmap
// dp3 r1, r5,r5
// rsq r1, r1.x
// mul r5.xyz, r5, r1
nrm r1, r5
mov r5, r1
// diffuse dot product
dp3 r6, r3, r5 // r6 = light
// modulate by the light projection
texldp r1, v3, s3
mul r6, r6, r1
// modulate by the light falloff
texldp r1, v2, s2
mul r6, r6, r1
// modulate by the diffuse map and constant diffuse factor
texld r1, v4, s4
mul r7, r1, PROGRAM_ENV_BASE_PLUS_0 // r7 = color
// calculate the half angle vector and normalize
add r8, r3, r4 // r8 = halfAngle
// dp3 r1, r8, r8
// rsq r1, r1.x
// mul r8.xyz, r8, r1
nrm r1, r8
mov r8, r1
// calculate specular
dp3 r1, r8, r5
// perform a dependent table read for the specular falloff
// use power instead of table
pow r1, r1.x, PROGRAM_ENV_BASE_PLUS_2.x
mul r1, r1, PROGRAM_ENV_BASE_PLUS_2.y
// modulate by the constant specular factor
mul r1, r1, PROGRAM_ENV_BASE_PLUS_1
// modulate by the specular map * 2
texld r2, v5, s5
add r2, r2, r2
mad r7, r1, r2, r7
mul r7, r6, r7
// modify by the vertex color
mul r0, r7, v7
mov oC0, r0
/*
mov r11, CONSTANTS_BASE_PLUS_0
//texld r3, t0, s0 // r3 = toLight
mov r4, t0
nrm r3, r4
mad r3, r3, r11.yyyy, r11.xxxx //scaleTwo, subOne
// normalize the direction to the viewer
dp3 r4, t6, t6 // r4 = toViewer
rsq r4, r4.x
mul r4, r4.x,t6
// load the filtered normal map
texld r5, t1, s1 // r5 = localNormal
mov r5.x, r5.a
mad r5.xyz, r5, r11.yyyy, r11.xxxx //scaleTwo, subOne
// normalize the bumpmap
dp3 r1, r5,r5
rsq r1, r1.x
mul r5.xyz, r5, r1
// diffuse dot product
dp3 r6, r3, r5 // r6 = light
// modulate by the light projection
texldp r1, t3, s3
mul r6, r6, r1
// modulate by the light falloff
texldp r1, t2, s2
mul r6, r6, r1
// modulate by the diffuse map and constant diffuse factor
texld r1, t4, s4
mul r7, r1, PROGRAM_ENV_BASE_PLUS_0 // r7 = color
// calculate the half angle vector and normalize
add r8, r3, r4 // r8 = halfAngle
dp3 r1, r8, r8
rsq r1, r1.x
mul r8.xyz, r8, r1
// calculate specular
dp3_sat r1, r8, r5
// perform a dependent table read for the specular falloff
// use power instead of table
pow r1, r1.x, PROGRAM_ENV_BASE_PLUS_2.x
mul r1, r1, PROGRAM_ENV_BASE_PLUS_2.y
// modulate by the constant specular factor
mul r1, r1, PROGRAM_ENV_BASE_PLUS_1
// modulate by the specular map * 2
texld r2, t5, s5
add r2, r2, r2
mad r7, r1, r2, r7
mul r7, r6, r7
// modify by the vertex color
mul r0, r7, FRAGMENT_COLOR
mov oC0, r0
*/
/*
!!ARBfp1.0
OPTION ARB_precision_hint_fastest;
# texture 0 is the cube map
# texture 1 is the per-surface bump map
# texture 2 is the light falloff texture
# texture 3 is the light projection texture
# texture 4 is the per-surface diffuse map
# texture 5 is the per-surface specular map
# texture 6 is the specular lookup table
# env[0] is the diffuse modifier
# env[1] is the specular modifier
TEMP toLight, light, toViewer, halfAngle, color, R1, R2, localNormal;
PARAM subOne = { -1, -1, -1, -1 };
PARAM scaleTwo = { 2, 2, 2, 2 };
#
# the amount of light contacting the fragment is the
# product of the two light projections and the surface
# bump mapping
#
# normalize the direction to the light
#DP3 toLight, fragment.texcoord[0],fragment.texcoord[0];
#RSQ toLight, toLight.x;
#MUL toLight, toLight.x, fragment.texcoord[0];
TEX toLight, fragment.texcoord[0], texture[0], CUBE;
MAD toLight, toLight, scaleTwo, subOne;
# normalize the direction to the viewer
DP3 toViewer, fragment.texcoord[6],fragment.texcoord[6];
RSQ toViewer, toViewer.x;
MUL toViewer, toViewer.x, fragment.texcoord[6];
#TEX toViewer, fragment.texcoord[6], texture[0], CUBE;
#MAD toViewer, toViewer, scaleTwo, subOne;
# load the filtered normal map
TEX localNormal, fragment.texcoord[1], texture[1], 2D;
MOV localNormal.x, localNormal.a;
MAD localNormal.xyz, localNormal, scaleTwo, subOne;
# normalize the bumpmap
DP3 R1, localNormal,localNormal;
RSQ R1, R1.x;
MUL localNormal.xyz, localNormal, R1;
# diffuse dot product
DP3 light, toLight, localNormal;
# modulate by the light projection
TXP R1, fragment.texcoord[3], texture[3], 2D;
MUL light, light, R1;
# modulate by the light falloff
TXP R1, fragment.texcoord[2], texture[2], 2D;
MUL light, light, R1;
# modulate by the diffuse map and constant diffuse factor
TEX R1, fragment.texcoord[4], texture[4], 2D;
MUL color, R1, program.env[0];
# calculate the half angle vector and normalize
ADD halfAngle, toLight, toViewer;
DP3 R1, halfAngle, halfAngle;
RSQ R1, R1.x;
MUL halfAngle.xyz, halfAngle, R1;
# calculate specular
DP3_SAT R1, halfAngle, localNormal;
# perform a dependent table read for the specular falloff
#TEX R1, R1, texture[6], 2D;
# use power instead of table
POW R1, R1.x, program.env[2].x;
MUL R1, R1, program.env[2].y;
# modulate by the constant specular factor
MUL R1, R1, program.env[1];
# modulate by the specular map * 2
TEX R2, fragment.texcoord[5], texture[5], 2D;
ADD R2, R2, R2;
MAD color, R1, R2, color;
MUL color, light, color;
# modify by the vertex color
MUL result.color, color, fragment.color;
# this should be better on future hardware, but current drivers make it slower
#MUL result.color.xyz, color, fragment.color;
END
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment