Sign in to follow this  

OpenGL Is Clustered Forward Shading worth implementing?

This topic is 1813 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

This has been a fascinating topic, and I commend everyone contributing too it! Warning, what follows is a somewhat off topic rant

 

Since it wasn't clear, I was arguing for deferred simply to handle most worst case scenarios in games today, not that it was the most efficient always, and yes forward/hybrid/etc. may always have scenarios where X is faster than Y. This generation, now closing, has seen an extreme need for optimization of resources for each game. Programmer time and talent has been, and will always be another consideration, but pushing good visuals versus limited resources has eaten up more and more consideration as time has gone on. So optimizing what you are doing for each game has been a priority, including refactoring something like lighting each time if need be.

 

This next generation however, I believe, will be different. Certainly more compute power will always be usable, pretty much into infinity. But the biggest constraint I can see is artist time. It's already been a constraint with modern games, and can only get worse now that a thousand materials can be supported on models a hundred thousand faces and more in count, not too mention all the advanced animation rigging for things like cloth physics, hair physics, skin and muscle simulation and etc. that can be done.

 

Which is simply why I foresee less time spent on refactoring rendering and more time making better tools for artists. Certainly, there are going to be cases still where forward/deferred/hybrid approaches are better; and as MJP pointed out you can have a more generalized pipeline far more easily now, which is great! But anything that makes the job easier and faster for artists, at least in my view, should be given priority. Which is a reason why I've viewed the use of multiple BRDFs with skepticism. The less the artist has to learn, and thus the more time spent actually making things, the better. And while certainly better can be done than Blinn-Phong, I'd simply rather not even give most artists the opportunity to sit there and switch between Beckmann to GGX to Cook-Torrance to etc. just to see what each did to "Get it right."

 

And I know there are ways to mitigate that. Suggestions I've seen range from pre-defined materials with correct values to not let artists screw things up to. etc. etc. All take time, and I'm mostly thinking way too hard about efficiency I suppose. So in short I'd rather hope for, in general, far less refactoring each game, as little complexity (and thus time and effort) added to the artists pipeline as possible, and more effort on all those very neat tools and research into such this go around. After all, I enjoy playing games as well, and would love to see them be as good as possible. And it makes more sense to me to take the Hollywood/offline VFX path of late, which is trying to make making things faster and cheaper, rather than trying harder to make things look better. So I'd rather have a deferred render capable of handling the worst case gameplay scenarios with a generalized BDRF that's good enough at doing multiple materials. But that's a far away thought I suppose.

Share this post


Link to post
Share on other sites

I.E. Here's what I'm talking about, even Hollywood and Disney have this problem and are trying to solve it: http://disney-animation.s3.amazonaws.com/library/s2012_pbs_disney_brdf_slides_v2.pdf

 

In fact, their BDRF sounds pretty good! "As few parameters as possible, 0-1 range, all combinations of parameters plausible" Mmmm yeah that's the stuff. One BDRF to rule them all, one BDRF to find them, one deferred renderer to bring them all, and in screenspace bind them! laugh.png

Edited by Frenetic Pony

Share this post


Link to post
Share on other sites
Which is a reason why I've viewed the use of multiple BRDFs with skepticism. The less the artist has to learn, and thus the more time spent actually making things, the better. And while certainly better can be done than Blinn-Phong, I'd simply rather not even give most artists the opportunity to sit there and switch between Beckmann to GGX to Cook-Torrance to etc. just to see what each did to "Get it right."

 

This isn't the problem you think it is; the BRDF/shaders are set up by tech artists (in association with rendering programmers) which are not the same guys doing the models/animation/rigging which take the time. Those guys are handed shaders and told 'use these' so they won't be swapping from one function to another to 'get it right'.

Share this post


Link to post
Share on other sites
Which is a reason why I've viewed the use of multiple BRDFs with skepticism. The less the artist has to learn, and thus the more time spent actually making things, the better. And while certainly better can be done than Blinn-Phong, I'd simply rather not even give most artists the opportunity to sit there and switch between Beckmann to GGX to Cook-Torrance to etc. just to see what each did to "Get it right."

 

This isn't the problem you think it is; the BRDF/shaders are set up by tech artists (in association with rendering programmers) which are not the same guys doing the models/animation/rigging which take the time. Those guys are handed shaders and told 'use these' so they won't be swapping from one function to another to 'get it right'.

Yes, and setting up a thousand BDRF shaders doesn't take up their time? Of course it does, otherwise Disney wouldn't have gone to all that trouble to reduce their rendering down to a single BDRF.

Share this post


Link to post
Share on other sites

ah yes, the old reductio ad absurdum argument....

 

A game is NOT going to have thousands of BDRF setup for it, a few will be selected from a small batch and those will be used (and result in many INSTANCES of the materials with different parameters) but the BDRFs themselves will be quite a low count. Over time more BDRF might get added but you aren't going to say "we are going to make a game, quick make ALL the BDRF shaders!" - that would be so many shades of dumb even thinking it is possible is.. well.. dumb.

Share this post


Link to post
Share on other sites
ah yes, the old reductio ad absurdum argument....

 

A game is NOT going to have thousands of BDRF setup for it, a few will be selected from a small batch and those will be used (and result in many INSTANCES of the materials with different parameters) but the BDRFs themselves will be quite a low count. Over time more BDRF might get added but you aren't going to say "we are going to make a game, quick make ALL the BDRF shaders!" - that would be so many shades of dumb even thinking it is possible is.. well.. dumb.

 

Tri-Ace was developing several already, for a game that was supposed to be this generation. Next gen there won't be nearly as much restriction, if Hollywood sees it as a problem to solve why would games, unburdened by much in the way of hardware constraints (as far as BDRF goes) be any different? Budgets can certainly be similar, and games often have far, far more assets.

 

With a single generalized BDRF, such as the one Disney has developed and I linked too, you would need a fat G-Buffer to store enough parameters sure. But you can go deferred and avoid dynamic branching, and you do save time. I'm not saying it's going to be as huge a benefit as a movie CG might get. Obviously artists wouldn't have time to sit there and fiddle with materials ad nauseum. But if it saves time it saves time. Point is I don't see much reason NOT to have a single, highly artists friendly BDRF as opposed to multiple kinds.

Share this post


Link to post
Share on other sites
Point is I don't see much reason NOT to have a single, highly artists friendly BDRF as opposed to multiple kinds.

In theory, it is a great idea... but, perhaps you're over-estimating next-gen power. Disney can spend an hour per frame, using 100 GPUs, we need 33ms per frame on 1 GPU.

 

For realtime, you're not going to want to compute sub-surface-scattering, or anisotropic reflections, for every surface if you can avoid it, etc, etc...

Edited by Hodgman

Share this post


Link to post
Share on other sites
For realtime, you're not going to want to compute sub-surface-scattering, or anisotropic reflections, for every surface if you can avoid it, etc, etc...

 

Awwee... But I want anistropic-specularity on my cream cheese, the bagels upon which 'tis spread, and my hot cup O' goodness!

 

There's an obvious engineering solution to this... isn't there? Ha... I'm sorry but I think it's just too simple to explicitly indicate. It's a very elementary premise of tool making... You don't need to internally implement such an "artist friendly BDRF" ... Too many hints ...

 

So yeah.

Share this post


Link to post
Share on other sites

Note that Forward+ (aka Clustered Forward, Light Indexed Deferred) is a very new topic and there's a lot of research coming up this year.

Now, just because I'd hate for this to turn into another deferred lighting / shading terminology kerfuffle:

 

Tiled Forward <=> Forward+, these use 2D tiling (same as Tiled Deferred), with a pre-z pass (optional) + separate geometry pass for shading.

Light Indexed Deferred, Builds the lists per pixel, which can be viewed as a 1x1 tile, and then it is really the same as Tiled Forward. The practical difference is pretty big, though...

Clustered Forward, performs tiling in 3D (or higher). othwewise as above.

Tiled/Clustered Deferred Shading, do tiling as their forward counterparts, but start with a G-Buffer pass and end with a deferred shading pass.

 

Hope this clears up, and/or prevents, some confusion.

Share this post


Link to post
Share on other sites

Thanks! Sad they don't have fries on them.

 

EDIT: @nfactorial, my hope is restored.

Edited by TheChubu

Share this post


Link to post
Share on other sites

Haha, whoops. I don't know why I wrote BDRF. Here's a reminder (saw this on Twitter smile.png):

 

7zZgSIk.png

BeaRDed F!

Share this post


Link to post
Share on other sites

There is a thing I don't understand.
It appears there's this thing still going on which plain forward can only do 8-10 lights per pass. How? In the past I've had quite some success encoding light data in textures and looping them on entry-level SM3 hardware. Perhaps I'm not seeing the whole picture but in SM4 with the much higher resource limits and the unlimited dynamic instruction count... shouldn't we go easily in the thousand range? Of course we'll neeed a z-only pass first.
So I guess there are additional practical reasons to stay in the 8-10 range.

 

At the top of page 2, I read about extra pressure and lower execution efficiency. I understand.

But, as much as I love lighting modularity coming from deferred, as a DDR3 card owner I still don't understand how the improved processing makes up for the bandwidth increase required. The trend on bandwidth is set. It looks to me we want to trash compute in the future.

Share this post


Link to post
Share on other sites

Hi Krohm,

 

In shader model 4.0 you can have up to 4096 entries in a constant buffer (which would limit lights to ~256 if they have position, direction diffuse, specular). Or you can use texture buffers and have near limitless lights.

Let's say you use the latter, so no worries about the light count. And today with SM 5.0 we really don't need to worry about loop count limits either. So we're good on that front

 

Indeed you can loop through a 1000 lights in SM4+ hardware. But let's say I'm running at 1920x1080 resolution and the whole screen is covered.

1920x1080 x 1000 lights = 2.073.600.000 light evaluations per frame.

Not to mention some BRDFs are expensive (i.e. Cook Torrance). Framerate would be sloooooooooow. So slow in fact, that it could trigger the Windows watchdog for believing the GPU is stalled and restart the driver.

 

The secret behind Deferred shaders (or Forward+) is that even though there are thousands of lights, they're not covering the whole screen at the same time.

In other words: many small lights = few big lights.

It's typical that a single region of the screen isn't lit by more than 4-20 lights, may be 5 on average. Let's be pessimistic and say 10.

1920x1080 x 10 lights = 20.736.000 light evaluations per frame

That's a lot more reasonable for a GPU to perform in real time. In such scenario every region of pixels (called tiles) would only have to loop through 10 lights (on average), not a 1000 and waste gpu time on 990 lights that aren't needed.

Share this post


Link to post
Share on other sites
But what if you would test whether a light actually should be covering the individual pixels inside this loop and skip all the lights, that shouldn't? The only difference to a tile-based deferred renderer would be, that the light culling is performed per pixel instead of per tile. But you wouldn't have all the BRDF, transparency, bandwidth and Anti-Aliasing issues. It would basically be a worse version of a light indexed deferred renderer, because the list of lights is not precomputed. Edited by CryZe

Share this post


Link to post
Share on other sites

Also with more traditional forward rendering you would typically have stage (performed either offline or online) where you determine which lights will affect a given mesh, so that you only apply those lights when rendering it. Once again the only major difference is your granularity, and when/where you cull your lights at your given level of granularity. Doing everything on the GPU lets you achieve very fine granularity (per-tile or per-pixel) with relatively simple code, which is the primary draw of deferred techniques.

Share this post


Link to post
Share on other sites

But what if you would test whether a light actually should be covering the individual pixels inside this loop and skip all the lights, that shouldn't? The only difference to a tile-based deferred renderer would be, that the light culling is performed per pixel instead of per tile. But you wouldn't have all the BRDF, transparency, bandwidth and Anti-Aliasing issues. It would basically be a worse version of a light indexed deferred renderer, because the list of lights is not precomputed.

You could do that, but GPUs suck at branch-heavy applications, specially if there's not good branch coherency within the tile block (pixel shaders are run in blocks)

 

And even if it did, a tile-based deferred renderer is MUCH more efficient in performing this culling.

Share this post


Link to post
Share on other sites

This topic is 1813 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this  

  • Similar Content

    • By xhcao
      Does sync be needed to read texture content after access texture image in compute shader?
      My simple code is as below,
      glUseProgram(program.get());
      glBindImageTexture(0, texture[0], 0, GL_FALSE, 3, GL_READ_ONLY, GL_R32UI);
      glBindImageTexture(1, texture[1], 0, GL_FALSE, 4, GL_WRITE_ONLY, GL_R32UI);
      glDispatchCompute(1, 1, 1);
      // Does sync be needed here?
      glUseProgram(0);
      glBindFramebuffer(GL_READ_FRAMEBUFFER, framebuffer);
      glFramebufferTexture2D(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
                                     GL_TEXTURE_CUBE_MAP_POSITIVE_X + face, texture[1], 0);
      glReadPixels(0, 0, kWidth, kHeight, GL_RED_INTEGER, GL_UNSIGNED_INT, outputValues);
       
      Compute shader is very simple, imageLoad content from texture[0], and imageStore content to texture[1]. Does need to sync after dispatchCompute?
    • By Jonathan2006
      My question: is it possible to transform multiple angular velocities so that they can be reinserted as one? My research is below:
      // This works quat quaternion1 = GEQuaternionFromAngleRadians(angleRadiansVector1); quat quaternion2 = GEMultiplyQuaternions(quaternion1, GEQuaternionFromAngleRadians(angleRadiansVector2)); quat quaternion3 = GEMultiplyQuaternions(quaternion2, GEQuaternionFromAngleRadians(angleRadiansVector3)); glMultMatrixf(GEMat4FromQuaternion(quaternion3).array); // The first two work fine but not the third. Why? quat quaternion1 = GEQuaternionFromAngleRadians(angleRadiansVector1); vec3 vector1 = GETransformQuaternionAndVector(quaternion1, angularVelocity1); quat quaternion2 = GEQuaternionFromAngleRadians(angleRadiansVector2); vec3 vector2 = GETransformQuaternionAndVector(quaternion2, angularVelocity2); // This doesn't work //quat quaternion3 = GEQuaternionFromAngleRadians(angleRadiansVector3); //vec3 vector3 = GETransformQuaternionAndVector(quaternion3, angularVelocity3); vec3 angleVelocity = GEAddVectors(vector1, vector2); // Does not work: vec3 angleVelocity = GEAddVectors(vector1, GEAddVectors(vector2, vector3)); static vec3 angleRadiansVector; vec3 angularAcceleration = GESetVector(0.0, 0.0, 0.0); // Sending it through one angular velocity later in my motion engine angleVelocity = GEAddVectors(angleVelocity, GEMultiplyVectorAndScalar(angularAcceleration, timeStep)); angleRadiansVector = GEAddVectors(angleRadiansVector, GEMultiplyVectorAndScalar(angleVelocity, timeStep)); glMultMatrixf(GEMat4FromEulerAngle(angleRadiansVector).array); Also how do I combine multiple angularAcceleration variables? Is there an easier way to transform the angular values?
    • By dpadam450
      I have this code below in both my vertex and fragment shader, however when I request glGetUniformLocation("Lights[0].diffuse") or "Lights[0].attenuation", it returns -1. It will only give me a valid uniform location if I actually use the diffuse/attenuation variables in the VERTEX shader. Because I use position in the vertex shader, it always returns a valid uniform location. I've read that I can share uniforms across both vertex and fragment, but I'm confused what this is even compiling to if this is the case.
       
      #define NUM_LIGHTS 2
      struct Light
      {
          vec3 position;
          vec3 diffuse;
          float attenuation;
      };
      uniform Light Lights[NUM_LIGHTS];
       
       
    • By pr033r
      Hello,
      I have a Bachelor project on topic "Implenet 3D Boid's algorithm in OpenGL". All OpenGL issues works fine for me, all rendering etc. But when I started implement the boid's algorithm it was getting worse and worse. I read article (http://natureofcode.com/book/chapter-6-autonomous-agents/) inspirate from another code (here: https://github.com/jyanar/Boids/tree/master/src) but it still doesn't work like in tutorials and videos. For example the main problem: when I apply Cohesion (one of three main laws of boids) it makes some "cycling knot". Second, when some flock touch to another it scary change the coordination or respawn in origin (x: 0, y:0. z:0). Just some streng things. 
      I followed many tutorials, change a try everything but it isn't so smooth, without lags like in another videos. I really need your help. 
      My code (optimalizing branch): https://github.com/pr033r/BachelorProject/tree/Optimalizing
      Exe file (if you want to look) and models folder (for those who will download the sources):
      http://leteckaposta.cz/367190436
      Thanks for any help...

    • By Andrija
      I am currently trying to implement shadow mapping into my project , but although i can render my depth map to the screen and it looks okay , when i sample it with shadowCoords there is no shadow.
      Here is my light space matrix calculation
      mat4x4 lightViewMatrix; vec3 sun_pos = {SUN_OFFSET * the_sun->direction[0], SUN_OFFSET * the_sun->direction[1], SUN_OFFSET * the_sun->direction[2]}; mat4x4_look_at(lightViewMatrix,sun_pos,player->pos,up); mat4x4_mul(lightSpaceMatrix,lightProjMatrix,lightViewMatrix); I will tweak the values for the size and frustum of the shadow map, but for now i just want to draw shadows around the player position
      the_sun->direction is a normalized vector so i multiply it by a constant to get the position.
      player->pos is the camera position in world space
      the light projection matrix is calculated like this:
      mat4x4_ortho(lightProjMatrix,-SHADOW_FAR,SHADOW_FAR,-SHADOW_FAR,SHADOW_FAR,NEAR,SHADOW_FAR); Shadow vertex shader:
      uniform mat4 light_space_matrix; void main() { gl_Position = light_space_matrix * transfMatrix * vec4(position, 1.0f); } Shadow fragment shader:
      out float fragDepth; void main() { fragDepth = gl_FragCoord.z; } I am using deferred rendering so i have all my world positions in the g_positions buffer
      My shadow calculation in the deferred fragment shader:
      float get_shadow_fac(vec4 light_space_pos) { vec3 shadow_coords = light_space_pos.xyz / light_space_pos.w; shadow_coords = shadow_coords * 0.5 + 0.5; float closest_depth = texture(shadow_map, shadow_coords.xy).r; float current_depth = shadow_coords.z; float shadow_fac = 1.0; if(closest_depth < current_depth) shadow_fac = 0.5; return shadow_fac; } I call the function like this:
      get_shadow_fac(light_space_matrix * vec4(position,1.0)); Where position is the value i got from sampling the g_position buffer
      Here is my depth texture (i know it will produce low quality shadows but i just want to get it working for now):
      sorry because of the compression , the black smudges are trees ... https://i.stack.imgur.com/T43aK.jpg
      EDIT: Depth texture attachment:
      glTexImage2D(GL_TEXTURE_2D, 0,GL_DEPTH_COMPONENT24,fbo->width,fbo->height,0,GL_DEPTH_COMPONENT,GL_FLOAT,NULL); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, fbo->depthTexture, 0);
  • Popular Now