Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (494)
Games in Android Showcase (114)
games submitted by our members
Games in WIP (563)
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 3361 times)
0 Members and 1 Guest are viewing this topic.
Offline obsidian_golem

Senior Newbie




Computer programmer / Google oracle


« Posted 2012-05-21 00: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 20: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
« Reply #2 - Posted 2012-05-21 20: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!
Legends of Yore - The Casual Retro Roguelike
Offline obsidian_golem

Senior Newbie




Computer programmer / Google oracle


« Reply #3 - Posted 2012-05-21 20: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
« Reply #4 - Posted 2012-05-21 21: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 02: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 14: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-23 23: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 05: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.

 

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

The first screenshot will be displayed as a thumbnail.

Dwinin (21 views)
2014-09-12 09:08:26

Norakomi (55 views)
2014-09-10 13:57:51

TehJavaDev (65 views)
2014-09-10 06:39:09

Tekkerue (33 views)
2014-09-09 02:24:56

mitcheeb (54 views)
2014-09-08 06:06:29

BurntPizza (38 views)
2014-09-07 01:13:42

Longarmx (24 views)
2014-09-07 01:12:14

Longarmx (30 views)
2014-09-07 01:11:22

Longarmx (28 views)
2014-09-07 01:10:19

mitcheeb (36 views)
2014-09-04 23:08:59
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

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

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

HotSpot Options
by dleskov
2014-07-08 01:59:08
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!