Search in sources :

Example 1 with Light

use of maspack.render.Light in project artisynth_core by artisynth.

the class GL2Viewer method setupLights.

protected void setupLights(GL2 gl) {
    maybeUpdateMatrices(gl);
    int maxLights = lightManager.maxLights();
    float intensityScale = 1.0f / lightManager.getMaxIntensity();
    // only enable up to maxLights
    for (Light light : lightManager.getLights()) {
        if (light.getId() < maxLights) {
            setupLight(gl, light, intensityScale);
        }
    }
}
Also used : Light(maspack.render.Light) Point(java.awt.Point)

Example 2 with Light

use of maspack.render.Light in project artisynth_core by artisynth.

the class GLLightManager method doRemoveLight.

private void doRemoveLight(int idx) {
    Light light = lights.get(idx);
    lights.remove(idx);
    // correct light IDs in list
    for (int i = idx; i < lights.size(); ++i) {
        lights.get(i).setId(i);
    }
    light.setId(-1);
}
Also used : Light(maspack.render.Light)

Example 3 with Light

use of maspack.render.Light in project artisynth_core by artisynth.

the class GLLightManager method createLight.

public Light createLight(float[] position, float[] ambient, float[] diffuse, float[] specular) {
    Light light = new Light(position, ambient, diffuse, specular);
    addLight(light);
    return light;
}
Also used : Light(maspack.render.Light)

Example 4 with Light

use of maspack.render.Light in project artisynth_core by artisynth.

the class GL3JPanelTest method setDefaultLights.

public static void setDefaultLights() {
    // // For debugging lights, set to R-G-B
    // float light0_ambient[] = { 0.2f, 0.2f, 0.2f, 1.0f };
    // float light0_diffuse[] = { 0.8f, 0.0f, 0.0f, 1.0f };
    // float light0_specular[] = { 0, 0, 0, 1 };
    // float light0_position[] = { 1, 0, 0, 0 };
    // 
    // float light1_ambient[] = { 0.0f, 0.0f, 0.0f, 1.0f };
    // float light1_diffuse[] = { 0.0f, 0.8f, 0.0f, 1.0f };
    // float light1_specular[] = { 0.0f, 0.0f, 0.0f, 1.0f };
    // float light1_position[] = { 0, 1, 0, 0 };
    // 
    // float light2_ambient[] = { 0.0f, 0.0f, 0.0f, 1.0f };
    // float light2_diffuse[] = { 0.0f, 0.0f, 0.8f, 1.0f };
    // float light2_specular[] = { 0.0f, 0.0f, 0.0f, 1.0f };
    // float light2_position[] = { 0, 0, 1, 0 };
    float[] light0_ambient = { 0.1f, 0.1f, 0.1f, 1f };
    float[] light0_diffuse = { 0.8f, 0.8f, 0.8f, 1.0f };
    float[] light0_specular = { 0.5f, 0.5f, 0.5f, 1.0f };
    float[] light0_position = { -0.8660254f, 0.5f, 1f, 0f };
    float[] light1_ambient = { 0.0f, 0.0f, 0.0f, 1.0f };
    float[] light1_diffuse = { 0.5f, 0.5f, 0.5f, 1.0f };
    float[] light1_specular = { 0.5f, 0.5f, 0.5f, 1.0f };
    float[] light1_position = { 0.8660254f, 0.5f, 1f, 0f };
    float[] light2_ambient = { 0.0f, 0.0f, 0.0f, 1.0f };
    float[] light2_diffuse = { 0.5f, 0.5f, 0.5f, 1.0f };
    float[] light2_specular = { 0.5f, 0.5f, 0.5f, 1.0f };
    float[] light2_position = { 0f, -10f, 1f, 0f };
    lightManager.clearLights();
    lightManager.addLight(new Light(light0_position, light0_ambient, light0_diffuse, light0_specular));
    lightManager.addLight(new Light(light1_position, light1_ambient, light1_diffuse, light1_specular));
    lightManager.addLight(new Light(light2_position, light2_ambient, light2_diffuse, light2_specular));
    lightManager.setMaxIntensity(1.0f);
}
Also used : Light(maspack.render.Light)

Example 5 with Light

use of maspack.render.Light in project artisynth_core by artisynth.

the class LightsUBO method updateLights.

public void updateLights(GL3 gl, List<Light> lights, float intensityScale, RigidTransform3d viewMatrix) {
    ByteBuffer buff = getBuffer();
    for (int i = 0; i < numLights; i++) {
        int idx = i * ATTRIBUTES_PER_LIGHT.length;
        // fill in properties
        Light light = lights.get(i);
        buff.position(getByteOffset(idx++));
        // diffuse
        putFloat(buff, light.getDiffuse(), 4);
        buff.position(getByteOffset(idx++));
        // ambient
        putFloat(buff, light.getAmbient(), 4);
        buff.position(getByteOffset(idx++));
        // specular
        putFloat(buff, light.getSpecular(), 4);
        // position
        buff.position(getByteOffset(idx++));
        // maybe adjust to camera space
        if (light.getLightSpace() == LightSpace.WORLD) {
            float[] flpos = light.getPosition();
            Point3d lpos = new Point3d(flpos[0], flpos[1], flpos[2]);
            lpos.transform(viewMatrix);
            buff.putFloat((float) (lpos.x));
            buff.putFloat((float) (lpos.y));
            buff.putFloat((float) (lpos.z));
        } else {
            // position
            putFloat(buff, light.getPosition(), 3);
        }
        // directional indicator
        if (light.getType() == LightType.DIRECTIONAL) {
            buff.putFloat(0f);
        } else {
            buff.putFloat(1f);
        }
        // direction
        buff.position(getByteOffset(idx++));
        // maybe adjust to camera space
        if (light.getLightSpace() == LightSpace.WORLD) {
            float[] fldir = light.getDirection();
            Vector3d ldir = new Vector3d(fldir[0], fldir[1], fldir[2]);
            ldir.transform(viewMatrix);
            buff.putFloat((float) (ldir.x));
            buff.putFloat((float) (ldir.y));
            buff.putFloat((float) (ldir.z));
        } else {
            // direction
            putFloat(buff, light.getDirection(), 3);
        }
        // spot indicator
        if (light.getType() == LightType.SPOT) {
            buff.putFloat((float) Math.cos(light.getSpotCutoff()));
        } else {
            // allow all light
            buff.putFloat(-1f);
        }
        // attenuation
        buff.position(getByteOffset(idx++));
        // attenuation
        buff.putFloat(light.getConstantAttenuation());
        buff.putFloat(light.getLinearAttenuation());
        buff.putFloat(light.getQuadraticAttenuation());
        buff.putFloat(light.getSpotExponent());
    }
    // light intensity
    int idx = numLights * ATTRIBUTES_PER_LIGHT.length;
    buff.position(getByteOffset(idx++));
    buff.putFloat(intensityScale);
    buff.flip();
    update(gl, buff);
}
Also used : Vector3d(maspack.matrix.Vector3d) Light(maspack.render.Light) Point3d(maspack.matrix.Point3d) ByteBuffer(java.nio.ByteBuffer)

Aggregations

Light (maspack.render.Light)8 ComponentList (artisynth.core.modelbase.ComponentList)1 LightComponent (artisynth.core.renderables.LightComponent)1 Point (java.awt.Point)1 ByteBuffer (java.nio.ByteBuffer)1 Point3d (maspack.matrix.Point3d)1 Vector3d (maspack.matrix.Vector3d)1 GLViewer (maspack.render.GL.GLViewer)1