Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - AeroShark333

Pages: 1 2 [3] 4 5 ... 22
31
Support / Re: Lighting on merged Object3Ds
« on: December 14, 2021, 08:38:00 pm »
I changed the code to your suggestions (see below):

Here are the animations:
https://imgur.com/a/Jk8zt2g
https://imgur.com/a/Zwxem7I

Code:
Code: [Select]
final GLSurfaceView.Renderer testRenderer = new GLSurfaceView.Renderer() {
                private FrameBuffer frameBuffer;
                private World world;
                private Object3D master;
                private Object3D plane1;
                private Object3D plane2;
                private Object3D plane3;
                private Camera camera;

                @Override
                public void onSurfaceCreated(GL10 gl10, EGLConfig eglConfig) {

                }

                @Override
                public void onSurfaceChanged(GL10 gl10, int w, int h) {
                    Config.nearPlane = 1f;
                    Config.glIgnoreNearPlane = false;

                    frameBuffer = new FrameBuffer(w, h);
                    world = new World();
                    world.setAmbientLight(0, 0, 0);
                    Light l1 = new Light(world);
                    l1.setPosition(new SimpleVector(0f, 6f, 0f));
                    camera = world.getCamera();

                    final Texture sphereTexture = new Texture(2, 2, new RGBColor(75, 0, 0));
                    final Texture overlayTexture = new Texture(2, 2, new RGBColor(0, 0, 75));
                    final Texture planeTexture = new Texture(2, 2, new RGBColor(0, 75, 0));

                    final TextureManager textureManager = TextureManager.getInstance();
                    textureManager.addTexture("tex0", sphereTexture);
                    textureManager.addTexture("tex1", overlayTexture);
                    textureManager.addTexture("tex2", planeTexture);

                    master = Object3D.createDummyObj();

                    plane1 = new Object3D(4);
                    plane2 = new Object3D(8);
                    plane3 = new Object3D(8);

                    plane1.addTriangle(new SimpleVector(-5.55, -0.941941941, -1.0), 0.0f, 0.0f, new SimpleVector(-5.55, -0.941941941, 1.0), 0.0f, 1.0f, new SimpleVector(5.55, -0.941941941, -1.0), 1.0f, 0.0f);
                    plane1.addTriangle(new SimpleVector(5.55, -0.941941941, 1.0), 1.0f, 1.0f, new SimpleVector(5.55, -0.941941941, -1.0), 1.0f, 0.0f, new SimpleVector(-5.55, -0.941941941, 1.0), 0.0f, 1.0f);
                    //roadMaster.setAdditionalColor(100, 100, 100);

                    //plane1.setAdditionalColor(100, 100, 100);
                    //plane1.compile(false, true);
                    //plane1.strip();
                    //plane1.build();
                    plane1.setTexture("tex0");

                    plane2.addTriangle(new SimpleVector(-6.6, - 0.9, -1.02), 0.5f, 0.0f, new SimpleVector(-6.6, - 0.9, 1.02), 0.5f, 1.0f, new SimpleVector(-5.55, - 0.9, -1.02), 1.0f, 0.0f);
                    plane2.addTriangle(new SimpleVector(-5.55, - 0.9, 1.02), 1.0f, 1.0f, new SimpleVector(-5.55, - 0.9, -1.02), 1.0f, 0.0f, new SimpleVector(-6.6, - 0.9, 1.02), 0.5f, 1.0f);
                    plane2.addTriangle(new SimpleVector(5.55, - 0.9, -1.02), 0.0f, 0.0f, new SimpleVector(5.55, - 0.9, 1.02), 0.0f, 1.0f, new SimpleVector(6.6, - 0.9, -1.02), 0.5f, 0.0f);
                    plane2.addTriangle(new SimpleVector(6.6, - 0.9, 1.02), 0.5f, 1.0f, new SimpleVector(6.6, - 0.9, -1.02), 0.5f, 0.0f, new SimpleVector(5.55, - 0.9, 1.02), 0.0f, 1.0f);

                    //plane2.setAdditionalColor(100, 100, 100);
                    //plane2.compile(false, true);
                    //plane2.strip();
                    //plane2.build();
                    plane2.setTexture("tex1");

                    float heightMultiplier = 333f;
                    float lastHeightLeft = 0.03f;
                    float newHeightLeft = 0.024f;
                    float newHeightRight = 0.012f;
                    float lastHeightRight = 0.01f;

                    // base

                    //plane3.setAdditionalColor(100, 100, 100);
                    plane3.addTriangle(new SimpleVector(-11.4f, lastHeightLeft * heightMultiplier / 3f, -1.02), 0.5f, 0.0f, new SimpleVector(-11.4f, newHeightLeft * heightMultiplier / 3f, 1.02), 0.5f, 1.0f, new SimpleVector(-6.6f, -0.941941941, -1.02), 1.0f, 0.0f);
                    plane3.addTriangle(new SimpleVector(-6.6f, -0.941941941, 1.02), 1.0f, 1.0f, new SimpleVector(-6.6f, -0.941941941, -1.02), 1.0f, 0.0f, new SimpleVector(-11.4f, newHeightLeft * heightMultiplier / 3f, 1.02), 0.5f, 1.0f);
                    plane3.addTriangle(new SimpleVector(6.6f, -0.941941941, -1.02), 0.0f, 0.0f, new SimpleVector(6.6f, -0.941941941, 1.02), 0.0f, 1.0f, new SimpleVector(11.4f, lastHeightRight * heightMultiplier / 3f, -1.02), 0.5f, 0.0f);
                    plane3.addTriangle(new SimpleVector(11.4f, newHeightRight * heightMultiplier / 3f, 1.02), 0.5f, 1.0f, new SimpleVector(11.4f, lastHeightRight * heightMultiplier / 3f, -1.02), 0.5f, 0.0f, new SimpleVector(6.6f, -0.941941941, 1.02), 0.0f, 1.0f);
                    plane3.setTexture("tex2");
                    //plane3.build();

                    boolean merge = false;

                    if(merge){
                        Object3D mergeObj = Object3D.mergeObjects(plane1, plane2);
                        mergeObj = Object3D.mergeObjects(plane3, mergeObj);
                        //mergeObj.setAdditionalColor(100, 100, 100);
                        mergeObj.build();
                        mergeObj.compile(false, true);
                        mergeObj.strip();
                        world.addObject( mergeObj);
                    }else {
                        world.addObject(plane1);
                        world.addObject(plane2);
                        world.addObject(plane3);

                        Object3D mergeObj = Object3D.mergeObjects(plane1, plane2);
                        mergeObj = Object3D.mergeObjects(plane3, mergeObj);
                        world.addObject( mergeObj);
                        //mergeObj.setAdditionalColor(100, 100, 100);
                        mergeObj.translate(0,0,3f);
                        plane1.translate(0,0,-3f);
                        plane2.translate(0,0,-3f);
                        plane3.translate(0,0,-3f);
                    }
                }

                @Override
                public void onDrawFrame(GL10 gl10) {
                    frameBuffer.clear();
                    final float maxDistance = 150f;
                    camera.setPosition(-(0.5f * ((float) Math.abs(Math.cos(world.getFrameCounter() * 0.03f))) + 0.25f) * maxDistance, 30f, 0f);
                    camera.lookAt(new SimpleVector(0,4.5f,0));
                    world.renderScene(frameBuffer);
                    world.draw(frameBuffer);
                    frameBuffer.display();
                }
            };

            // Attach to some GLSurfaceView...
            viewer.setRenderer(testRenderer);

If I do:
Code: [Select]
plane2.setTexture("tex2");the problem disappears..?  ???

32
Support / Re: Lighting on merged Object3Ds
« on: December 12, 2021, 04:32:09 am »
Actually, if the normals have been calculated (or loaded from file with Config.useNormalsFromOBJ=true) already before merging, they won't be recalculated after the merge when you call build on the merged object. I'm not sure if your issue is related to merging at all, though. I rather think it's caused by normal vectors that aren't calculated in a why that fits your scene. Does the file from which these objects come includes normals? In that case, you could try the config switch mentioned above.
I'm not using models from files, but I create them using Object3D#addTriangle (as they are simple planes sort of...)
I don't think the Config switch would do anything for this...

I was able to create a test case, however... (it doesn't look amazing but it shows the problem I guess...)
Code: [Select]
final GLSurfaceView.Renderer testRenderer = new GLSurfaceView.Renderer() {
                private FrameBuffer frameBuffer;
                private World world;
                private Object3D master;
                private Object3D plane1;
                private Object3D plane2;
                private Object3D plane3;
                private Camera camera;

                @Override
                public void onSurfaceCreated(GL10 gl10, EGLConfig eglConfig) {

                }

                @Override
                public void onSurfaceChanged(GL10 gl10, int w, int h) {
                    Config.nearPlane = 1f;
                    Config.glIgnoreNearPlane = false;

                    frameBuffer = new FrameBuffer(w, h);
                    world = new World();
                    world.setAmbientLight(0, 0, 0);
                    Light l1 = new Light(world);
                    l1.setPosition(new SimpleVector(0f, 6f, 0f));
                    camera = world.getCamera();

                    final Texture sphereTexture = new Texture(2, 2, new RGBColor(75, 0, 0));
                    final Texture overlayTexture = new Texture(2, 2, new RGBColor(0, 0, 75));
                    final Texture planeTexture = new Texture(2, 2, new RGBColor(0, 75, 0));

                    final TextureManager textureManager = TextureManager.getInstance();
                    textureManager.addTexture("tex0", sphereTexture);
                    textureManager.addTexture("tex1", overlayTexture);
                    textureManager.addTexture("tex2", planeTexture);

                    master = Object3D.createDummyObj();

                    plane1 = new Object3D(4);
                    plane2 = new Object3D(8);
                    plane3 = new Object3D(8);

                    plane1.addTriangle(new SimpleVector(-5.55, -0.941941941, -1.0), 0.0f, 0.0f, new SimpleVector(-5.55, -0.941941941, 1.0), 0.0f, 1.0f, new SimpleVector(5.55, -0.941941941, -1.0), 1.0f, 0.0f);
                    plane1.addTriangle(new SimpleVector(5.55, -0.941941941, 1.0), 1.0f, 1.0f, new SimpleVector(5.55, -0.941941941, -1.0), 1.0f, 0.0f, new SimpleVector(-5.55, -0.941941941, 1.0), 0.0f, 1.0f);
                    //roadMaster.setAdditionalColor(100, 100, 100);

                    plane1.setAdditionalColor(100, 100, 100);
                    plane1.compile(false, true);
                    plane1.strip();
                    plane1.build();
                    plane1.setTexture("tex0");

                    plane2.addTriangle(new SimpleVector(-6.6, -0.939, -1.02), 0.5f, 0.0f, new SimpleVector(-6.6, -0.939, 1.02), 0.5f, 1.0f, new SimpleVector(-5.55, -0.941941941, -1.02), 1.0f, 0.0f);
                    plane2.addTriangle(new SimpleVector(-5.55, -0.941941941, 1.02), 1.0f, 1.0f, new SimpleVector(-5.55, -0.941941941, -1.02), 1.0f, 0.0f, new SimpleVector(-6.6, -0.939, 1.02), 0.5f, 1.0f);
                    plane2.addTriangle(new SimpleVector(5.55, -0.941941941, -1.02), 0.0f, 0.0f, new SimpleVector(5.55, -0.941941941, 1.02), 0.0f, 1.0f, new SimpleVector(6.6, -0.939, -1.02), 0.5f, 0.0f);
                    plane2.addTriangle(new SimpleVector(6.6, -0.939, 1.02), 0.5f, 1.0f, new SimpleVector(6.6, -0.939, -1.02), 0.5f, 0.0f, new SimpleVector(5.55, -0.941941941, 1.02), 0.0f, 1.0f);

                    plane2.setAdditionalColor(100, 100, 100);
                    plane2.compile(false, true);
                    plane2.strip();
                    plane2.build();
                    plane2.setTexture("tex1");

                    float heightMultiplier = 333f;
                    float lastHeightLeft = 0.03f;
                    float newHeightLeft = 0.024f;
                    float newHeightRight = 0.012f;
                    float lastHeightRight = 0.01f;

                    // base

                    plane3.setAdditionalColor(100, 100, 100);
                    plane3.addTriangle(new SimpleVector(-11.4f, lastHeightLeft * heightMultiplier / 3f, -1.02), 0.5f, 0.0f, new SimpleVector(-11.4f, newHeightLeft * heightMultiplier / 3f, 1.02), 0.5f, 1.0f, new SimpleVector(-6.6f, -0.939, -1.02), 1.0f, 0.0f);
                    plane3.addTriangle(new SimpleVector(-6.6f, -0.939, 1.02), 1.0f, 1.0f, new SimpleVector(-6.6f, -0.939, -1.02), 1.0f, 0.0f, new SimpleVector(-11.4f, newHeightLeft * heightMultiplier / 3f, 1.02), 0.5f, 1.0f);
                    plane3.addTriangle(new SimpleVector(6.6f, -0.939, -1.02), 0.0f, 0.0f, new SimpleVector(6.6f, -0.939, 1.02), 0.0f, 1.0f, new SimpleVector(11.4f, lastHeightRight * heightMultiplier / 3f, -1.02), 0.5f, 0.0f);
                    plane3.addTriangle(new SimpleVector(11.4f, newHeightRight * heightMultiplier / 3f, 1.02), 0.5f, 1.0f, new SimpleVector(11.4f, lastHeightRight * heightMultiplier / 3f, -1.02), 0.5f, 0.0f, new SimpleVector(6.6f, -0.939, 1.02), 0.0f, 1.0f);
                    plane3.setTexture("tex2");
                    plane3.build();

                    boolean merge = false;

                    if(merge){
                        Object3D mergeObj = Object3D.mergeObjects(plane1, plane2);
                        mergeObj = Object3D.mergeObjects(plane3, mergeObj);
                        world.addObject( mergeObj);
                    }else {
                        world.addObject(plane1);
                        world.addObject(plane2);
                        world.addObject(plane3);

                        Object3D mergeObj = Object3D.mergeObjects(plane1, plane2);
                        mergeObj = Object3D.mergeObjects(plane3, mergeObj);
                        world.addObject( mergeObj);
                        mergeObj.setSpecularLighting(false);
                        mergeObj.translate(0,0,3f);
                    }
                }

                @Override
                public void onDrawFrame(GL10 gl10) {
                    frameBuffer.clear();
                    final float maxDistance = 150f;
                    camera.setPosition(-(0.5f * ((float) Math.abs(Math.cos(world.getFrameCounter() * 0.03f))) + 0.25f) * maxDistance, 30f, 0f);
                    camera.lookAt(new SimpleVector(0,0,0));
                    world.renderScene(frameBuffer);
                    world.draw(frameBuffer);
                    frameBuffer.display();
                }
            };

            // Attach to some GLSurfaceView...
            viewer.setRenderer(testRenderer);

Results: https://imgur.com/a/KffOw9m (left = merged object, right = not merged objects)
The first two images show the same but at a slightly different camera distance/angle, and you can see that the green tile on the left object is slightly darker than the in the second image.
In the last image, you can see some shading pattern on the red and green on the left object.

These do share coordinates however... maybe that nullifies the build() effect...

EDIT:
Okay... apparently it still happens when the coordinates are NOT shared...
So now I don't understand why build() didn't work...

Code snippet for non-sharing coordinates (replace these lines in the test case...):
Code: [Select]
plane2.addTriangle(new SimpleVector(-6.6, - 0.9, -1.02), 0.5f, 0.0f, new SimpleVector(-6.6, - 0.9, 1.02), 0.5f, 1.0f, new SimpleVector(-5.55, - 0.9, -1.02), 1.0f, 0.0f);
                    plane2.addTriangle(new SimpleVector(-5.55, - 0.9, 1.02), 1.0f, 1.0f, new SimpleVector(-5.55, - 0.9, -1.02), 1.0f, 0.0f, new SimpleVector(-6.6, - 0.9, 1.02), 0.5f, 1.0f);
                    plane2.addTriangle(new SimpleVector(5.55, - 0.9, -1.02), 0.0f, 0.0f, new SimpleVector(5.55, - 0.9, 1.02), 0.0f, 1.0f, new SimpleVector(6.6, - 0.9, -1.02), 0.5f, 0.0f);
                    plane2.addTriangle(new SimpleVector(6.6, - 0.9, 1.02), 0.5f, 1.0f, new SimpleVector(6.6, - 0.9, -1.02), 0.5f, 0.0f, new SimpleVector(5.55, - 0.9, 1.02), 0.0f, 1.0f);

                    plane2.setAdditionalColor(100, 100, 100);
                    plane2.compile(false, true);
                    plane2.strip();
                    plane2.build();
                    plane2.setTexture("tex1");

                    float heightMultiplier = 333f;
                    float lastHeightLeft = 0.03f;
                    float newHeightLeft = 0.024f;
                    float newHeightRight = 0.012f;
                    float lastHeightRight = 0.01f;

                    // base

                    plane3.setAdditionalColor(100, 100, 100);
                    plane3.addTriangle(new SimpleVector(-11.4f, lastHeightLeft * heightMultiplier / 3f, -1.02), 0.5f, 0.0f, new SimpleVector(-11.4f, newHeightLeft * heightMultiplier / 3f, 1.02), 0.5f, 1.0f, new SimpleVector(-6.6f, -0.941941941, -1.02), 1.0f, 0.0f);
                    plane3.addTriangle(new SimpleVector(-6.6f, -0.941941941, 1.02), 1.0f, 1.0f, new SimpleVector(-6.6f, -0.941941941, -1.02), 1.0f, 0.0f, new SimpleVector(-11.4f, newHeightLeft * heightMultiplier / 3f, 1.02), 0.5f, 1.0f);
                    plane3.addTriangle(new SimpleVector(6.6f, -0.941941941, -1.02), 0.0f, 0.0f, new SimpleVector(6.6f, -0.941941941, 1.02), 0.0f, 1.0f, new SimpleVector(11.4f, lastHeightRight * heightMultiplier / 3f, -1.02), 0.5f, 0.0f);
                    plane3.addTriangle(new SimpleVector(11.4f, newHeightRight * heightMultiplier / 3f, 1.02), 0.5f, 1.0f, new SimpleVector(11.4f, lastHeightRight * heightMultiplier / 3f, -1.02), 0.5f, 0.0f, new SimpleVector(6.6f, -0.941941941, 1.02), 0.0f, 1.0f);
                    plane3.setTexture("tex2");
                    plane3.build();

EDIT2: I forgot to set the additionalColor on the merged object... Just forget everything above...
Here is a test case without any additionalColor:
Code: [Select]
final GLSurfaceView.Renderer testRenderer = new GLSurfaceView.Renderer() {
                private FrameBuffer frameBuffer;
                private World world;
                private Object3D master;
                private Object3D plane1;
                private Object3D plane2;
                private Object3D plane3;
                private Camera camera;

                @Override
                public void onSurfaceCreated(GL10 gl10, EGLConfig eglConfig) {

                }

                @Override
                public void onSurfaceChanged(GL10 gl10, int w, int h) {
                    Config.nearPlane = 1f;
                    Config.glIgnoreNearPlane = false;

                    frameBuffer = new FrameBuffer(w, h);
                    world = new World();
                    world.setAmbientLight(0, 0, 0);
                    Light l1 = new Light(world);
                    l1.setPosition(new SimpleVector(0f, 6f, 0f));
                    camera = world.getCamera();

                    final Texture sphereTexture = new Texture(2, 2, new RGBColor(75, 0, 0));
                    final Texture overlayTexture = new Texture(2, 2, new RGBColor(0, 0, 75));
                    final Texture planeTexture = new Texture(2, 2, new RGBColor(0, 75, 0));

                    final TextureManager textureManager = TextureManager.getInstance();
                    textureManager.addTexture("tex0", sphereTexture);
                    textureManager.addTexture("tex1", overlayTexture);
                    textureManager.addTexture("tex2", planeTexture);

                    master = Object3D.createDummyObj();

                    plane1 = new Object3D(4);
                    plane2 = new Object3D(8);
                    plane3 = new Object3D(8);

                    plane1.addTriangle(new SimpleVector(-5.55, -0.941941941, -1.0), 0.0f, 0.0f, new SimpleVector(-5.55, -0.941941941, 1.0), 0.0f, 1.0f, new SimpleVector(5.55, -0.941941941, -1.0), 1.0f, 0.0f);
                    plane1.addTriangle(new SimpleVector(5.55, -0.941941941, 1.0), 1.0f, 1.0f, new SimpleVector(5.55, -0.941941941, -1.0), 1.0f, 0.0f, new SimpleVector(-5.55, -0.941941941, 1.0), 0.0f, 1.0f);
                    //roadMaster.setAdditionalColor(100, 100, 100);

                    //plane1.setAdditionalColor(100, 100, 100);
                    plane1.compile(false, true);
                    plane1.strip();
                    plane1.build();
                    plane1.setTexture("tex0");

                    plane2.addTriangle(new SimpleVector(-6.6, - 0.9, -1.02), 0.5f, 0.0f, new SimpleVector(-6.6, - 0.9, 1.02), 0.5f, 1.0f, new SimpleVector(-5.55, - 0.9, -1.02), 1.0f, 0.0f);
                    plane2.addTriangle(new SimpleVector(-5.55, - 0.9, 1.02), 1.0f, 1.0f, new SimpleVector(-5.55, - 0.9, -1.02), 1.0f, 0.0f, new SimpleVector(-6.6, - 0.9, 1.02), 0.5f, 1.0f);
                    plane2.addTriangle(new SimpleVector(5.55, - 0.9, -1.02), 0.0f, 0.0f, new SimpleVector(5.55, - 0.9, 1.02), 0.0f, 1.0f, new SimpleVector(6.6, - 0.9, -1.02), 0.5f, 0.0f);
                    plane2.addTriangle(new SimpleVector(6.6, - 0.9, 1.02), 0.5f, 1.0f, new SimpleVector(6.6, - 0.9, -1.02), 0.5f, 0.0f, new SimpleVector(5.55, - 0.9, 1.02), 0.0f, 1.0f);

                    //plane2.setAdditionalColor(100, 100, 100);
                    plane2.compile(false, true);
                    plane2.strip();
                    plane2.build();
                    plane2.setTexture("tex1");

                    float heightMultiplier = 333f;
                    float lastHeightLeft = 0.03f;
                    float newHeightLeft = 0.024f;
                    float newHeightRight = 0.012f;
                    float lastHeightRight = 0.01f;

                    // base

                    //plane3.setAdditionalColor(100, 100, 100);
                    plane3.addTriangle(new SimpleVector(-11.4f, lastHeightLeft * heightMultiplier / 3f, -1.02), 0.5f, 0.0f, new SimpleVector(-11.4f, newHeightLeft * heightMultiplier / 3f, 1.02), 0.5f, 1.0f, new SimpleVector(-6.6f, -0.941941941, -1.02), 1.0f, 0.0f);
                    plane3.addTriangle(new SimpleVector(-6.6f, -0.941941941, 1.02), 1.0f, 1.0f, new SimpleVector(-6.6f, -0.941941941, -1.02), 1.0f, 0.0f, new SimpleVector(-11.4f, newHeightLeft * heightMultiplier / 3f, 1.02), 0.5f, 1.0f);
                    plane3.addTriangle(new SimpleVector(6.6f, -0.941941941, -1.02), 0.0f, 0.0f, new SimpleVector(6.6f, -0.941941941, 1.02), 0.0f, 1.0f, new SimpleVector(11.4f, lastHeightRight * heightMultiplier / 3f, -1.02), 0.5f, 0.0f);
                    plane3.addTriangle(new SimpleVector(11.4f, newHeightRight * heightMultiplier / 3f, 1.02), 0.5f, 1.0f, new SimpleVector(11.4f, lastHeightRight * heightMultiplier / 3f, -1.02), 0.5f, 0.0f, new SimpleVector(6.6f, -0.941941941, 1.02), 0.0f, 1.0f);
                    plane3.setTexture("tex2");
                    plane3.build();

                    boolean merge = false;

                    if(merge){
                        Object3D mergeObj = Object3D.mergeObjects(plane1, plane2);
                        mergeObj = Object3D.mergeObjects(plane3, mergeObj);
                        //mergeObj.setAdditionalColor(100, 100, 100);
                        world.addObject( mergeObj);
                    }else {
                        world.addObject(plane1);
                        world.addObject(plane2);
                        world.addObject(plane3);

                        Object3D mergeObj = Object3D.mergeObjects(plane1, plane2);
                        mergeObj = Object3D.mergeObjects(plane3, mergeObj);
                        world.addObject( mergeObj);
                        //mergeObj.setAdditionalColor(100, 100, 100);
                        mergeObj.translate(0,0,3f);
                        plane1.translate(0,0,-3f);
                        plane2.translate(0,0,-3f);
                        plane3.translate(0,0,-3f);
                    }
                }

                @Override
                public void onDrawFrame(GL10 gl10) {
                    frameBuffer.clear();
                    final float maxDistance = 150f;
                    camera.setPosition(-(0.5f * ((float) Math.abs(Math.cos(world.getFrameCounter() * 0.03f))) + 0.25f) * maxDistance, 30f, 0f);
                    camera.lookAt(new SimpleVector(0,0,0));
                    world.renderScene(frameBuffer);
                    world.draw(frameBuffer);
                    frameBuffer.display();
                }
            };

            // Attach to some GLSurfaceView...
            viewer.setRenderer(testRenderer);

EDIT3: An animated image for the last test case: https://imgur.com/a/wR8MqgG
I believe I get similar-ish results but it gets brighter for me randomly but I guess it's a similar idea

EDIT4: I have a slight feeling this issue is there because the merged Object3D is multi-textured..? I'm not entirely sure...
The issue seems to disappear if it has 1 or 2 different textures only (but when you add the third, the lighting seems to behave differently)

33
Support / Re: Lighting on merged Object3Ds
« on: December 10, 2021, 10:01:04 pm »
Each object will be lit by itself, no matter how they overlap with each other. Regarding the lighting, they are completely independant. Maybe it's just caused by way in which the normals are created? A vertex normal is calculated by taking the face normals of the adjacent polygons and averaging them. If you, for example, stack boxes onto another the normals on the lower corners will face something like 45° down while the ones on the upper corners will face 45° up. That will cause uneven lighting on something like a wall that consists of these boxes.
Is it possible to merge Object3D's without these vertices being combined (or normals being recalculated) but instead literally keep the original meshes and add them together (non-optimized), so that the normals stay as the original Object3D's? (if this makes sense)

34
Support / Re: Lighting on merged Object3Ds
« on: December 08, 2021, 03:22:34 pm »
Are these meshes sharing coordinates?
No, but they are usually very close (almost negligible), though probably they don't get merged to be using them as the same coordinates as they are still slightly different.

You might want to try to call build() on the objects before merging them and not afterwards to see if that helps.
This didn't work

I fixed part of the issue by making them share coordinates (I believe the overlap makes the lower layer 'unlit..'..? or something)
But I still have the lighting issue for some other parts (but these appear too bright..? for unknown reason, they also flicker)

EDIT: Images for clarification: https://imgur.com/a/FYNF3Wm
It might not seem like a lot in the images, but it flickers from dark to bright so it is very noticable in that way

35
Support / Re: ShadowHelper and special Textures
« on: December 08, 2021, 03:08:56 pm »
Is it Helge Foerster who made the engine?

I've decided to send a mail to the info address instead with these questions.

Thanks again :)
Seems so... https://www.jpct.net/imprint.html
Most likely also the very person you've been talking with hehe

Thanks a bunch for all the help and support, and the engine is wonderful by the way I think I've never mentioned it before.
Is there somewhere I can read of how, when and why the engine came to be? It would be very interesting to read and know more about the background, there's a lot of information about it to read but I donīt think I've seen anything about that.
Would be interesting to know indeed

36
Support / Lighting on merged Object3Ds
« on: December 03, 2021, 01:37:22 am »
Hello again,

I'm having some lighting issues when using Object3D.mergeObjects(obj1, obj2)

See image: https://imgur.com/a/aIF67LC

I believe the main cause of this is that the Object3D's overlap..?
(road and the dirt on the side are different layers for instance, at slightly different heights (dirt layer is above road layer).
When rendering it as separate Object3D's the issue is not there.

Any way to solve this without having to flatten the layers in height? I believe the merging of Object3D's messes up the normal vectors or something..? Can this be prevented so it renders similarly as if it were two separate Object3D's?

I'm having similar issues when merging other parts of the scene. Sometimes things appear too bright, sometimes there's dark areas.
It was worse like this before https://imgur.com/a/kfvdjI8 (because one Object3D accidentally had setTransparency, affecting the final merged Object3D...) Removing setTransparency improves it but sometimes there's still random brightly lit parts in the scene.. I wish to get the same visual results as if it was not merged. (Merging seems to boost FPS so that's why..)

Cheers :)

Note:
sideview of road:
Code: [Select]
dirt layer:   ____________                                _____________
road layer:          -----------------------------------------

37
Support / Re: Are merged Object3D able to have shared submeshes?
« on: November 24, 2021, 02:10:10 pm »
This is the code of setDepth():

Code: [Select]
public void setDepth(float depth) {
if (depth < Config.nearPlane) {
depth = Config.nearPlane + 1f;
}
this.depth = depth;
}

As you can see, setting it to -infinity has no effect other than setting the depth to Config.nearPlane + 1f
Hmmm, okay...

Another idea: Split scene and overlay in two different world instances and render them one after the other with a z-buffer clear in between...
This does work without any issues.
I thought the renderhook solution should have worked as well, but apparently not..?
I did make sure it got called.

Anyway, I guess this will do for now.
Thank you for the support and help :D

38
Support / Re: Are merged Object3D able to have shared submeshes?
« on: November 20, 2021, 02:41:26 pm »
If you set Config.glIgnoreNearPlane, the value set for the near plane won't be used. The default (1) will be used instead. If you combine that with your overlay and the fact that you've set the near plane to 0 (which usually is too close btw), you will end up with a near plane of 1 for the scene and a depth of (0+1) for the overlay as well. I'm surprised that it shows up at all.
Hmmm okay...

Try to set Config.glIgnoreNearPlane to false and see if that changes anything. And, as said, 0 as the near plane is too close. Try some higher value instead.
I set Config.glIgnoreNearPlane to false and I varied the near plane value between 0.5f and 3f... Still no luck...
I thought it'd work for values higher than 1f, since the default value is 1f according to documentations... but apparently it doesn't work still..?

That said, if the overlay is transparent it won't write into the depth buffer, which can lead to objects drawn later to be painted over it. If you set it to opaque, the depth buffer will handle the overdraw and in turn avoid the problem. You can try to change the sort order of the overlay to make it render after everything else:

  • use Oyerlay.getObject3D() to get the internal Object3D from the overlay
  • call setZSortOffset(-xxxx) with xxxx being a large value on the Object3D of the overlay

That should, in theory, change the overlays sorting so that is will be rendered after everything else.
I tried this using:
Code: [Select]
overlay.getObject3D().setSortOffset(-3E33f);but still no luck. This is one of the first things I tried too when trying to solve this issue... positive values seem to affect it, negative values don't..?

This can be replicated with the test case that I provided before with minor changes:
- adding the setSortOffset
- removing any Config changes
- keeping clearZBufferOnly()
But none of these seem to help..?

Something that does seem to 'fix it' (not entirely sure if it completely fixes it but it seems so visually) is:
overlay.setDepth(Float.NEGATIVE_INFINITY);
But I wouldn't be able to explain how or why if you say the depth should be capped by nearPlane..?
Now values such as 0f, 1f and 2f seem to work too for the setDepth method..?
I wonder if the depth is initialized properly to begin with.. which I assume it to be 2f by default if I understood your last post properly?
Around 3f, it will start clipping through again which makes me think that the depth is already too large by default..? (probably >3f or something by default..?)

EDIT: I believe I found something that might cause the flickering effect with setDepth(...):
When the Object3D's are close, the floating point precision is probably high enough to order the Overlay on top of it still.
But when the camera is further away, the floating point precision might not be high enough (basically causing the overlay and Object3D to have equal z-depths) and giving priority to the Object3Ds sometimes rather than the Overlay (causing flickering).
But I find that weird since the Object3D's are further away..?
What I could do then, is to increase the nearPlane depth... but then the clipping will start happening again.
Let's say I use setDepth(0f) on the overlays:
Bringing Config.nearPlane to 0 will remove the clipping but introduce flickering. Increasing Config.nearPlane will increase clipping but remove flickering... Seems like some trade-off thing to me.
Config.nearPlane = 1E-6f; has too much flickering
Config.nearPlane = 1E-1f; has too much clipping
Config.nearPlane = 1E-3f; seems to work best so far...

39
Support / Re: Are merged Object3D able to have shared submeshes?
« on: November 19, 2021, 06:37:11 pm »
Yes, I did make sure that the RenderHook implementation gets called, I double checked with a "System.out.println("ok");" which flooded the logcat.
In my scene, the overlay is transparent itself, but most of the objects in the scene are not... So I don't think that is the issue...
But maybe the transparency of the overlay itself causes issues...
The "Config.nearPlane = 0f" in my scene and I also use "Config.glIgnoreNearPlane = true"... I'm not sure how or if the nearPlane value is used if it's ignored..?

A test case... (I hope this is complete enough..?)
So... as I said before, I believe the culprit might be that the Overlay is transparent... Without transparency, there's no such issue with the clipping.
Code: [Select]
    final GLSurfaceView.Renderer testRenderer = new GLSurfaceView.Renderer() {
            private FrameBuffer frameBuffer;
            private World world;
            private Overlay overlay;
            private Object3D sphere;
            private Camera camera;

            @Override
            public void onSurfaceCreated(GL10 gl10, EGLConfig eglConfig) {

            }

            @Override
            public void onSurfaceChanged(GL10 gl10, int w, int h) {
                Config.nearPlane = 0.0f;
                Config.glIgnoreNearPlane = true;

                frameBuffer = new FrameBuffer(w, h);
                world = new World();
                camera = world.getCamera();

                final Texture sphereTexture = new Texture(2, 2, new RGBColor(75, 0, 0));
                final Texture overlayTexture = new Texture(2, 2, new RGBColor(0, 0, 75));

                final TextureManager textureManager = TextureManager.getInstance();
                textureManager.addTexture("tex0", sphereTexture);
                textureManager.addTexture("tex1", overlayTexture);

                sphere = Primitives.getSphere(1.0f);
                sphere.setTexture("tex0");
                sphere.strip();
                sphere.build();
                world.addObject(sphere);

                overlay = new Overlay(world, 0, 0, frameBuffer.getWidth(), frameBuffer.getHeight() / 2, "tex1");
                // I believe this line below is the culprit; without it, things seem fine...
                overlay.setTransparency(255);
                // Gone..?
                //overlay.setDepth(0f);
                // Fixed..?
                //overlay.setDepth(Float.NEGATIVE_INFINITY);
                // Not fixed..?
                //overlay.setDepth(-3E33f);
                overlay.getObject3D().setRenderHook(new IRenderHook() {
                    @Override
                    public void beforeRendering(int i) {
                        frameBuffer.clearZBufferOnly();
                        // check that it gets called
                        overlay.setRotation(((float)Math.random())*0.01f);
                    }

                    @Override
                    public void afterRendering(int i) {

                    }

                    @Override
                    public void setCurrentObject3D(Object3D object3D) {

                    }

                    @Override
                    public void setCurrentShader(GLSLShader glslShader) {

                    }

                    @Override
                    public void setTransparency(float v) {

                    }

                    @Override
                    public void onDispose() {

                    }

                    @Override
                    public boolean repeatRendering() {
                        return false;
                    }
                });
            }

            @Override
            public void onDrawFrame(GL10 gl10) {
                frameBuffer.clear();
                final float maxDistance = 7.5f;
                camera.setPosition(0f, 0f, -(0.5f * ((float) Math.abs(Math.cos(world.getFrameCounter() * 0.03f))) + 0.5f) * maxDistance);
                world.renderScene(frameBuffer);
                world.draw(frameBuffer);
                frameBuffer.display();
            }
        };

        // Attach to some GLSurfaceView here...
        viewer.setRenderer(testRenderer);

Thanks for the tips, I'll keep that in mind!  ;D

40
There is one, just not in the way in which you expect it to be. What you have to do is to grab the information you need from the various methods in the PolygonManager, create a TextureInfo-Instance from these and assign it to the polygon by using setPolygonTexture(). This code from the wiki has an example of that in the setTexture()-method where I'm tiling a terrain texture: https://www.jpct.net/wiki/index.php?title=Texture_splatting_on_a_terrain
Ah... yes, I forgot TextureInfo holds UV information... My bad

41
Support / Re: Are merged Object3D able to have shared submeshes?
« on: November 18, 2021, 03:08:15 pm »
  • create the overlay as usual
  • user Oyerlay.getObject3D() to get the internal Object3D from the overlay
  • attach an IRenderHook implementation to that object, that...
  • ...implements IRenderHook.beforeRendering(<int>) in a way that FrameBuffer.clearZBufferOnly() is being called in it.
  • ...and then check what this does...
I tried this but it didn't seem to make a difference unfortunately... Any other suggestions?
I believe Overlay#setDepth(-9E30f) sort of works best for now but still not perfectly

About the merging: It's the usual trade-off, I guess. Merging them requires time at startup (not sure if that matters here) and consumes more memory, because it limits the ability to share meshes. On the other hand, it uses less draw calls, which should make it render faster. Apart from that, the basic idea sounds fine to me. It would have done it the same way (maybe that doesn't say much, but anyway...). In fact, I did something very similar with the dungeons in Naroth. They aren't a solid mesh but consist of building blocks for walls, ceilings and floors that are constantly enabled, disabled and moved around when the player moves. Of course, that's slower than a single mesh but it's actually fast enough and requires much less memory and is more flexible.
About the enabling/disabling, did you mean Object3D#setVisibility(boolean), World.removeObject(Object3D) or something else? (I assume these are basically the same anyway...)
Does this need to be actively done for every frame (or camera update)? ??? I thought jPCT took care of this automatically based on what's visible inside the camera's view...

Merging at startup would be possible but the scenery would be more dull in that sense... I'm not sure if merging can be recommended during render time but it would make the scenery better I guess....
But I believe merging might be better still since I have the feeling that currently too many draw calls are being made, lowering the FPS as a result. I guess I'll split it up in a mergeable and non-mergeable part per segment or something

42
Hmmm, what I would do myself is probably this:
- Texture#setClamping(false) => so it goes into texture repeating mode.
- Scale the UV coordinates with the amount of repetitions you want in each direction (instead of the usual 0.0 to 1.0, it'll go from 0.0 to N*1.0, where N is the amount of repetitions in the U or V direction).

Since I assume you don't want to do the second option... Here's what I'd suggest still:
I think you should be able to retrieve UV coordinates from an Object3D: https://www.jpct.net/jpct-ae/doc/com/threed/jpct/PolygonManager.html#getTextureUV-int-int-
I am missing a setTextureUV() method here though...
In the end, I believe https://www.jpct.net/jpct-ae/doc/com/threed/jpct/Object3D.html#setTextureMatrix-com.threed.jpct.Matrix- might be your best bet for scaling/offsetting UV coordinates
I'm not entirely sure if this will give the desired results, however...

43
Support / Re: Are merged Object3D able to have shared submeshes?
« on: November 17, 2021, 02:38:39 pm »
Here are some images for explanation: https://imgur.com/a/mt0FB2K
I only started on this project last week or so... So it doesn't look that good yet...
Although these screenshots are taken from an emulator, the same problem is present on an actual phone.
The red circles show the clipping problem. The cyan/blue circles explain what I meant with static/dynamic.

The overlays in the images use the default depth.
Using: Overlay#setDepth(-9E30f); seems to help a lot but the objects very rarely still seem to clip through (causing a slight flickering effect)

Basically the road is randomly generated (and so are the mountains and guardrails)
However, everything is made up from small segments. (So there is road segments, guardrail segments, mountain segments, etc.)
The segments in the back get moved to the front once the car is moving (so it is an infinitely long road).
The segmented implementation allows rotations (curved roads) to happen without having to modify the meshes.

The road segments and the guardrail segments all share the same mesh.
The mountain segments do not share the same mesh (so these are dynamically created...).
I didn't mean dynamic as in for animation purposes.

What I basically wanted is to merge the mountain segment and the guardrail segments together into a 'terrain segment'.
So you could see the terrain segment's mesh to consist of two parts: a (shareable) mesh part and a (variable/non-shareable) mesh part
Where the shareable mesh is the guardrail, and the non-shareable mesh is the mountain.
I'm not even sure if this idea would have any performance benefits...

I wonder if there are better ways to implement this whole idea anyway
Currently, I have 150 road segments, 150 mountain segments, 150 dirt segments and (maximally) (150*2+50*2) guardrail segments (left and right guardrail and left and right guardrail pole respectively).
On my phone rendering this scene gives about 30 to 60 FPS depending on the direction of where the camera is pointing.
400+ Object3D's seem to be a lot anyway... But I'm not sure if it's more expensive to have them merged or to let them have parent-child relationships.
My issue is basically: creating a lot of Object3D's with child-parent relationships (avoids merging) vs. creating a lot of Object3D's and merging to reduce the amount of Object3D's (avoids having a lot of Object3D)

44
Support / Are merged Object3D able to have shared submeshes?
« on: November 16, 2021, 10:06:27 am »
Hello,

Let's say I have 300 dynamic Object3D's and 300 static Object3D's.
The 300 static ones share the same mesh, the dynamic one does not.
However, in the world scene these objects will always be rendered together (one dynamic Object3D with one static Object3D). Each of the 300 Object3D's have different positions and rotations, but every dynamic Object3D is 'coupled' with a static Object3D.

Would it be better to have 600 Object3D's with a child/parent relationship? Or is it possible to merge these to 300 Object3D's which could be cheaper to render (because the submesh could be shared..?). I wonder which is best in terms of memory usage and performance. Or is there another better way to implement this..? (The Object3D's have between 12 to 60 triangles each for further information)

In the documentation it said merged Object3D's aren't compressed by default but I am not sure how or if that holds if one of two Object3D shares their mesh.

Cheers.

Edit: I'm also having issues with my multiple Overlays. When I use Overlay#setDepth() the Overlay seems to vanish..? I can solve the sorting problem of multiple Overlays using Object3D#setSortingOffset on its Object3D. However, it is still possible for my other World Object3D's to appear in front of the Overlay... (even without the sorting offset). How can I make sure the Overlay is always on top?
Edit2: Nevermind... apparently setDepth allows negative values (although documentation says it should always be positive..?) Maybe having Config.nearPlane = 0f and Config.ignoreNearPlane = true ruins compatibility or something. setDepth with negative values do seem to work and also fix my issue...
Edit3: Sometimes the other Object3Ds in the world still seem to clip through the overlay... (it appears as flickering but it's barely noticable but still weird...) Well whatever... I give up for now

45
Support / Re: Diffuse vs. Specular light color
« on: November 07, 2021, 01:28:56 am »
Ah okay...
I wasn't sure if setAdditionalColor still relied on RGBColor afterwards, since there's an (int, int, int) method for it too

Thanks for explaining! :)

Pages: 1 2 [3] 4 5 ... 22