OpenGL 3D Game Tutorial 11: Per-Pixel Lighting

preview_player
Показать описание
LWJGL tutorial series on how to create a 3D Java game with OpenGL!

This week we add per-pixel diffuse lighting to the game, making everything look that little bit more epic!

Common Problems:

- Make sure that you are calling bindAttributes() *before* glLinkProgram() in the ShaderProgram constructor. Also, check that you spelled the "in" variable names correctly in the "bindAttributes()" method in the StaticShader class.

-If your dragon seems to have lots of white and black patches then it could be one of 2 problems:

1. Your texture dimensions might not be powers of 2 (64x64, 128x128, 256x256 etc.)

2. If they are powers of 2 then try adding the following lines to the end of the loadTexture() method, just before returning the texture ID:

Source: Stanford University Computer Graphics Laboratory

Vector maths basics:

Dot product:

End of video music- Kai Engel, "Waking Stars":

Рекомендации по теме
Комментарии
Автор

Finally! Keep doing the tutorials, there are very easy to understand! And you're a big motivation for me!

ricsubtil
Автор

I love the drawings, they really help a lot, thanks man!

rektsammy
Автор

If your dragon seems to have lots of white and black patches then it could be one of 2 problems:
1. Your texture dimensions might not be powers of 2 (64x64, 128x128, 256x256 etc.)
2. If they are powers of 2 then try adding the following lines to the end of the loadTexture() method, just before returning the texture ID:
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR);
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR);
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL11.GL_REPEAT);
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL11.GL_REPEAT);

ThinMatrix
Автор

I am currently doing a graphics course at Imperial and I can say that you are better at explaining concepts than many of the phd assistants here..

keep up the good work!
thank you very much!

woo-jinchokim
Автор

I'm not sure if you have paid tutorials or coaching or not, but you should definitely do it. You have a real skill for explaining complicated stuff in an easy manner. Probably the best one I see on youtube tutorials and I've seen some.

stangeorge
Автор

Thank you, ThinMatrix! I can make my dreams come true.

최고가될꺼야
Автор

Thank you for making these tutorials man. You have done a far better job then the university I paid thousands of dollars for. In their lecture slides they actually explain it completely damn wrong and I had done as they instructed and the result I got was completely wrong .... Finally fixed after a day wondering why it's not working ... and that is something that should have taken me 15 minutes.

darinbogdanov
Автор

I downloaded your all videos.They all are amazing buddy. thanks for your service.Thankyou

romeshfernando
Автор

Great tutorial, it's really nice to see how things can become quite easy to understand and build when you have a good setup and understanding. Before this, I just followed some tutorials and copied it, but never really understood it myself. Writing the shaders from scratch really helps to understand the inner workings, instead of using gLight() It seems even easier now! :)

pinguisimo
Автор

That seems to be pretty hardcore ;0
Feels like I finally get how a lot of the high level stuff relies on that sort of math.
Your tutorials are really good :)

datsnek
Автор

Great Lesson!! Things were very clear and concise.

TheCalkronic
Автор

I found that making an Object class that has position and rotation parameters aswell as a few other useful methods for any entities and then extending classes such as Light, Entity, Camera etc. from that is a very useful method. This way you only have to include the entity-specific method's in it's class and thus can simply make methods like applyMovement, applyRotation, etc. in one class only. ;)

AdriansNetlis
Автор

Great tutorial! Keep up the good work!

DemonicGaming
Автор

To anyone who's getting a weird render with your model, despite everything seemingly being correct. Make sure in the "prepare()" function in the Renderer class looks like this:

public void prepare() {


GL11.glClearColor(1, 0, 0, 1);
}

I missed out on adding the DEPTH_TEST and Clearing the DEPTH_BUFFER_BIT and so my model looked very weird. As the triangles were rendering on top of one another.

lightningshark
Автор

Vertex shader failed to compile with the following errors:
ERROR: 0:23: error(#162) Wrong operand types: no operation "-" exists that takes a left-hand operand of type "uniform highp 4-component vector of vec4" and a right operand of type "highp 3-component vector of vec3" (or there is no acceptable conversion)
ERROR: 0:23: error(#160) Cannot convert from: "uniform highp 4-component vector of vec4" to: "default out highp 3-component vector of vec3"
ERROR: error(#273) 2 compilation errors. No c
Could not compile shader!
please someone help!

hailclientdev
Автор

I am getting an invalid operands to "-" in my vertexShaders with the line that reads:

toLightVector = lightPosition - worldPosition.xyz;

I can't compile my shaders, and I can't figure out how the subtraction symbol is an invalid operand...

JSHyCS
Автор

Very useful!
Thanks a lot for this awesome tutorial :D

iguagofernando
Автор

If you find it difficult to understand normalization; picture a really long line pointing in a certain direction, and you simply shorten the line, but it still points in the same direction. That's what normalizing does. The length of the line is between 0.0f and 1.0f after it is normalized.

NeilRoy
Автор

shouldn't you pass the surface normal and the light vector already normalized? that way you dont have to normalize per pixel

javari
Автор

The dragon is rendering inside out and I cant find the origin of the problem. I am using the exact same model and even if I use other models, the textures and lighting renders on the inside

ojaslandge