• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
korvax

Trying to understand Lighting general.

11 posts in this topic

Hi,

im quiet new to graphic programming,, been programing for quiet some time now.

 

Im trying to understand some general of how lighting works (not the shader logic behind it), and how it should be structured with in a program.

 

Lets say i have X objects in my scene, and 3 different types of light sources lets say that all lights sources affects all objects, Point, Spotlight, Diffuse. As i understand it i need 3 different shaders (same shader compiled with different defines or one that is branched). In a more standard approach (I guees its called Forward Rendering) Do I need to render render each object 3 times  with a different shader each time seems a bit inefficient in my untrained eyes. and if so will the output be automatically merged or do i need to something?

 

If i have same scenario but i use a Deferred approach how would that work?

0

Share this post


Link to post
Share on other sites

Hey,

 

Not sure what was on the blog as I wrote that entry a million years ago, but for Deferred Lighting, the recipe is basically as follow:

 

1- Render pixel attributes to G-Buffers (diffuse, specular, gloss, normal, position/depth, ... whatever you need)

2- For each light (point, spot, whatever) apply a specific shader.

The shader draws pixels (on a texture buffer), using the step1 information.

 

So, rendering the objects is really separated from the lighting step, which does not involve the 3D meshes of the objects.

 

Notice that nowadays several newer techniques such as "Tiled Deferred Rendering" are being introduced. The idea remains the same, though it's more optimized. Either way, I would start with a simple deferred renderer first for learning purposes.

 

Good luck!

0

Share this post


Link to post
Share on other sites

As i understand it i need 3 different shaders (same shader compiled with different defines or one that is branched). In a more standard approach (I guees its called Forward Rendering) Do I need to render render each object 3 times with a different shader each time seems a bit inefficient in my untrained eyes.

Yes, it is. The main problem with forward techniques (or the main advantage of deferred) is exactly this decoupling of lighting complexity from shaders.
Nobody says you need 3 shaders and three drawcalls. If you know you have 1 point, 1 spot and 1 area (I suppose that's your diffuse) then just write a shader than evaluates those three.

Accumulating more lighting through multipass is not automatic, it's a blend operation to be turned on. You might have heard blend is slow. Basic ("dumb" would be a better terminology) deferred blends even more so I guess we can all afford it. Or so they say.
What you report as the solution is basically a multi-pass technique doing basically the same thing by using render-texture. It doesn't radically change what's going on conceptually, although the performance will hopefully be different. Edited by Krohm
1

Share this post


Link to post
Share on other sites

Hey,

 

Not sure what was on the blog as I wrote that entry a million years ago, but for Deferred Lighting, the recipe is basically as follow:

 

1- Render pixel attributes to G-Buffers (diffuse, specular, gloss, normal, position/depth, ... whatever you need)

2- For each light (point, spot, whatever) apply a specific shader.

The shader draws pixels (on a texture buffer), using the step1 information.

 

So, rendering the objects is really separated from the lighting step, which does not involve the 3D meshes of the objects.

 

Notice that nowadays several newer techniques such as "Tiled Deferred Rendering" are being introduced. The idea remains the same, though it's more optimized. Either way, I would start with a simple deferred renderer first for learning purposes.

 

Good luck!

Any clue where I should start looking if i want to learn more how i should implement a Defered Rendering.. Haven't really found any good example on it but loads on Forwared Rendering.

0

Share this post


Link to post
Share on other sites

Not sure where I got it from... I believe I found code on Delphi3d.net (but that website is gone, maybe the examples are still there somwhere) and from the nVidia SDK 9.5 which has a lot of example programs.

 

It's not that difficult, but do you know how to render data to texture buffers / G-buffers? The first step would be to render your (opaque) scene into a couple of buffers (note you can render into multiple textures at the same time). Once you have these buffers, you can do all kinds of stuff with them, including deferred lighting. At which point are you right now?

0

Share this post


Link to post
Share on other sites

Not sure where I got it from... I believe I found code on Delphi3d.net (but that website is gone, maybe the examples are still there somwhere) and from the nVidia SDK 9.5 which has a lot of example programs.

 

It's not that difficult, but do you know how to render data to texture buffers / G-buffers? The first step would be to render your (opaque) scene into a couple of buffers (note you can render into multiple textures at the same time). Once you have these buffers, you can do all kinds of stuff with them, including deferred lighting. At which point are you right now?

Well im no where. it seems, currently trying to research the subject so i can understand where i should start. So it seems that i first need to learn how to render multiple texture texture and when I have master that and able to display and fill them. 

 

 

Accumulating more lighting through multipass is not automatic, it's a blend operation to be turned on. You might have heard blend is slow. Basic ("dumb" would be a better terminology) deferred blends even more so I guess we can all afford it. Or so they say.
What you report as the solution is basically a multi-pass technique doing basically the same thing by using render-texture. It doesn't radically change what's going on conceptually, although the performance will hopefully be different.

  

 

So to able to merge the output from the different shaders i need to blend them? Is the blend operation something that I use in the shaders or in the "cpu world". 

0

Share this post


Link to post
Share on other sites

I don't know the DirectX terms exactly, but indeed, find an example that does "MRT" (multi render target) so you can draw an object into multiple buffers. I'm pretty sure that nVidia SDK has a lot of examples on that. Once you have set that up, try to render several pixel attributes into your textures. For example:

 

* texture1: rgb = pixel diffuse color  a = specular term

* texture2: rgb = pixel world position a = specular glossiness

* texture3: rgb = pixel normal   a = ...?

 

Note this is just an example. You can compress data such as the normals and positions to get more available for other attributes. But this would be an easy start. Also note that this step does not involve any lighting so far.

 

 

>> blending

Yes. Compare it with photoshop & layers. In the first layer, you have your scenery with its diffuse colors - no lights yet. On a second layer, you draw a red circle that represents a red point light. Set the layer blending mode to "additive" or "light up", or whatever its called in PS. Then on layer 3, you can make another lamp, and so on. Finally, merge all light layers and multiply it with the first lighting. It's not exactly the same, but pretty close.

 

Blending is not too fast, though additive blending is pretty simple, and I wouldn't worry about the performance unless you want LOT's of lights and/or target lower end hardware. But once you master Deferred Lighting, you could pick up Compute Shaders which allow you you to do all lights in a single pass, applied on smaller tiles on the screen. The Battlefield3 Frostbite engine has a nice paper that explains this "Tiled Deferred lighting". But anyhow, that's for later concern.

1

Share this post


Link to post
Share on other sites

I don't know the DirectX terms exactly, but indeed, find an example that does "MRT" (multi render target) so you can draw an object into multiple buffers. I'm pretty sure that nVidia SDK has a lot of examples on that. Once you have set that up, try to render several pixel attributes into your textures. For example:

 

* texture1: rgb = pixel diffuse color  a = specular term

* texture2: rgb = pixel world position a = specular glossiness

* texture3: rgb = pixel normal   a = ...?

 

Note this is just an example. You can compress data such as the normals and positions to get more available for other attributes. But this would be an easy start. Also note that this step does not involve any lighting so far.

 

 

>> blending

Yes. Compare it with photoshop & layers. In the first layer, you have your scenery with its diffuse colors - no lights yet. On a second layer, you draw a red circle that represents a red point light. Set the layer blending mode to "additive" or "light up", or whatever its called in PS. Then on layer 3, you can make another lamp, and so on. Finally, merge all light layers and multiply it with the first lighting. It's not exactly the same, but pretty close.

 

Blending is not too fast, though additive blending is pretty simple, and I wouldn't worry about the performance unless you want LOT's of lights and/or target lower end hardware. But once you master Deferred Lighting, you could pick up Compute Shaders which allow you you to do all lights in a single pass, applied on smaller tiles on the screen. The Battlefield3 Frostbite engine has a nice paper that explains this "Tiled Deferred lighting". But anyhow, that's for later concern.

Thank you spek  and Krohm your invaluable help, I now have plan to work from and  some better understanding of Lighting. I will put your'e names in the credits when my super Engine done. Which btw will make UnrealEngine and CryEngine look like armature hour :P

0

Share this post


Link to post
Share on other sites
Just to say Spek that your posts on your blog are very nice. Especially the "3D survival guide for starters".

=) Edited by Rakilonn
0

Share this post


Link to post
Share on other sites

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  
Followers 0