2
\$\begingroup\$

I am working on a deferred rendering engine and just finished skeletal animation in the vertex shader, but soon realized that this was only updating the rendered geometry and not the shadows, as the animation was only done in the VS of the deferred rendering step, and not in the VS of each light.

I assume this means I should just calculate the animation on the cpu, as otherwise it will be done #oflights + 1 times in the gpu, which seems like a huge waste of cycles.

Is this how it is typically done?

Edit: As a note, I am currently implementing this in OpenGL

\$\endgroup\$
  • \$\begingroup\$ GPU's are much better at matrix multiplication than CPU's. It shouldn't be a problem to do those multiplications several times. Doing thousands of Matrix multiplications on the CPU is not viable. You should also consider that you should cull a lot of geometry for the shadow passes. Most objects won't be in the influence-sphere of more than 2-3 lights. \$\endgroup\$ – LukeG Mar 23 '16 at 14:23
  • \$\begingroup\$ I am doing culling, so the number of lights will most likely be limited. I am using dual quaternion representation for rotation/translation information and then changing it to a matrix within the shader. If I were to go this route, I would image I would need to do that conversion first \$\endgroup\$ – user1958698 Mar 23 '16 at 15:34
  • \$\begingroup\$ Just write a single render function per specific type of object, this way you can call it regardless of rendering to the screen or into a shadowmap. \$\endgroup\$ – Yattabyte Mar 23 '16 at 15:39
2
\$\begingroup\$

If you are working with DirectX 10 or higher, you can do stream-output. The Idea is, that you keep a vertex buffer of the unskinned mesh, run it through a stream-output shader which is a vertex shader + geometry shader combo. In that shader you can do your skinning, and stream it out to an other Buffer, which you can bind like a regular vertex buffer later. See MSDN

You can also stream out in OpenGL, though I am not familiar with that yet. From the documentation it seems that you can use that feature since the 4.0 version. OpenGL Output streams

\$\endgroup\$
  • \$\begingroup\$ Apologies, I should have noted this is currently in OpenGL, and plan to implement DirectX support down the road. I want to make a broad based solution though, so I am looking to solve this issue generically. I have edited my post to represent this is OpenGL \$\endgroup\$ – user1958698 Mar 23 '16 at 15:38
  • \$\begingroup\$ OpenGL also has that, please see my updated answer. \$\endgroup\$ – János Turánszki Mar 23 '16 at 18:28
0
\$\begingroup\$

Just write a single render function per specific type of object, this way you can call the object's render function regardless of where you are rendering to, such as the screen or a shadowmap.

As others have said, you should pass all your matrices to the shader and do the math there. Since you have 2 different rendering operations (standard model rendering, and shadow map rendering), you will need to make sure you use the right bone transformations in both shaders.

This tutorial may be of help: http://ogldev.atspace.co.uk/www/tutorial38/tutorial38.html

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.