Hello everyone.
I’ve stumbled upon these great Java tutorials, and I implemented one of the tutorials which was about creating a normal map for 2D textures https://github.com/mattdesl/lwjgl-basics/wiki/ShaderLesson6. It works great, and looks really beautiful.
Now I’m wondering what would be an efficient way to use this method for two or more different textures at the same time? I’m using LibGDX.
(I did not get a good look at the tutorial, because I was too impatient to implement it, so I hope what I’m asking is not covered in the tutorial)
Thanks in advance.
I don’t understand the question… Just pass the shader both the textures and render. What are you trying to do that isn’t already explained in the tutorial?
What I want to do is to have multiple “shaded” textures at the same time.
So for instance, I want to not only be able to have this tutorial’s “shaded” texture rendered, but another texture too, a character for example.
See here for example:
The background wall and the character are both “shaded”, whereas the tutorial shows us how to do this for just one texture. How can I accomplish this in an effective way?
I’m pretty sure my problem is that I don’t understand GLSL that good yet, but if someone explained this to me it would really help me understand it.
The shader will apply the lighting to anything you render. So if you render a background, and then a sprite on top, as long as they both use the same shader, they will both get lit with normal mapping.
First of all, thanks for making these tutorials, they are really descriptive and informative.
The problem I’m having is binding the new sprite’s normal map and diffuse color. I don’t know where or how exactly I should do it.
Here’s the render code from the project Im working on and some screenshots:
batch.begin();
// shader will now be in use
// update light position, normalized to screen resolution
float offsetX = 0.085f;
float offsetY = 0.11f;
LIGHT_POS.x = world.getPlayer().getX() / (float) Project.width + offsetX;
LIGHT_POS.y = world.getPlayer().getY() / (float) Project.height + offsetY;
LIGHT_POS.z = 0.020f;
// send a Vector4f to GLSL
shader.setUniformf("LightPos", LIGHT_POS);
// bind normal map to texture unit 1
floorNormals.bind(1);
// bind diffuse color to texture unit 0
// important that we specify 0 otherwise we'll still be bound to
// glActiveTexture(GL_TEXTURE1)
floor.bind(0);
// draw the texture unit 0 with our shader effect applied
for (int i = 0; i < 10; i++) {
for (int j = 0; j < 10; j++) {
batch.draw(floor, i * Project.GLOBAL_SCALEX, j * Project.GLOBAL_SCALEY, Project.GLOBAL_SCALEX, Project.GLOBAL_SCALEY);
}
}
batch.draw(world.getPlayer().getTexture(), world.getPlayer().getX(), world.getPlayer().getY(), Project.GLOBAL_SCALEX, Project.GLOBAL_SCALEY);
batch.end();
This is the result:
(The character’s sprite is using the floor’s normal map.)
Binding the character’s textures after drawing the floor changes the floor’s normal map to the character’s I think.
// draw the texture unit 0 with our shader effect applied
for (int i = 0; i < 10; i++) {
for (int j = 0; j < 10; j++) {
batch.draw(floor, i * Project.GLOBAL_SCALEX, j * Project.GLOBAL_SCALEY, Project.GLOBAL_SCALEX, Project.GLOBAL_SCALEY);
}
}
world.getPlayer().getTextureNormal().bind(1);
world.getPlayer().getTexture().bind(0);
batch.draw(world.getPlayer().getTexture(), world.getPlayer().getX(), world.getPlayer().getY(), Project.GLOBAL_SCALEX, Project.GLOBAL_SCALEY);
batch.end();
Ive never used libGDX but I can put this out in terms of what i think your saying. Personally I would approach it by giving each object a shader value , then applying to a temporary image generated at run time, then drawing them all together one on top of the other with a combinelevel(); method. Im not to sure how lib GDX works but thats how I would approach it. hope it help.s