Search in sources :

Example 1 with Point3DLight

use of com.gempukku.libgdx.graph.plugin.lighting3d.Point3DLight 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)

Aggregations

Array (com.badlogic.gdx.utils.Array)1 ObjectMap (com.badlogic.gdx.utils.ObjectMap)1 LightColor (com.gempukku.libgdx.graph.plugin.lighting3d.LightColor)1 Lighting3DEnvironment (com.gempukku.libgdx.graph.plugin.lighting3d.Lighting3DEnvironment)1 Lighting3DPrivateData (com.gempukku.libgdx.graph.plugin.lighting3d.Lighting3DPrivateData)1 Point3DLight (com.gempukku.libgdx.graph.plugin.lighting3d.Point3DLight)1 Lights3DProvider (com.gempukku.libgdx.graph.plugin.lighting3d.provider.Lights3DProvider)1 DefaultFieldOutput (com.gempukku.libgdx.graph.shader.node.DefaultFieldOutput)1