1
\$\begingroup\$

I need to draw a normal-vector scene and default scene.

enter image description here

enter image description here

I could achieve this my having two programs with different fragment shader to produce the following images. It will require me to draw twice.

//somethinglike
useProgram(normal_vector_rendering_program);
render_bunny();
useProgram(just_default_scene_program);
render_bunny();

However when I am rendering the default scene, I am already passing normal vector information to achieve the lighting.

So it got me curious, can I produce two different scenes with one program(a program that has two color_buffer attaches) and one draw call somehow? I think if such is possible then I am saving lots of computer resource by not having to draw multiple times for different images.

\$\endgroup\$
2
\$\begingroup\$

http://chat.stackexchange.com/transcript/message/30419781#30419781

Bind more than one render target. Output two different colors from the fragment shader. You will of course need a second draw call to draw a fullscreen quad containing the render target you want to show. You can also branch every fragment on a uniform if you really want. Fairly straightforward. Unlikely to be saving you a whole lot of "computing resources" for your bunny model though.

\$\endgroup\$
  • \$\begingroup\$ Just to add a bit, if you render your geometry textures in one texture (called diffuse color buffer, or albedo), normals in one texture, positions or depth in one texture, then you will be able to render very large amount of lights in your scene. This is called "deferred rendering" which means that lights are deferred for later, after rendering the scene geometry. Click for a nice tutorial \$\endgroup\$ – Lasse Jun 17 '16 at 4:56

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.