# vertex shaders - oFog register, clamping

This topic is 5399 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))
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?

##### Share on other sites
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 ;)

• 18
• 29
• 11
• 21
• 16