grass_wave_refract.txt

(2 KB) Pobierz
; DESCRIPTION:
; Vertex shader used to render grasses with waving manipulation and consider refract depth fog
; this shader does below works:
; # vertex transform
; # output texture coordinates

vs.1.1

;------------------------------------------------------------------------------
; v0 	  = position in world space
; v1	  = index, w1, w2
; v2 	  = texture coordinates
;------------------------------------------------------------------------------

;------------------------------------------------------------------------------
; Constants specified by the app;
; c0      = (1.0, 0.0, 0.0, 1.0f/vSightRange*vSightRange)
; c1-c4	  = view matrix * projection matrix
; c5-c8   = light map texture generate matrix
; c9	  = camera's position in world space
; c10-    = wind offset index array
; c91     = (1.0, WaterHeight, fogDensity, fogOffset)
;------------------------------------------------------------------------------

;------------------------------------------------------------------------------
; oPos	  = Output position
; oD0	  = Diffuse
; oT0	  = base texture coordinates
; oT1	  = light map texture coords.
; oT2	  = light map night texture coords.
; oFog    = fog value
;------------------------------------------------------------------------------

; Transfrom position from world space to cuboid space and output it
mov a0.x, v1.x
mul r1, v1.y, c[10+a0.x]
add r0, v0, r1
m4x4 oPos, r0, c1
m4x4 r1, r0, c5
mov oT1, r1
mov oT2, r1

; calculate the fog
sub r1.y, c91.y, r0.y
; calculate fog
sub r0, c9, v0
dp3 r0.w, r0, r0
rsq r0.w, r0.w
mul r0.xyz, r0, r0.w
rcp r0.y, r0.y

mul r1.z, r1.y, r0.y
mul r1.z, r1.z, c91.z		// density * distance
;mul r1.x, r1.z, r1.z		// power of 2
;mul r1.z, r1.x, r1.z		// power of 3
exp r1.z, r1.z
rcp r1.z, r1.z
add oFog, r1.z, c91.w

; now calculate the alpha value according to the distance to camera
sub r1, v0, c9		;to camera vector
dp3 r0, r1, r1		;distance square to camera
mul r1.w, r0.w, c0.w;   ;0~1 from camera to sight range
sub r1.w, c0.x, r1.w    ;1~0 from camera to sight range
max oD0.w, r1.w, c0.y   ;clamp if < 0

; Copy texture coordinate
mov oT0, v2




Zgłoś jeśli naruszono regulamin