I'm adding a rain effect in my pipeline in forward mode. I'm rendering a reflection map used to mirror the scene on a "wet" ground.

I have raindrops rendered as circles with an animated normalmap and use this to distord the reflection map in xz direction based on a global directional light. Quite simple and easy.

Now I want to add an elongation distortion as we usually see for instance with car lights. I don't know where to start for this calculation. I have a couple of ideas in mind.

One is to use the alpha channel of the reflection map to store some deepness information on the rendered pixel. This is possible because I have a fading effect of the reflection that disappears for distance to the mirror plane > 64. So a 8 bits channel would be sufficient to store this relative distance. Then the deepness information could be compared to the current ground height and used to resample the map at another y location. But two texture reads.

The other idea is to initially elongate the objects when they are rendered to the reflection map. So we need here some scale matrix but in a way that it scales with the mirror plane height as the reference elongation, I mean elongation is not in the [-y, h,+y] but in the [h,+y] range, where h is the distance of the object position relative to the mirror plane. (I hope its clear). The position of the object can be volume centered or volume.min.y relative (for my skinned characters).

A third solution is to use the reflect function to deviate the pixel offset but I did not see how to proceed in forward mode.

Alternatively other probably more general solutions are welcome.


1 Answer 1


As expected the elongation on various horizontal plane can result from concatenation of matrices. given R the amount of elongation, H the height of a reflexion plane, and P the reflexion matrix for this plane:

PSTMat = P*XMMatrixScaling(1, R, 1)*XMMatrixTranslation(0, H*(1 - R), 0);

then concatenate PSTMat to the WorldMat of the object and the Scene ViewProj and use this during the reflexion map generation. In my shaders a fading effect is also added to vanish the object with the height.

for objects O GlobalMat = WorldMat*PSTMat*ViewProj;

A couple of screenshots in the figure show the result for A) R=1, B) R=2 qnd C) R=0.5. The rain comes from a simplified version of the NVidia rain demo. When used the reflexion map texcoords are "distorded" to give the ripples with an animated ripple normalmap and some random offset with a noisy normalmap to simulate the impacts of drops.

enter image description here


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .