pixel.psd
资源名称:Direct3D.rar [点击查看]
上传用户:junlon
上传日期:2022-01-05
资源大小:39075k
文件大小:1k
源码类别:
DirextX编程
开发平台:
Visual C++
- // pixel shader file: pixel.vsd
- ps_2_x
- // c0 hold the light position
- // c1.xyz hold the light direction, while c1.w hold the light area, c1.xyz should be normalized, c1.w larger,
- dcl v0 // ambient diffuse color
- dcl_2d s0 // sampler
- dcl t0 // texture0
- dcl t1 // texture1, in fact it hold the position value of the pixel, transformed by world matrix
- def c10, 0.0, 0.0, 0.0, 0.0
- def c11, 0.5, 0.5, 0.5, 1.0
- texld r0, t0, s0 // sample the tex color
- ////////calculate the diffuse color from the spotlight/////////////////////////////
- sub r4, t1, c0 // get the vector from light to pixel
- mov r4.w, c10.x // set the 4th component of r4 to 0
- nrm r5, r4 // normalize the vector
- dp4 r5.w, r5, c1 // don't care the value of c1.w, r5.w is equal to 0
- // if( r5.w > c1.w )
- // lit the pixel using spotlight
- // else
- // doesnt lit the pixel
- sub r6, c1, r5 // if (r5.w > c1.w) then lit the pixel, r6.w < 0
- mov r6.x, r6.w
- mov r6.y, r6.w
- mov r6.z, r6.w
- mov r8, c10
- mov r9, c11
- cmp r7, r6, r8, r9 //
- add r1, v0, r7 // increase the diffuse color
- min r1.w, r1.w, c11.x // clamp the alpha value to 1.0
- //////////////////////////////////////////////////////////////////////////////////
- mul r2, r0, r1 // dot product the tex and the diffuse
- mov oC0, r2 // output the pixel color