Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ; Example PICA200 vertex shader
- ; Uniforms
- .fvec projection[4], model[4], view[4]
- .fvec lightVec, lightHalfVec, lightClr, material[4]
- .alias mat_amb material[0]
- .alias mat_dif material[1]
- .alias mat_spe material[2]
- .alias mat_emi material[3]
- ; Constants
- .constf myconst(0.0, 1.0, -1.0, -0.5)
- .alias zeros myconst.xxxx ; Vector full of zeros
- .alias ones myconst.yyyy ; Vector full of ones
- ; Outputs
- .out outpos position
- .out outtc0 texcoord0
- .out outclr color
- ; Inputs (defined as aliases for convenience)
- .alias inpos v0
- .alias intex v1
- .alias innrm v2
- .proc main
- ; Force the w component of inpos to be 1.0
- mov r0.xyz, inpos ; mov --> move value inpos to r0.xyz
- mov r0.w, ones
- ; Calculating the MVP (Model View Projection) matrix
- ; r1 = model * inpos
- dp4 r1.x, model[0], r0
- dp4 r1.y, model[1], r0
- dp4 r1.z, model[2], r0
- dp4 r1.w, model[3], r0
- ;
- dp4 r2.x, view[0], r1
- dp4 r2.y, view[1], r1
- dp4 r2.z, view[2], r1
- dp4 r2.w, view[3], r1
- ; outpos = projection * r2
- dp4 outpos.x, projection[0], r2
- dp4 outpos.y, projection[1], r2
- dp4 outpos.z, projection[2], r2
- dp4 outpos.w, projection[3], r2
- ; outtex = intex
- mov outtc0, intex
- ; Transform the normal vector with the modelView matrix
- ; r1 = normalize(modelView * innrm)
- mov r0.xyz, innrm
- mov r0.w, zeros
- dp4 r1.x, model[0], r0
- dp4 r1.y, model[1], r0
- dp4 r1.z, model[2], r0
- mov r1.w, zeros
- dp3 r2, r1, r1 ; r2 = x^2+y^2+z^2 for each component
- rsq r2, r2 ; r2 = 1/sqrt(r2) ''
- mul r1, r2, r1 ; r1 = r1*r2
- ; Calculate the diffuse level (r0.x) and the shininess level (r0.y)
- ; r0.x = max(0, -(lightVec * r1))
- ; r0.y = max(0, (-lightHalfVec[i]) * r1) ^ 2
- dp3 r0.x, lightVec, r1
- add r0.x, zeros, -r0
- dp3 r0.y, -lightHalfVec, r1
- max r0, zeros, r0
- mul r0.y, r0, r0
- ; Accumulate the vertex color in r1, initializing it to the emission color
- mov r1, mat_emi
- ; r1 += specularColor * lightClr * shininessLevel
- mul r2, lightClr, r0.yyyy
- mad r1, r2, mat_spe, r1
- ; r1 += diffuseColor * lightClr * diffuseLevel
- mul r2, lightClr, r0.xxxx
- mad r1, r2, mat_dif, r1
- ; r1 += ambientColor * lightClr
- mov r2, lightClr
- mad r1, r2, mat_amb, r1
- ; outclr = clamp r1 to [0,1]
- min outclr, ones, r1
- ; We're finished
- end
- .end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement