Search in sources :

Example 11 with Lighting3DEnvironment

use of com.gempukku.libgdx.graph.plugin.lighting3d.Lighting3DEnvironment in project gdx-graph by MarcinSc.

the class DirectionalLightShaderNodeBuilder method buildCommonNode.

@Override
protected ObjectMap<String, ? extends FieldOutput> buildCommonNode(boolean designTime, String nodeId, final JsonValue data, ObjectMap<String, FieldOutput> inputs, ObjectSet<String> producedOutputs, CommonShaderBuilder commonShaderBuilder, GraphShaderContext graphShaderContext, GraphShader graphShader) {
    final int index = data.getInt("index");
    final String environmentId = data.getString("id", "");
    ObjectMap<String, DefaultFieldOutput> result = new ObjectMap<>();
    if (producedOutputs.contains("direction")) {
        String name = "u_directionalLightDirection_" + nodeId + "_" + index;
        commonShaderBuilder.addUniformVariable(name, "vec3", false, new UniformRegistry.UniformSetter() {

            @Override
            public void set(BasicShader shader, int location, ShaderContext shaderContext) {
                Lighting3DPrivateData privatePluginData = shaderContext.getPrivatePluginData(Lighting3DPrivateData.class);
                Lighting3DEnvironment environment = privatePluginData.getEnvironment(environmentId);
                Lights3DProvider lights3DProvider = privatePluginData.getLights3DProvider();
                Array<Directional3DLight> directionalLights = lights3DProvider.getDirectionalLights(environment, shaderContext.getRenderableModel(), index + 1);
                if (directionalLights != null && directionalLights.size > index && directionalLights.get(index) != null) {
                    Directional3DLight directionalLight = directionalLights.get(index);
                    shader.setUniform(location, directionalLight.getDirectionX(), directionalLight.getDirectionY(), directionalLight.getDirectionZ());
                } else {
                    shader.setUniform(location, 0f, 0f, 0f);
                }
            }
        }, "Light direction");
        result.put("direction", new DefaultFieldOutput(ShaderFieldType.Vector3, name));
    }
    if (producedOutputs.contains("color")) {
        String name = "u_directionalLightColor_" + nodeId + "_" + index;
        commonShaderBuilder.addUniformVariable(name, "vec4", false, new UniformRegistry.UniformSetter() {

            @Override
            public void set(BasicShader shader, int location, ShaderContext shaderContext) {
                Lighting3DPrivateData privatePluginData = shaderContext.getPrivatePluginData(Lighting3DPrivateData.class);
                Lighting3DEnvironment environment = privatePluginData.getEnvironment(environmentId);
                Lights3DProvider lights3DProvider = privatePluginData.getLights3DProvider();
                Array<Directional3DLight> directionalLights = lights3DProvider.getDirectionalLights(environment, shaderContext.getRenderableModel(), index + 1);
                if (directionalLights != null && directionalLights.size > index && directionalLights.get(index) != null) {
                    Directional3DLight directionalLight = directionalLights.get(index);
                    LightColor color = directionalLight.getColor();
                    shader.setUniform(location, color.getRed(), color.getGreen(), color.getBlue(), 1f);
                } else {
                    shader.setUniform(location, 0f, 0f, 0f, 1f);
                }
            }
        }, "Light color");
        result.put("color", new DefaultFieldOutput(ShaderFieldType.Vector4, name));
    }
    return result;
}
Also used : Directional3DLight(com.gempukku.libgdx.graph.plugin.lighting3d.Directional3DLight) Lighting3DPrivateData(com.gempukku.libgdx.graph.plugin.lighting3d.Lighting3DPrivateData) DefaultFieldOutput(com.gempukku.libgdx.graph.shader.node.DefaultFieldOutput) Array(com.badlogic.gdx.utils.Array) Lights3DProvider(com.gempukku.libgdx.graph.plugin.lighting3d.provider.Lights3DProvider) ObjectMap(com.badlogic.gdx.utils.ObjectMap) Lighting3DEnvironment(com.gempukku.libgdx.graph.plugin.lighting3d.Lighting3DEnvironment) LightColor(com.gempukku.libgdx.graph.plugin.lighting3d.LightColor)

Example 12 with Lighting3DEnvironment

use of com.gempukku.libgdx.graph.plugin.lighting3d.Lighting3DEnvironment in project gdx-graph by MarcinSc.

the class PointLightShaderNodeBuilder method buildCommonNode.

@Override
protected ObjectMap<String, ? extends FieldOutput> buildCommonNode(boolean designTime, String nodeId, final JsonValue data, ObjectMap<String, FieldOutput> inputs, ObjectSet<String> producedOutputs, CommonShaderBuilder commonShaderBuilder, GraphShaderContext graphShaderContext, GraphShader graphShader) {
    final int index = data.getInt("index");
    final String environmentId = data.getString("id", "");
    ObjectMap<String, DefaultFieldOutput> result = new ObjectMap<>();
    if (producedOutputs.contains("position")) {
        String name = "u_pointLightPosition_" + nodeId + "_" + index;
        commonShaderBuilder.addUniformVariable(name, "vec3", false, new UniformRegistry.UniformSetter() {

            @Override
            public void set(BasicShader shader, int location, ShaderContext shaderContext) {
                Lighting3DPrivateData privatePluginData = shaderContext.getPrivatePluginData(Lighting3DPrivateData.class);
                Lighting3DEnvironment environment = privatePluginData.getEnvironment(environmentId);
                Lights3DProvider lights3DProvider = privatePluginData.getLights3DProvider();
                Array<Point3DLight> pointLights = lights3DProvider.getPointLights(environment, shaderContext.getRenderableModel(), index + 1);
                if (pointLights != null && pointLights.size > index && pointLights.get(index) != null) {
                    Point3DLight pointLight = pointLights.get(index);
                    shader.setUniform(location, pointLight.getPosition());
                } else {
                    shader.setUniform(location, 0f, 0f, 0f);
                }
            }
        }, "Point light position");
        result.put("position", new DefaultFieldOutput(ShaderFieldType.Vector3, name));
    }
    if (producedOutputs.contains("color")) {
        String name = "u_pointLightColor_" + nodeId + "_" + index;
        commonShaderBuilder.addUniformVariable(name, "vec4", false, new UniformRegistry.UniformSetter() {

            @Override
            public void set(BasicShader shader, int location, ShaderContext shaderContext) {
                Lighting3DPrivateData privatePluginData = shaderContext.getPrivatePluginData(Lighting3DPrivateData.class);
                Lighting3DEnvironment environment = privatePluginData.getEnvironment(environmentId);
                Lights3DProvider lights3DProvider = privatePluginData.getLights3DProvider();
                Array<Point3DLight> pointLights = lights3DProvider.getPointLights(environment, shaderContext.getRenderableModel(), index + 1);
                if (pointLights != null && pointLights.size > index && pointLights.get(index) != null) {
                    Point3DLight pointLight = pointLights.get(index);
                    LightColor color = pointLight.getColor();
                    shader.setUniform(location, color.getRed(), color.getGreen(), color.getBlue(), 1f);
                } else {
                    shader.setUniform(location, 0f, 0f, 0f, 1f);
                }
            }
        }, "Point light color");
        result.put("color", new DefaultFieldOutput(ShaderFieldType.Vector4, name));
    }
    if (producedOutputs.contains("intensity")) {
        String name = "u_pointLightIntensity_" + nodeId + "_" + index;
        commonShaderBuilder.addUniformVariable(name, "float", false, new UniformRegistry.UniformSetter() {

            @Override
            public void set(BasicShader shader, int location, ShaderContext shaderContext) {
                Lighting3DPrivateData privatePluginData = shaderContext.getPrivatePluginData(Lighting3DPrivateData.class);
                Lighting3DEnvironment environment = privatePluginData.getEnvironment(environmentId);
                Lights3DProvider lights3DProvider = privatePluginData.getLights3DProvider();
                Array<Point3DLight> pointLights = lights3DProvider.getPointLights(environment, shaderContext.getRenderableModel(), index + 1);
                if (pointLights != null && pointLights.size > index && pointLights.get(index) != null) {
                    Point3DLight pointLight = pointLights.get(index);
                    shader.setUniform(location, pointLight.getIntensity());
                } else {
                    shader.setUniform(location, 0f);
                }
            }
        }, "Point light intensity");
        result.put("intensity", new DefaultFieldOutput(ShaderFieldType.Float, name));
    }
    return result;
}
Also used : Lighting3DPrivateData(com.gempukku.libgdx.graph.plugin.lighting3d.Lighting3DPrivateData) DefaultFieldOutput(com.gempukku.libgdx.graph.shader.node.DefaultFieldOutput) Array(com.badlogic.gdx.utils.Array) Point3DLight(com.gempukku.libgdx.graph.plugin.lighting3d.Point3DLight) Lights3DProvider(com.gempukku.libgdx.graph.plugin.lighting3d.provider.Lights3DProvider) ObjectMap(com.badlogic.gdx.utils.ObjectMap) Lighting3DEnvironment(com.gempukku.libgdx.graph.plugin.lighting3d.Lighting3DEnvironment) LightColor(com.gempukku.libgdx.graph.plugin.lighting3d.LightColor)

Example 13 with Lighting3DEnvironment

use of com.gempukku.libgdx.graph.plugin.lighting3d.Lighting3DEnvironment in project gdx-graph by MarcinSc.

the class SpotLightShaderNodeBuilder method buildCommonNode.

@Override
protected ObjectMap<String, ? extends FieldOutput> buildCommonNode(boolean designTime, String nodeId, final JsonValue data, ObjectMap<String, FieldOutput> inputs, ObjectSet<String> producedOutputs, CommonShaderBuilder commonShaderBuilder, GraphShaderContext graphShaderContext, GraphShader graphShader) {
    final int index = data.getInt("index");
    final String environmentId = data.getString("id", "");
    ObjectMap<String, DefaultFieldOutput> result = new ObjectMap<>();
    if (producedOutputs.contains("position")) {
        String name = "u_spotLightPosition_" + nodeId + "_" + index;
        commonShaderBuilder.addUniformVariable(name, "vec3", false, new UniformRegistry.UniformSetter() {

            @Override
            public void set(BasicShader shader, int location, ShaderContext shaderContext) {
                Lighting3DPrivateData privatePluginData = shaderContext.getPrivatePluginData(Lighting3DPrivateData.class);
                Lighting3DEnvironment environment = privatePluginData.getEnvironment(environmentId);
                Lights3DProvider lights3DProvider = privatePluginData.getLights3DProvider();
                Array<Spot3DLight> spotLights = lights3DProvider.getSpotLights(environment, shaderContext.getRenderableModel(), index + 1);
                if (spotLights != null && spotLights.size > index && spotLights.get(index) != null) {
                    Spot3DLight spotLight = spotLights.get(index);
                    shader.setUniform(location, spotLight.getPosition());
                } else {
                    shader.setUniform(location, 0f, 0f, 0f);
                }
            }
        }, "Spot light position");
        result.put("position", new DefaultFieldOutput(ShaderFieldType.Vector3, name));
    }
    if (producedOutputs.contains("direction")) {
        String name = "u_spotLightDirection_" + nodeId + "_" + index;
        commonShaderBuilder.addUniformVariable(name, "vec3", false, new UniformRegistry.UniformSetter() {

            @Override
            public void set(BasicShader shader, int location, ShaderContext shaderContext) {
                Lighting3DPrivateData privatePluginData = shaderContext.getPrivatePluginData(Lighting3DPrivateData.class);
                Lighting3DEnvironment environment = privatePluginData.getEnvironment(environmentId);
                Lights3DProvider lights3DProvider = privatePluginData.getLights3DProvider();
                Array<Spot3DLight> spotLights = lights3DProvider.getSpotLights(environment, shaderContext.getRenderableModel(), index + 1);
                if (spotLights != null && spotLights.size > index && spotLights.get(index) != null) {
                    Spot3DLight spotLight = spotLights.get(index);
                    shader.setUniform(location, spotLight.getDirectionX(), spotLight.getDirectionY(), spotLight.getDirectionZ());
                } else {
                    shader.setUniform(location, 0f, 0f, 0f);
                }
            }
        }, "Spot light direction");
        result.put("direction", new DefaultFieldOutput(ShaderFieldType.Vector3, name));
    }
    if (producedOutputs.contains("color")) {
        String name = "u_spotLightColor_" + nodeId + "_" + index;
        commonShaderBuilder.addUniformVariable(name, "vec4", false, new UniformRegistry.UniformSetter() {

            @Override
            public void set(BasicShader shader, int location, ShaderContext shaderContext) {
                Lighting3DPrivateData privatePluginData = shaderContext.getPrivatePluginData(Lighting3DPrivateData.class);
                Lighting3DEnvironment environment = privatePluginData.getEnvironment(environmentId);
                Lights3DProvider lights3DProvider = privatePluginData.getLights3DProvider();
                Array<Spot3DLight> spotLights = lights3DProvider.getSpotLights(environment, shaderContext.getRenderableModel(), index + 1);
                if (spotLights != null && spotLights.size > index && spotLights.get(index) != null) {
                    Spot3DLight spotLight = spotLights.get(index);
                    LightColor color = spotLight.getColor();
                    shader.setUniform(location, color.getRed(), color.getGreen(), color.getBlue(), 1f);
                } else {
                    shader.setUniform(location, 0f, 0f, 0f, 1f);
                }
            }
        }, "Spot light color");
        result.put("color", new DefaultFieldOutput(ShaderFieldType.Vector4, name));
    }
    if (producedOutputs.contains("intensity")) {
        String name = "u_spotLightIntensity_" + nodeId + "_" + index;
        commonShaderBuilder.addUniformVariable(name, "float", false, new UniformRegistry.UniformSetter() {

            @Override
            public void set(BasicShader shader, int location, ShaderContext shaderContext) {
                Lighting3DPrivateData privatePluginData = shaderContext.getPrivatePluginData(Lighting3DPrivateData.class);
                Lighting3DEnvironment environment = privatePluginData.getEnvironment(environmentId);
                Lights3DProvider lights3DProvider = privatePluginData.getLights3DProvider();
                Array<Spot3DLight> spotLights = lights3DProvider.getSpotLights(environment, shaderContext.getRenderableModel(), index + 1);
                if (spotLights != null && spotLights.size > index && spotLights.get(index) != null) {
                    Spot3DLight spotLight = spotLights.get(index);
                    shader.setUniform(location, spotLight.getIntensity());
                } else {
                    shader.setUniform(location, 0f);
                }
            }
        }, "Spot light intensity");
        result.put("intensity", new DefaultFieldOutput(ShaderFieldType.Float, name));
    }
    if (producedOutputs.contains("cutOffAngle")) {
        String name = "u_spotLightCutOffAngle_" + nodeId + "_" + index;
        commonShaderBuilder.addUniformVariable(name, "float", false, new UniformRegistry.UniformSetter() {

            @Override
            public void set(BasicShader shader, int location, ShaderContext shaderContext) {
                Lighting3DPrivateData privatePluginData = shaderContext.getPrivatePluginData(Lighting3DPrivateData.class);
                Lighting3DEnvironment environment = privatePluginData.getEnvironment(environmentId);
                Lights3DProvider lights3DProvider = privatePluginData.getLights3DProvider();
                Array<Spot3DLight> spotLights = lights3DProvider.getSpotLights(environment, shaderContext.getRenderableModel(), index + 1);
                if (spotLights != null && spotLights.size > index && spotLights.get(index) != null) {
                    Spot3DLight spotLight = spotLights.get(index);
                    shader.setUniform(location, spotLight.getCutoffAngle());
                } else {
                    shader.setUniform(location, 0f);
                }
            }
        }, "Spot light cut-off angle");
        result.put("cutOffAngle", new DefaultFieldOutput(ShaderFieldType.Float, name));
    }
    if (producedOutputs.contains("exponent")) {
        String name = "u_spotLightExponent_" + nodeId + "_" + index;
        commonShaderBuilder.addUniformVariable(name, "float", false, new UniformRegistry.UniformSetter() {

            @Override
            public void set(BasicShader shader, int location, ShaderContext shaderContext) {
                Lighting3DPrivateData privatePluginData = shaderContext.getPrivatePluginData(Lighting3DPrivateData.class);
                Lighting3DEnvironment environment = privatePluginData.getEnvironment(environmentId);
                Lights3DProvider lights3DProvider = privatePluginData.getLights3DProvider();
                Array<Spot3DLight> spotLights = lights3DProvider.getSpotLights(environment, shaderContext.getRenderableModel(), index + 1);
                if (spotLights != null && spotLights.size > index && spotLights.get(index) != null) {
                    Spot3DLight spotLight = spotLights.get(index);
                    shader.setUniform(location, spotLight.getExponent());
                } else {
                    shader.setUniform(location, 0f);
                }
            }
        }, "Spot light exponent");
        result.put("exponent", new DefaultFieldOutput(ShaderFieldType.Float, name));
    }
    return result;
}
Also used : Spot3DLight(com.gempukku.libgdx.graph.plugin.lighting3d.Spot3DLight) Lighting3DPrivateData(com.gempukku.libgdx.graph.plugin.lighting3d.Lighting3DPrivateData) DefaultFieldOutput(com.gempukku.libgdx.graph.shader.node.DefaultFieldOutput) Array(com.badlogic.gdx.utils.Array) Lights3DProvider(com.gempukku.libgdx.graph.plugin.lighting3d.provider.Lights3DProvider) ObjectMap(com.badlogic.gdx.utils.ObjectMap) Lighting3DEnvironment(com.gempukku.libgdx.graph.plugin.lighting3d.Lighting3DEnvironment) LightColor(com.gempukku.libgdx.graph.plugin.lighting3d.LightColor)

Example 14 with Lighting3DEnvironment

use of com.gempukku.libgdx.graph.plugin.lighting3d.Lighting3DEnvironment in project gdx-graph by MarcinSc.

the class Episode9Scene method createLights.

private Lighting3DEnvironment createLights() {
    float ambientBrightness = 0.3f;
    float directionalBrightness = 0.8f;
    Lighting3DEnvironment lights = new Lighting3DEnvironment();
    lights.setAmbientColor(new Color(ambientBrightness, ambientBrightness, ambientBrightness, 1f));
    DirectionalLight directionalLight = new DirectionalLight();
    directionalLight.setColor(directionalBrightness, directionalBrightness, directionalBrightness, 1f);
    directionalLight.setDirection(-0.3f, -0.4f, -1);
    lights.addDirectionalLight(new Directional3DLight(directionalLight));
    return lights;
}
Also used : Directional3DLight(com.gempukku.libgdx.graph.plugin.lighting3d.Directional3DLight) Lighting3DEnvironment(com.gempukku.libgdx.graph.plugin.lighting3d.Lighting3DEnvironment) Color(com.badlogic.gdx.graphics.Color) DirectionalLight(com.badlogic.gdx.graphics.g3d.environment.DirectionalLight)

Example 15 with Lighting3DEnvironment

use of com.gempukku.libgdx.graph.plugin.lighting3d.Lighting3DEnvironment in project gdx-graph by MarcinSc.

the class Episode16Scene method createLights.

private Lighting3DEnvironment createLights() {
    float ambientBrightness = 0.8f;
    float directionalBrightness = 0.8f;
    Lighting3DEnvironment lights = new Lighting3DEnvironment();
    lights.setAmbientColor(new Color(ambientBrightness, ambientBrightness, ambientBrightness, 1f));
    DirectionalLight directionalLight = new DirectionalLight();
    directionalLight.setColor(directionalBrightness, directionalBrightness, directionalBrightness, 1f);
    directionalLight.setDirection(-1f, -0.3f, 0);
    lights.addDirectionalLight(new Directional3DLight(directionalLight));
    return lights;
}
Also used : Directional3DLight(com.gempukku.libgdx.graph.plugin.lighting3d.Directional3DLight) Lighting3DEnvironment(com.gempukku.libgdx.graph.plugin.lighting3d.Lighting3DEnvironment) Color(com.badlogic.gdx.graphics.Color) DirectionalLight(com.badlogic.gdx.graphics.g3d.environment.DirectionalLight)

Aggregations

Lighting3DEnvironment (com.gempukku.libgdx.graph.plugin.lighting3d.Lighting3DEnvironment)18 Directional3DLight (com.gempukku.libgdx.graph.plugin.lighting3d.Directional3DLight)14 Color (com.badlogic.gdx.graphics.Color)12 DirectionalLight (com.badlogic.gdx.graphics.g3d.environment.DirectionalLight)11 Array (com.badlogic.gdx.utils.Array)5 ObjectMap (com.badlogic.gdx.utils.ObjectMap)5 LightColor (com.gempukku.libgdx.graph.plugin.lighting3d.LightColor)5 Lighting3DPrivateData (com.gempukku.libgdx.graph.plugin.lighting3d.Lighting3DPrivateData)5 DefaultFieldOutput (com.gempukku.libgdx.graph.shader.node.DefaultFieldOutput)5 Lights3DProvider (com.gempukku.libgdx.graph.plugin.lighting3d.provider.Lights3DProvider)4 RenderPipelineBuffer (com.gempukku.libgdx.graph.pipeline.RenderPipelineBuffer)2 Camera (com.badlogic.gdx.graphics.Camera)1 OrthographicCamera (com.badlogic.gdx.graphics.OrthographicCamera)1 PerspectiveCamera (com.badlogic.gdx.graphics.PerspectiveCamera)1 Texture (com.badlogic.gdx.graphics.Texture)1 Material (com.badlogic.gdx.graphics.g3d.Material)1 Model (com.badlogic.gdx.graphics.g3d.Model)1 ModelInstance (com.badlogic.gdx.graphics.g3d.ModelInstance)1 ModelBuilder (com.badlogic.gdx.graphics.g3d.utils.ModelBuilder)1 TextureDescriptor (com.badlogic.gdx.graphics.g3d.utils.TextureDescriptor)1