Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

About light module #40

Closed
RMTT opened this issue May 28, 2020 · 2 comments
Closed

About light module #40

RMTT opened this issue May 28, 2020 · 2 comments
Assignees
Labels
question Further information is requested

Comments

@RMTT
Copy link

RMTT commented May 28, 2020

Hello, i'm comeback again : )

Nowadays, i'm studying the light model.
Your engine are using the plane lights with a single light source, is right?
But what the principle to compute the shadow, any document will be helpful, thank you very much!

@ScrappyCocco ScrappyCocco self-assigned this May 28, 2020
@ScrappyCocco ScrappyCocco added the question Further information is requested label May 28, 2020
@ScrappyCocco
Copy link
Owner

Hello again, as i said in the previous discussion, i am not an expert in implementing lightning tecniques, so i will just explain the basics about how it works in the engine and where you can look to implement your own.

Basics

Usually, if you want to achieve a whole illuminated scene with multiple lights and effects you go for Deferred rendering, you can read the basics about how it works there or googling. This allow you to implement a lot of lighting tecniques more easily.

To keep it simple and to study just the basics i used only a directional light (the sun basically), rendered using Forward Rendering. This process usually is solwer in terms of performance and could be a bit more complicated.

So as i said, in my engine there's just a directional light, adding more lights (such as point lights) could be done but require quite some changes, either improving the Forward Rendering code or switching the whole engine to Deferred rendering.

Notice that i didn't use any of the tecniques to achieve good lightning such as specular/normal/... textures.

Shadows

That was just the basics to render lights, rendering the shadows is another whole topic, and could be more difficult to understand and implement.

Rendering a shadow is basically "capturing" the scene from the light point of view and so compute where the mesh are projected. I really suggest you to look at LearnOpenGL-/Shadow-Mapping to understand the basics.

Every light could be different: while a directional light is basically rendering the scene from another point of view, a point light need to know how the scene looks from every angle, so it ususlly contains 6 (cubemmap)/8 shadow textures.

It could look easy as long as you have a single light, when you want multiple lights with shadows from each one of them, things gets harder because you can't allocate lots of shadow textures in the GPU and need to choose which to pick or implement optimization tecniques, but these are more advanced topic i will not explain right now. If you want you can give a look at this presentation.

Examples

Basic examples you can look at (All of them use Forward Rendering):

If you want examples with Deferred Rendering:

In the engine

So, once again, right now my engine use only a single directional light for the sun, is exactly the same as the first example linked above (Basic shadowmapping).

The resources are created here: StandardShadowmapping.cpp.

As everything else it need to be in a command buffer, this is here: StandardCommandBuffer.cpp#L99.

Basically first it render the shadow commands and then the actual game adding the information from the shadow rendering. I suggest you to analyze it with Renderdoc if you have time. (You need to download the last .exe from Releases).

The main rendering order is here: RenderManager.cpp#L429 and as i said before, first there are the shadow commands and then the final command that produce the final result.

End

These are just the basics, if you need to know more go read other resources and look at examples, i'm not an expert in this yet, so i can't help you so much.

@RMTT
Copy link
Author

RMTT commented May 28, 2020

Thanks man, i have known this principle!
Really thanks for your recommendation of https://learnopengl.com/Advanced-Lighting/Shadows/Shadow-Mapping

@RMTT RMTT closed this as completed May 28, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants