Hi !
Featured games (84)
games approved by the League of Dukes
Games in Showcase (604)
Games in Android Showcase (171)
games submitted by our members
Games in WIP (653)
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 4195 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: 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
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: 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)?
public void render(Mesh m) {
      Matrix3 nm = makeNormalMatrix(model);
      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.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]);

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.

SHC (28 views)
2015-08-01 03:58:20

Jesse (20 views)
2015-07-29 04:35:27

Riven (40 views)
2015-07-27 16:38:00

Riven (22 views)
2015-07-27 15:35:20

Riven (24 views)
2015-07-27 12:26:13

Riven (15 views)
2015-07-27 12:23:39

BurntPizza (36 views)
2015-07-25 00:14:37

BurntPizza (46 views)
2015-07-24 22:06:39

BurntPizza (31 views)
2015-07-24 06:06:53

NoxInc (37 views)
2015-07-22 22:16:53
List of Learning Resources
by gouessej
2015-07-09 11:29:36

How Do I Expand My Game?
by bashfrog
2015-06-14 11:34:43

List of Learning Resources
by PocketCrafter7
2015-05-31 05:37:30

Intersection Methods
by Roquen
2015-05-29 08:19:33

List of Learning Resources
by SilverTiger
2015-05-05 10:20:32

How to: JGO Wiki
by Mac70
2015-02-17 20:56:16

2D Dynamic Lighting
by ThePixelPony
2015-01-01 20:25:42

How do I start Java Game Development?
by gouessej
2014-12-27 19:41:21 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‑
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!