Jump to content

  • Log In with Google      Sign In   
  • Create Account


Multipass forward rendering?


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
8 replies to this topic

#1 KaiserJohan   Members   -  Reputation: 1085

Like
0Likes
Like

Posted 16 April 2013 - 04:04 AM

Hello,

 

Right now I'm using a forward renderer (OpenGL 3.3+) where I just run one pass with a maximum amount of lights predefined in the scene:

 

 

 

const int numberOfLights = 8;

struct PerLight
{
vec4 position;
vec4 intensity;
}

uniform Lights
{
vec4 ambientIntensity;
float lightAttenuation;
PerLight lights[numberOfLights];
} Lgt;
 

There are some issues, like for example if I only have 2 lights I still have to fill up space for 8, and the maximum amount is set at 8 so its not very flexible and dynamic. I want to be able to support any given amount of lights and I want my code to be independent of the amount of lights in the scene. 

 

I've read something about multipass forward rendering.. but I don't know really what it means, and I cannot find any good sources. From what I've gathered so far, it involves rendering each mesh a number of times equal to the number of lights that affects it and then somehow add the results? So for example if I have one mesh affected by 3 lights, I would render it three times and blend the results?

 

Do I understand it correctly? Also I do not know how to implement it in practice, is there any complete examples lying around? For example, how do you setup the actual blending between rendering passes, what opengl functions are used, etc? Is there anything else I should know?

 

Also, I have read about deferred rendering, but from what I've gathered it sounds abit complex and I'd rather try to atleast First get a multipass forward renderer working, since that seems easier and cooperates better with all the other tutorials on the internet (for example I still havnt learned texturing)


Edited by KaiserJohan, 16 April 2013 - 04:38 AM.


Sponsor:

#2 Ashaman73   Crossbones+   -  Reputation: 6881

Like
1Likes
Like

Posted 16 April 2013 - 04:16 AM

I've read something about multipass forward rendering.. but I don't know really what it means, and I cannot find any good sources. From what I've gathered so far, it involves rendering each mesh a number of times equal to the number of lights that affects it and then somehow add the results? So for example if I have one mesh affected by 3 lights, I would render it three times and blend the results?

Yes, light is additive and you can calculate one or more lights in a single pass and add it (blend one/one) to the buffer. Basicly you have two shaders, a base light shader (containing emissive/ambient light) and an additive light shader. The base shader should already handle more than one light (8 sounds good), and for each (8-) block of additional lights render the scene in an additional pass using additve blending.

 

As you can already see, this will scale really badly with scene complexity/number of lights, therefor you should either optimize it (not each light affects each face) or switch over to deferred rendering/lighting which scales really great only with number of lights.



#3 KaiserJohan   Members   -  Reputation: 1085

Like
0Likes
Like

Posted 16 April 2013 - 04:41 AM

I see. How does the blending between shader passes work, how do you accumulate the results between shader passes? 

I'm using OpenGL 3.3+ btw



#4 Schrompf   Prime Members   -  Reputation: 950

Like
1Likes
Like

Posted 16 April 2013 - 05:30 AM

You accumulate by using Alpha Blending.

glEnable (GL_BLEND);
glBlendFunc (GL_ONE, GL_ONE);

 

From the top of my head, no guarantees given.


----------
Gonna try that "Indie" stuff I keep hearing about. Let's start with Splatter.

#5 KaiserJohan   Members   -  Reputation: 1085

Like
0Likes
Like

Posted 16 April 2013 - 06:31 AM

Something like this then, for drawing one mesh?

 

 

glEnable (GL_BLEND);
glBlendFunc (GL_ONE, GL_ONE);

// udate uniform buffer with lights 1 to 8
DrawVAO();

// update uniform buffer with lights 9 to 16 and draw same vao again
DrawVAO();

glDisable (GL_BLEND);

 

 

?


Edited by KaiserJohan, 16 April 2013 - 06:46 AM.


#6 Schrompf   Prime Members   -  Reputation: 950

Like
0Likes
Like

Posted 16 April 2013 - 07:19 AM

I'm not your debugger. Try it. 


----------
Gonna try that "Indie" stuff I keep hearing about. Let's start with Splatter.

#7 Hodgman   Moderators   -  Reputation: 28500

Like
0Likes
Like

Posted 16 April 2013 - 07:29 AM

For opaque objects, the first light should have blending disabled, then the following lights should have it enabled with one/one (additive).

In other words, the first light performs a renderTarget=shader, while the rest of the lights do renderTarget+=shader.



#8 skytiger   Members   -  Reputation: 258

Like
0Likes
Like

Posted 16 April 2013 - 03:42 PM

You have to be careful with gamma, or use floating point rendertarget

http://www.gamedev.net/topic/631164-does-alpha-blending-shall-be-gamma-corrected/



#9 L. Spiro   Crossbones+   -  Reputation: 12800

Like
0Likes
Like

Posted 16 April 2013 - 07:14 PM

For alpha objects, which should be drawn after opaque objects as mentioned, the first render should be src = GL_SRC_ALPHA, dst = GL_ONE_MINUS_SRC_ALPHA, but the following passes should be src = GL_SRC_ALPHA, dst = GL_ONE.

 

 

L. Spiro


It is amazing how often people try to be unique, and yet they are always trying to make others be like them. - L. Spiro 2011
I spent most of my life learning the courage it takes to go out and get what I want. Now that I have it, I am not sure exactly what it is that I want. - L. Spiro 2013
I went to my local Subway once to find some guy yelling at the staff. When someone finally came to take my order and asked, “May I help you?”, I replied, “Yeah, I’ll have one asshole to go.”
L. Spiro Engine: http://lspiroengine.com
L. Spiro Engine Forums: http://lspiroengine.com/forums




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS