Ok, hab mir Mal n andres Beispiel angeschaut und da wird tatsächlich nicht ASM verwendet. Aber im D3D-Shader für "Atmospheric" steht dieser Code hier:
Code: Alles auswählen
; Scattering Vertex shader
; (c) Preetham ATI Research, 2002.
; V View direction
; L Sun direction
; Theta Scattering angle
; s Distance
; E Total extinction (including reflectance).
;
vs.2.0
dcl_position v0
dcl_texcoord v2
; Transformation.
m4x4 oPos, v0, c0 ; Transform position to viewport
; Texture Coordinates.
; 0 Normal/Horizon map
; 1 Terrain texture
; 2 Cloud texture
mov oT0.xy, v2
mov oT1.xy, v2
mov r1, c32
mad oT2.xy, r1, c33, v2
mov r0, c22 ; get eye position in eye space (origin)
m4x4 r1, r0, c8 ; eye position in model space
sub r1, v0, r1 ; V = vertex eye
dp3 r1.w, r1, r1 ; normalize V
rsq r1.w, r1.w ;
mul r1, r1, r1.w ;
; calculate sun's position in sky
mov r8.x, c19.x
mul r8.x, r8.x, c32.x
frc r8.xy, r8.x
sub r8.x, r8.x, c31.z
mul r8.x, r8.x, c31.w
add r8.x, r8.x, c17.x
max r8.x, r8.x, -c31.x
min r8.x, r8.x, c31.x
; calculate sun direction
; r2 = [cos(theta), sin(theta)] of sun's rotation from east to west
mov r2.x, r8.x
max r2.y, r2.x, -r2.x
sub r2.y, c31.x, r2.y
; rotate sun from east to west depending on east_to_west value [-1,1]
; y' = y
mov r5, c18
; x' = z sin(theta)
mul r5.x, c18.z, r2.y
; x' = (z sin(theta)) + (x cos(theta))
mad r5.x, c18.x, r2.x, r5.x
; z' = (x sin(theta))
mul r5.z, c18.x, r2.y
; z' = (z cos(theta)) (x sin(theta))
mad r5.z, c18.z, r2.x, -r5.z
; normalize sun direction vector
dp3 r5.w, r5, r5
rsq r5.w, r5.w
mul r5.xyz, r5.xyz, -r5.w
; scale and bias to [0,1]
add r7, r5, c31.xxx
mul oT5, r7, c31.zzz
; Angle (theta) between sun direction (L) and view direction (V).
dp3 r0.x, r1, r5 ; r0.x = [cos(theta)] = V.L
mad r0.y, r0.x, r0.x, c31.x ; r0.y = [1+cos^2(theta)] = Phase1(theta)
; Distance (s)
m4x4 r1, v0, c4 ; r1.z = s
mov r0.z, r1.z ; store in r0.z for future use.
; Terms used in the scattering equation.
; r0 = [cos(theta), 1+cos^2(theta), s]
; at noon we want no shadows
dp3 r10.x, r5, c14
add r10.x, r10.x, c31.x
mul r10.x, r10.x, c31.z ; sun angle for shadowing
sub oT3, c31.x, r10.x
; Approximate theta r10.x = theta / (pi/2)
mov r10, r5
dp3 r10.x, r10, c14
max r10.x, r10.x, -r10.x ; get abs of cos(theta)
//add r10.x, r10.x, c31.x ; scale and bias cos(theta) to [0,1] range
//mul r10.x, r10.x, c31.z ; ...
mov oT4.xy, r10.x ; ;
; Extinction term E
mov r1, c26.xxx
add r1, r1, c26.yyy ; beta_1 + beta_2
mul r1, r1, -r0.z ; -(beta_1+beta_2) * s
mul r1, r1, c31.y ; -(beta_1+beta_2) * s * log_2 e
exp r1.x, r1.x ; r1 = e^(-(beta_1 + beta_2) * s) = E1
exp r1.y, r1.y
exp r1.z, r1.z
; Apply Reflectance to E to get total net effective E
mul r3, r1, c13 ;r3 = E (Total extinction)
; Phase2(theta) = (1-g^2)/(1+g-2g*cos(theta))^(3/2)
; theta is 180 actual theta (this corrects for sign)
; c[28] = [(1-g)^2, 1+g^2, 2g]
mov r8.xyz, c28.xxx
sub r8.x, c31.x, r8.x
mul r8.xy, r8.xy, r8.xy ; r8.xy = [(1-g)^2, g^2]
add r8.y, r8.y, c31.x ; r8.y = 1+g^2
mul r8.z, r8.z, c31.w // 2g
mad r4.x, r8.z, r0.x, r8.y;
rsq r4.x, r4.x
mul r4.y, r4.x, r4.x
mul r4.x, r4.y, r4.x;
mul r0.w, r4.x, r8.x ; r0.w = Phase2(theta)
; Inscattering (I) = (Beta'_1 * Phase_1(theta) + Beta'_2 * Phase_2(theta)) *
; [1-exp(-Beta_1*s).exp(-Beta_2*s)] / (Beta_1 + Beta_2)
mul r4, c26.xxx, r0.y
mul r5, c26.yyy, r0.w
sub r6, c31.x, r1
mov r1, c26.xxx
add r1, r1, c26.yyy ; beta_1 + beta_2
mov r7, r1
add r4, r4, r5
mul r4, r4, r6
rcp r1.x, r1.x
mul r4, r4, r1.xxx ; r4 = I (inscattering)
; Apply Inscattering contribution factors.
mul r4, r4, c25.y
; Scale with Sun color & intesity.
mul r4, r4, c15
mul r4, r4, c15.w
mul r3, r3, c15
mul r3, r3, c15.w
; Outputs.
mov oD0, r3 ; Extinction
mov oD1, r4 ; Inscattering