Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (477)
Games in Android Showcase (109)
games submitted by our members
Games in WIP (536)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Normal Mapping for multiple textures  (Read 418 times)
0 Members and 1 Guest are viewing this topic.
Offline Tapestry

Junior Newbie





« Posted 2013-08-26 15:28:51 »

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.  Smiley
Offline opiop65

JGO Kernel


Medals: 153
Projects: 7
Exp: 3 years


JumpButton Studios


« Reply #1 - Posted 2013-08-26 16:39:46 »

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?

Offline Tapestry

Junior Newbie





« Reply #2 - Posted 2013-08-26 17:05:16 »

Sorry for not describing my problem better.

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:
https://github.com/mattdesl/lwjgl-basics/wiki/images/S6ElW.gif
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.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline davedes
« Reply #3 - Posted 2013-08-26 17:33:01 »

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. Smiley

Offline Tapestry

Junior Newbie





« Reply #4 - Posted 2013-08-26 18:13:28 »

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. Smiley

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:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
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.
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
      // 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();



What am I doing wrong?  Clueless
Offline lcass
« Reply #5 - Posted 2013-08-26 18:46:44 »

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
Offline Tapestry

Junior Newbie





« Reply #6 - Posted 2013-08-27 17:17:39 »

Thanks for your input lcass. That's how I'll propably do it too, I'll learn more about Frame Buffer Objects from davedes's tutorials.
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

CogWheelz (18 views)
2014-07-30 21:08:39

Riven (25 views)
2014-07-29 18:09:19

Riven (15 views)
2014-07-29 18:08:52

Dwinin (12 views)
2014-07-29 10:59:34

E.R. Fleming (33 views)
2014-07-29 03:07:13

E.R. Fleming (12 views)
2014-07-29 03:06:25

pw (43 views)
2014-07-24 01:59:36

Riven (43 views)
2014-07-23 21:16:32

Riven (30 views)
2014-07-23 21:07:15

Riven (31 views)
2014-07-23 20:56:16
List of Learning Resources
by SilverTiger
2014-07-31 18:29:50

List of Learning Resources
by SilverTiger
2014-07-31 18:26:06

List of Learning Resources
by SilverTiger
2014-07-31 13:54:12

HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!