Diffuse Lighting // OpenGL Tutorial #20

  Рет қаралды 8,840

OGLDEV

OGLDEV

Күн бұрын

Пікірлер: 14
@OGLDEV
@OGLDEV 3 жыл бұрын
Don't miss the previous tutorial on ambient lighting! - kzbin.info/www/bejne/j5-lmX2Yhr9_q6c
@OGLDEV
@OGLDEV 3 жыл бұрын
@Unity Programmer Yeah I guess most beginner level OpenGL tutorials and books have to go through a very similar path at this stage but I believe there will be unique material in the future so stay tuned!
@OGLDEV
@OGLDEV 3 жыл бұрын
@Unity Programmer Ogre3D supports both APIs as backends but do you need direct access to the gpu? Not sure how simple that is.
@gokalpates1567
@gokalpates1567 3 жыл бұрын
keep working on this tutorials extremely helpful!
@OGLDEV
@OGLDEV 3 жыл бұрын
Sure will, thanks!
@dluffy121
@dluffy121 2 жыл бұрын
The series has been awesome. Just want to add a note for 6:19, we use reverse vector as we know that the angle of reflection vector wrt normal will be same as the angle of light vector. This only clicked me after you explained reflect function
@OGLDEV
@OGLDEV 2 жыл бұрын
Thanks! I think that the most intuitive example is that when the light vector is perpendicular to the surface. In that case the light vector and the normal are directly opposite so in theory the angle between them is 180 degrees but of course we want to refer to this case as if the angle is zero so we reverse the light vector. Some people prefer doing the reverse already in the application so save them from this operation in the shader on every pixel. This makes sense but for educational reasons I do it all in one place.
@kaede_elfen
@kaede_elfen 3 жыл бұрын
Keep up the awesome work!
@OGLDEV
@OGLDEV 3 жыл бұрын
Thank you!
@kermalis
@kermalis 2 жыл бұрын
At 11:30 and in your other videos (like for directional lighting), you bring up transforming everything back to local space from world space. However you mentioned that this would only work for uniform scaling, and that your solution of transposing the matrix is just a temporary one. It's a little scary for me to leave it that way, since you haven't brought this back up and clarified the proper way to do it which would handle non-uniform scaling. I think having non-uniform scaling is important and so my question is, how would I properly transform to local space? The code in question is the DirectionalLight local space direction calculation, and the WorldTrans WorldToLocal(). For the DirectionalLight, is it as simple as inverting the mesh's world transform matrix4x4, rather than transposing the top-left matrix3x3? You mentioned inverting it at 11:59. I already can invert it but am not sure if it's the correct solution, or whether to invert just the 3x3 portion or the entire 4x4 portion and skip the second vector multiplication. As for the WorldTrans one, I'm not sure if it needs updating since it's only used for the camera's local position and point lights' local positions, and we calculate their directions in the fragment shader with a simple subtraction. I figured I'd ask in case you could give me an answer for both since it's a little unclear for me right now, even though I think I understand how it all works Also thank you for your resources, I am grateful, and that you also take the time to reply to comments, you are invaluable
@OGLDEV
@OGLDEV 2 жыл бұрын
Thanks for bringing up the issue of scaling because there is a problem there and I wanted to do a followup video about it but couldn't find a time to squeeze it into the agenda. The problem is mostly for point lights where the vector to the light source changes from pixel to pixel. Let's say that you have a normalized quad from (-1,0,-1) to (1,0,1) and you want to use it as a large field and run a point light along it (see the point light demo on my website). With these coordinates you just need to apply a large scaling factor so no rotation and translation whatsoever. The light source local position is equal to its world position in this case. As the light runs back and forth along the field you expect it to attenuate and be visible only locally. In addition, the vector from the light to the far end of the field should be very sharp, affecting the diffuse factor. But if you ignore scaling you will do all calculation on the original (small) quad and it wil not be as expected. If you’re using uniform scaling the solution is simply to provide the scaling factor as a scalar to the VS and multiply it by the local position. It’s still less expensive than multiplying by a matrix. In the case of non-uniform scaling you can supply a vector of scaling factors and multiply it by the local position. GLSL does component wise multiplication in this case which is exactly what we need. Regarding WorldToLocal: in the case of diffuse lighting we just need to reverse the rotation so transposing the top 3x3 matrix should be enough. Translation won’t affect the light vector so we can ignore it. In the case of specular lighting we reverse translation and rotation separately and combine them to get the inverse. I agree that this is somewhat cumbersome so if you want to use a simple inversion of the entire matrix (using the determinant, etc) in the 4x4 case go ahead.
@kermalis
@kermalis 2 жыл бұрын
@@OGLDEV Yep, I ran into that point light scaling issue in my test scene, where the light was stretching with the entire mesh, because as you said, it was using the original small mesh as a reference. However I decided that I will tackle this local space optimization another time, since it's adding a bit more complexity than I'd like at the moment. I want to get things as robust as possible for the future before I start optimizing my systems, but I was curious about it so I figured I'd ask you, and you explain everything perfectly. I look forward to your next videos even though I started learning all of these things last year, because you keep teaching me advanced things that other teachers are leaving out, like these local transformation optimizations. So once again, thank you for all you do :)
@walidyider7766
@walidyider7766 3 ай бұрын
i have an issue , so when using multiplication for example : (materialColor * lightColor) if the materialColor is red and the lightColor is blue , this will result in black instead of purple
@OGLDEV
@OGLDEV 3 ай бұрын
In real world physics if a pure red light hits a pure blue surface it will seem like nothing is reflected back. But this is an extreme case. The Sun's light is white so you always get back the color of the surface. If you need a purple surface then make it purple and make sure the incoming light includes purple (or more).
Specular Lighting  // OpenGL Tutorial #21
23:00
OGLDEV
Рет қаралды 6 М.
Basic Lighting And Materials // OpenGL Tutorial #19
23:33
OGLDEV
Рет қаралды 16 М.
I Sent a Subscriber to Disneyland
0:27
MrBeast
Рет қаралды 104 МЛН
How to have fun with a child 🤣 Food wrap frame! #shorts
0:21
BadaBOOM!
Рет қаралды 17 МЛН
The Endless Grid
21:58
OGLDEV
Рет қаралды 4 М.
An introduction to Shader Art Coding
22:40
kishimisu
Рет қаралды 1 МЛН
Vertex Attribute Interpolation // OpenGL Tutorial #9
13:28
Moving The Camera // OpenGL Tutorial #14
22:40
OGLDEV
Рет қаралды 13 М.
The OpenGL Software Ecosystem
13:51
OGLDEV
Рет қаралды 10 М.
Basic Shadow Mapping // OpenGL Tutorial #35
16:54
OGLDEV
Рет қаралды 25 М.
Perspective Projection - Part 1 // OpenGL Tutorial #11
24:13
Scaling Transformation  // OpenGL Tutorial #8
15:35
OGLDEV
Рет қаралды 8 М.
The Dome Paradox: A Loophole in Newton's Laws
22:59
Up and Atom
Рет қаралды 203 М.