Bug with diffuse lighting

Started by AeroShark333, November 09, 2022, 02:33:03 AM

Previous topic - Next topic

AeroShark333

Hello,

I have noticed a minor bug while working on something.

Bug: It seems that the "diffuseColors" are not all set properly.
For the first two light sources the colors seem fine, but for 3 and 4 (and possibly till 8 ), the diffuseColor seems white instead of the color supplied through #setIntensity(R,G,B).
I have tried to use the "diffuseColors" from 1&2 for 3&4 by changing the default shader code. And this seems to be working as intended.
So my suspect is that in the Java code of the library, the diffuse colors are not set to the uniform "diffuseColors" properly.

Thanks in advance! :)

EgonOlsen



EgonOlsen

I made this test case, but I fail to see an issue with it:




package com.threed.jpct.example;

import android.app.Activity;
import android.opengl.GLSurfaceView;
import android.os.Bundle;

import com.threed.jpct.Camera;
import com.threed.jpct.FrameBuffer;
import com.threed.jpct.Light;
import com.threed.jpct.Object3D;
import com.threed.jpct.Primitives;
import com.threed.jpct.RGBColor;
import com.threed.jpct.SimpleVector;
import com.threed.jpct.World;

import java.util.ArrayList;
import java.util.List;

import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.opengles.GL10;

public class HelloWorld extends Activity {
    private GLSurfaceView mGLView;
    private MyRenderer renderer = null;
    private FrameBuffer fb = null;
    private World world = null;
    private final List<Light> lights = new ArrayList<>();
    private float[] dir = null;

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        mGLView = new GLSurfaceView(getApplication());
        mGLView.setEGLContextClientVersion(2);
        mGLView.setPreserveEGLContextOnPause(true);

        renderer = new MyRenderer();
        mGLView.setRenderer(renderer);
        setContentView(mGLView);
    }

    @Override
    protected void onPause() {
        super.onPause();
        mGLView.onPause();
    }

    @Override
    protected void onResume() {
        super.onResume();
        mGLView.onResume();
    }

    @Override
    protected void onStop() {
        super.onStop();
        System.exit(0);
    }


    class MyRenderer implements GLSurfaceView.Renderer {

        public MyRenderer() {
            //
        }

        public void onSurfaceChanged(GL10 gl, int w, int h) {
            world = new World();
            world.setAmbientLight(0, 0, 0);

            SimpleVector[] cols = new SimpleVector[]{
                    SimpleVector.create(64, 128, 64),
                    SimpleVector.create(0, 128, 128),
                    SimpleVector.create(128, 0, 128),
                    SimpleVector.create(128, 128, 0),
                    SimpleVector.create(0, 0, 128),
                    SimpleVector.create(128, 0, 0),
                    SimpleVector.create(0, 128, 0),
                    SimpleVector.create(0, 64, 64)};

            for (int i = 0; i < 8; i++) {
                Object3D obj = Primitives.getSphere(50, 8);
                world.addObject(obj);
                int pos = 30 + (i - 7) * 10;
                obj.translate(10 - 20 * (i % 2), pos, 0);
                obj.build();
            }

            for (int i = 0; i < 8; i++) {
                int pos = 30 + (i - 7) * 30;
                Light light = new Light(world);
                light.setIntensity(cols[i]);
                SimpleVector sv = new SimpleVector();
                sv.y = pos;
                sv.z -= 20 - 40 * (i % 2);
                light.setPosition(sv);
                lights.add(light);
            }

            dir = new float[lights.size()];
            for (int i = 0; i < lights.size(); i++) {
                dir[i] = 1f;
            }

            Camera cam = world.getCamera();
            cam.moveCamera(Camera.CAMERA_MOVEOUT, 45);
            cam.lookAt(SimpleVector.ORIGIN);

            fb = new FrameBuffer(w, h);
        }

        public void onSurfaceCreated(GL10 gl, EGLConfig config) {
            //
        }

        public void onDrawFrame(GL10 gl) {
            fb.clear(RGBColor.BLACK);
            world.renderScene(fb);
            world.draw(fb);
            fb.display();

            for (int i = 0; i < lights.size(); i++) {
                Light light = lights.get(i);
                SimpleVector sv = light.getPosition();
                sv.y += dir[i];
                if (sv.y > 150 || sv.y < -150) {
                    dir[i] *= -1f;
                }
                light.setPosition(sv);
            }
        }
    }
}



Do you have a test case that shows this problem?

AeroShark333

#4
I tried to modify the test case to something similar as what I had but it seems to be working fine...

I tried to look again at my own situation too but it seems fine now...  ???
I think I just made a mistake myself along the way
Sorry for bringing this up, I guess it was an error on my side after all
I think I forgot to set the intensities for some lights and they showed the wrong color (white by default...)

I'll report back if there was something fishy going on still but I suppose it is not the case; so... case closed for now