• 13
• 18
• 19
• 27
• 9

# vertex shaders - oFog register, clamping

This topic is 4910 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Look at this piece of code from "dolphintween.vsh", a DXSDK example:
;------------------------------------------------------------------------------
; Fog calculation
;------------------------------------------------------------------------------

; compute fog factor f = (fog_end - dist)*(1/(fog_end-fog_start))
add r0.x, -r9.z, c23.y
mul r0.x, r0.x, c23.z
max r0.x, r0.x, c0.x       ; clamp fog to > 0.0
min oFog, r0.x, c1.x     ; clamp fog to < 1.0

They are clamping the value passed to oFog. Now read this text from the DX Documentation: "Fog Register - oFog The output fog value registers. [...] Values are clamped between zero and one before passing to the rasterizer." So there's no need to clamp the value between 0 and 1 because it is automatically done anyway! The example is wasting two instructions. And it's not the only one: dolphintween2.vsh, seafloor.vsh and seafloor2.vsh are doing the same thing. This sounds very strange to me, so, is there something I'm missing?