Java-Gaming.org
Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
Featured games (78)
games approved by the League of Dukes
Games in Showcase (407)
games submitted by our members
Games in WIP (293)
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  
  Combining meshes opengl and libgdx  (Read 2115 times)
0 Members and 1 Guest are viewing this topic.
Offline obsidian_golem

Senior Newbie




Computer programmer / Google oracle


« Posted 2012-05-21 02:37:56 »

I am having some problems with lighting when combining meshes. I am creating what I call a mesh batch and creating a mesh from vertices and generated indices. My problem is that the normals seem to be wrong. Here is my mesh batch code: http://www.java-gaming.org/?action=pastebin&id=92. Vertices are passed into addmesh in the same order as the generated mesh, namely three coords, the color for that vertex, and then the normals. Why am I getting this result with my lighting? Here are some screenshots illustrating my problem:

With combined:


Without combined:

Offline obsidian_golem

Senior Newbie




Computer programmer / Google oracle


« Reply #1 - Posted 2012-05-21 22:07:45 »

Can I have some help? I really need to fix this. When I disable the combined mesh altogether the lighting looks like it does without the combined mesh.
Offline Danny02

JGO Knight


Medals: 36



« Reply #2 - Posted 2012-05-21 22:31:58 »

you do a lot, a lot!, of redudant work.
casting, copying, sorting and so on and so on.

Let me quickly clean up your code a bit, then I take a look.
Games published by our own members! Check 'em out!
Play the free demo of Revenge of the Titans!
Offline obsidian_golem

Senior Newbie




Computer programmer / Google oracle


« Reply #3 - Posted 2012-05-21 22:34:28 »

Thanks, I do prototyping first and cleanup afterwards. I like to know how to do something before I make it pretty.
Offline Danny02

JGO Knight


Medals: 36



« Reply #4 - Posted 2012-05-21 23:09:06 »

so I change a little bit in your code
here: http://www.java-gaming.org/?action=pastebin&id=96
I added some hopefully useful comments and also fixed your bug I think.

You based your index offset on the highest previous index which can be wrong.
You have to base it on the existing vertex count;
Offline obsidian_golem

Senior Newbie




Computer programmer / Google oracle


« Reply #5 - Posted 2012-05-22 04:30:58 »

Ok, different question. Is there any way that the amount of lighting on one object can effect the amount on another? If so how, and how could my a combined mesh be causing it?
Offline obsidian_golem

Senior Newbie




Computer programmer / Google oracle


« Reply #6 - Posted 2012-05-23 16:20:00 »

The vertices look good. After a bit of debugging I got this: http://www.java-gaming.org/?action=pastebin&id=97. These are the values sent into the mesh. Normals appear to be good. Can anyone see anything wrong with these? The order is 3 floats for vertices, 1 for color, and 3 more for normals. The pastebin might have cut off some of the data.
Offline obsidian_golem

Senior Newbie




Computer programmer / Google oracle


« Reply #7 - Posted 2012-05-24 01:58:59 »

Would it help if I gave Renderer.render(Mesh m)?
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  
public void render(Mesh m) {
      Matrix3 nm = makeNormalMatrix(model);
      model.idt();
      model.rotate(new Vector3(1.0f,0.0f,0.0f), xrot);
      model.rotate(new Vector3(0.0f,1.0f,0.0f), yrot);
      model.translate(new Vector3(x, y, z));
      shader.begin();
      shader.setUniformMatrix("u_pv", Camera.getInstance().get());
      shader.setUniformMatrix("u_m", model);
      shader.setUniformMatrix("u_nm", nm, true);
      float l1[],l2[],l3[],l4[];
      if(cache == null) {
         l1 = LightManager.getInstance().updateAndGetLights(0);
         l2 = LightManager.getInstance().getLights(1);
         l3 = LightManager.getInstance().getLights(2);
         l4 = LightManager.getInstance().getLights(3);
      }
      else {
         l1 = cache.asFloat(0);
         l2 = cache.asFloat(1);
         l3 = cache.asFloat(2);
         l4 = cache.asFloat(3);
      }
      //System.out.println(l1[0]+" "+l1[1]+" "+l1[2]+" "+l1[3]);
     shader.setUniformf("ulight[0]", l1[0],l1[1],l1[2],l1[3]);
      shader.setUniformf("ulight[1]", l2[0],l2[1],l2[2],l2[3]);
      shader.setUniformf("ulight[2]", l3[0],l3[1],l3[2],l3[3]);
      shader.setUniformf("ulight[3]", l4[0],l4[1],l4[2],l4[3]);
      m.render(shader,GL10.GL_TRIANGLES);
      shader.end();
   }

Basicly it binds the shader, sets a few attributes and uniforms, and renders it. LightCache is a cached version of the 4 closest lights.
Offline obsidian_golem

Senior Newbie




Computer programmer / Google oracle


« Reply #8 - Posted 2012-05-24 07:06:37 »

I seem to have fixed it. By rendering the tiles as meshbatches the rendering seems to work. Can anyone guess how this works?
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
 
Browse for soundtracks for your game!

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

The first screenshot will be displayed as a thumbnail.

The invasion has landed! On Mars! And you're there to beat 'em!
cubemaster21 (88 views)
2013-05-17 21:29:12

alaslipknot (96 views)
2013-05-16 21:24:48

gouessej (128 views)
2013-05-16 00:53:38

gouessej (123 views)
2013-05-16 00:17:58

theagentd (130 views)
2013-05-15 15:01:13

theagentd (118 views)
2013-05-15 15:00:54

StreetDoggy (161 views)
2013-05-14 15:56:26

kutucuk (184 views)
2013-05-12 17:10:36

kutucuk (185 views)
2013-05-12 15:36:09

UnluckyDevil (191 views)
2013-05-12 05:09:57
Complex number cookbook
by Roquen
2013-04-24 12:47:31

2D Dynamic Lighting
by Oskuro
2013-04-17 16:46:12

2D Dynamic Lighting
by Oskuro
2013-04-17 16:45:57

2D Dynamic Lighting
by Oskuro
2013-04-17 16:23:20

Noise (bandpassed white)
by Roquen
2013-04-05 17:36:01

Noise (bandpassed white)
by Roquen
2013-04-03 16:17:38

Java Data structures
by Roquen
2013-03-29 13:21:12

Topic Request
by kutucuk
2013-03-22 21:42:01
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!
Page created in 0.153 seconds with 21 queries.