vertex shaders - oFog register, clamping

Started by
0 comments, last by nohbdy 19 years, 6 months ago
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?
Advertisement
Well they are just examples... they might do things explicitely just for illustrative purposes... or didn't want to rely on the fact that it gets clamped between 0 and 1 later in the pipeline.

Just another example of the DXSDK being a bad source for anything but reference ;)

This topic is closed to new replies.

Advertisement