Search in sources :

Example 1 with LightColor

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

the class ShadowBlinnPhongLightingShaderNodeBuilder method buildFragmentNodeSingleInputs.

@Override
public ObjectMap<String, ? extends FieldOutput> buildFragmentNodeSingleInputs(boolean designTime, String nodeId, final JsonValue data, ObjectMap<String, FieldOutput> inputs, ObjectSet<String> producedOutputs, VertexShaderBuilder vertexShaderBuilder, FragmentShaderBuilder fragmentShaderBuilder, final GraphShaderContext graphShaderContext, final GraphShader graphShader) {
    final String environmentId = data.getString("id", "");
    fragmentShaderBuilder.addStructure("Lighting", "  vec3 diffuse;\n" + "  vec3 specular;\n");
    // Lighting3DUtils.configureShadowInformation(fragmentShaderBuilder, nodeId, environmentId, maxNumberOfDirectionalLights, graphShader.getDefaultTexture());
    // 
    // Lighting3DUtils.configureAmbientLighting(fragmentShaderBuilder, nodeId, environmentId);
    final float[] shadowCameras = new float[16 * maxNumberOfDirectionalLights];
    fragmentShaderBuilder.addArrayUniformVariable("u_shadowCamera_" + nodeId, maxNumberOfDirectionalLights, "mat4", true, new UniformRegistry.UniformSetter() {

        @Override
        public void set(BasicShader shader, int location, ShaderContext shaderContext) {
            Lighting3DEnvironment environment = shaderContext.getPrivatePluginData(Lighting3DPrivateData.class).getEnvironment(data.getString("id", ""));
            if (environment != null) {
                Array<Directional3DLight> directionalLights = environment.getDirectionalLights();
                for (int i = 0; i < directionalLights.size; i++) {
                    OrthographicCamera shadowCamera = directionalLights.get(i).getShadowCamera();
                    if (shadowCamera != null) {
                        System.arraycopy(shadowCamera.combined.val, 0, shadowCameras, i * 16, 16);
                    }
                }
            }
            shader.setUniformMatrix4Array(location, shadowCameras);
        }
    }, "Shadow camera matrix");
    final float[] shadowCamerasBufferSize = new float[1 * maxNumberOfDirectionalLights];
    fragmentShaderBuilder.addArrayUniformVariable("u_shadowCameraBufferSize_" + nodeId, maxNumberOfDirectionalLights, "float", true, new UniformRegistry.UniformSetter() {

        @Override
        public void set(BasicShader shader, int location, ShaderContext shaderContext) {
            Lighting3DEnvironment environment = shaderContext.getPrivatePluginData(Lighting3DPrivateData.class).getEnvironment(data.getString("id", ""));
            if (environment != null) {
                Array<Directional3DLight> directionalLights = environment.getDirectionalLights();
                for (int i = 0; i < directionalLights.size; i++) {
                    OrthographicCamera shadowCamera = directionalLights.get(i).getShadowCamera();
                    if (shadowCamera != null) {
                        shadowCamerasBufferSize[i] = directionalLights.get(i).getShadowBufferSize();
                    }
                }
            }
            shader.setUniformFloatArray(location, shadowCamerasBufferSize);
        }
    }, "Shadow camera buffer size");
    final float[] shadowCamerasClipping = new float[2 * maxNumberOfDirectionalLights];
    fragmentShaderBuilder.addArrayUniformVariable("u_shadowCameraClipping_" + nodeId, maxNumberOfDirectionalLights, "vec2", true, new UniformRegistry.UniformSetter() {

        @Override
        public void set(BasicShader shader, int location, ShaderContext shaderContext) {
            Lighting3DEnvironment environment = shaderContext.getPrivatePluginData(Lighting3DPrivateData.class).getEnvironment(data.getString("id", ""));
            if (environment != null) {
                Array<Directional3DLight> directionalLights = environment.getDirectionalLights();
                for (int i = 0; i < directionalLights.size; i++) {
                    OrthographicCamera shadowCamera = directionalLights.get(i).getShadowCamera();
                    if (shadowCamera != null) {
                        shadowCamerasClipping[i * 2 + 0] = shadowCamera.near;
                        shadowCamerasClipping[i * 2 + 1] = shadowCamera.far;
                    }
                }
            }
            shader.setUniformVector2Array(location, shadowCamerasClipping);
        }
    }, "Shadow camera clipping");
    final float[] shadowCamerasPosition = new float[3 * maxNumberOfDirectionalLights];
    fragmentShaderBuilder.addArrayUniformVariable("u_shadowCameraPosition_" + nodeId, maxNumberOfDirectionalLights, "vec3", true, new UniformRegistry.UniformSetter() {

        @Override
        public void set(BasicShader shader, int location, ShaderContext shaderContext) {
            Lighting3DEnvironment environment = shaderContext.getPrivatePluginData(Lighting3DPrivateData.class).getEnvironment(data.getString("id", ""));
            if (environment != null) {
                Array<Directional3DLight> directionalLights = environment.getDirectionalLights();
                for (int i = 0; i < directionalLights.size; i++) {
                    OrthographicCamera shadowCamera = directionalLights.get(i).getShadowCamera();
                    if (shadowCamera != null) {
                        shadowCamerasPosition[i * 3 + 0] = shadowCamera.position.x;
                        shadowCamerasPosition[i * 3 + 1] = shadowCamera.position.y;
                        shadowCamerasPosition[i * 3 + 2] = shadowCamera.position.z;
                    }
                }
            }
            shader.setUniformVector3Array(location, shadowCamerasPosition);
        }
    }, "Shadow camera position");
    for (int i = 0; i < maxNumberOfDirectionalLights; i++) {
        final int lightIndex = i;
        final TextureDescriptor<Texture> textureDescriptor = new TextureDescriptor<>(null, Texture.TextureFilter.Nearest, Texture.TextureFilter.Nearest, Texture.TextureWrap.ClampToEdge, Texture.TextureWrap.ClampToEdge);
        fragmentShaderBuilder.addUniformVariable("u_shadowMap_" + nodeId + "_" + i, "sampler2D", true, new UniformRegistry.UniformSetter() {

            @Override
            public void set(BasicShader shader, int location, ShaderContext shaderContext) {
                Lighting3DEnvironment environment = shaderContext.getPrivatePluginData(Lighting3DPrivateData.class).getEnvironment(data.getString("id", ""));
                if (environment != null) {
                    Array<Directional3DLight> directionalLights = environment.getDirectionalLights();
                    RenderPipelineBuffer shadowFrameBuffer = null;
                    if (directionalLights.size > lightIndex)
                        shadowFrameBuffer = directionalLights.get(lightIndex).getShadowFrameBuffer();
                    if (shadowFrameBuffer != null) {
                        textureDescriptor.texture = shadowFrameBuffer.getColorBufferTexture();
                    } else {
                        textureDescriptor.texture = graphShader.getDefaultTexture();
                    }
                } else {
                    textureDescriptor.texture = graphShader.getDefaultTexture();
                }
                shader.setUniform(location, textureDescriptor);
            }
        }, "Shadow map " + i);
    }
    fragmentShaderBuilder.addUniformVariable("u_ambientLight_" + nodeId, "vec3", true, new UniformRegistry.UniformSetter() {

        @Override
        public void set(BasicShader shader, int location, ShaderContext shaderContext) {
            Lighting3DEnvironment environment = shaderContext.getPrivatePluginData(Lighting3DPrivateData.class).getEnvironment(data.getString("id", ""));
            if (environment != null && environment.getAmbientColor() != null) {
                LightColor ambientColor = environment.getAmbientColor();
                shader.setUniform(location, ambientColor.getRed(), ambientColor.getGreen(), ambientColor.getBlue());
            } else {
                shader.setUniform(location, 0f, 0f, 0f);
            }
        }
    }, "Ambient light");
    loadFragmentIfNotDefined(fragmentShaderBuilder, "unpackVec3ToFloat");
    String isLightedFunctionName = "isLighted_" + nodeId;
    String probeShadowMapFunctionName = "probeShadowMap_" + nodeId;
    fragmentShaderBuilder.addFunction(probeShadowMapFunctionName, createProbeShadowMapFunction(nodeId));
    ObjectMap<String, String> variables = new ObjectMap<>();
    variables.put("NUM_SPOT_LIGHTS", String.valueOf(maxNumberOfSpotlights));
    variables.put("NUM_POINT_LIGHTS", String.valueOf(maxNumberOfPointLights));
    variables.put("NUM_DIRECTIONAL_LIGHTS", String.valueOf(maxNumberOfDirectionalLights));
    variables.put("SHADOW_ACNE_VALUE", SimpleNumberFormatter.format(shadowAcneValue));
    variables.put("SHADOW_SOFTNESS", String.valueOf(shadowSoftness));
    variables.put("SHADOW_PROBE_COUNT", SimpleNumberFormatter.format((shadowSoftness + 1) * (shadowSoftness + 1)));
    variables.put("NODE_ID", nodeId);
    fragmentShaderBuilder.addFunction(isLightedFunctionName, GLSLFragmentReader.getFragment("isLighted", variables));
    if (maxNumberOfDirectionalLights > 0)
        passDirectionalLights(environmentId, fragmentShaderBuilder, nodeId, variables);
    if (maxNumberOfPointLights > 0)
        passPointLights(environmentId, fragmentShaderBuilder, nodeId, variables);
    if (maxNumberOfSpotlights > 0)
        passSpotLights(environmentId, fragmentShaderBuilder, nodeId, variables);
    FieldOutput positionValue = inputs.get("position");
    FieldOutput normalValue = inputs.get("normal");
    FieldOutput albedoValue = inputs.get("albedo");
    FieldOutput emissionValue = inputs.get("emission");
    FieldOutput specularValue = inputs.get("specular");
    FieldOutput ambientOcclusionValue = inputs.get("ambientOcclusion");
    FieldOutput shininessValue = inputs.get("shininess");
    String position = positionValue.getRepresentation();
    String normal = normalValue.getRepresentation();
    String albedo = albedoValue != null ? albedoValue.getRepresentation() : "vec3(0.0)";
    String emission = emissionValue != null ? emissionValue.getRepresentation() : "vec3(0.0)";
    String specular = specularValue != null ? specularValue.getRepresentation() : "vec3(1.0)";
    String ambientOcclusion = ambientOcclusionValue != null ? ambientOcclusionValue.getRepresentation() : "1.0";
    String shininess = shininessValue != null ? shininessValue.getRepresentation() : "32.0";
    fragmentShaderBuilder.addMainLine("// Blinn-Phong Lighting node");
    String calculateLightingFunctionName = "calculateBlinnPhongLightingFunction_" + nodeId;
    fragmentShaderBuilder.addFunction(calculateLightingFunctionName, createCalculateLightingFunction(nodeId));
    String lightingVariable = "lighting_" + nodeId;
    fragmentShaderBuilder.addMainLine("Lighting " + lightingVariable + " = " + calculateLightingFunctionName + "(" + position + ", " + normal + ", " + shininess + ");");
    ShaderFieldType resultType = ShaderFieldTypeRegistry.findShaderFieldType(ShaderFieldType.Vector3);
    ObjectMap<String, DefaultFieldOutput> result = new ObjectMap<>();
    if (producedOutputs.contains("output")) {
        String name = "color_" + nodeId;
        fragmentShaderBuilder.addMainLine(resultType.getShaderType() + " " + name + " = " + emission + ".rgb + " + ambientOcclusion + " * u_ambientLight_" + nodeId + " * " + albedo + ".rgb;");
        fragmentShaderBuilder.addMainLine(name + " += " + lightingVariable + ".diffuse * " + albedo + ".rgb + " + lightingVariable + ".specular * " + specular + ".rgb;");
        result.put("output", new DefaultFieldOutput(resultType.getName(), name));
    }
    if (producedOutputs.contains("diffuse")) {
        result.put("diffuse", new DefaultFieldOutput(resultType.getName(), lightingVariable + ".diffuse"));
    }
    if (producedOutputs.contains("specularOut")) {
        result.put("specularOut", new DefaultFieldOutput(resultType.getName(), lightingVariable + ".specular"));
    }
    return result;
}
Also used : RenderPipelineBuffer(com.gempukku.libgdx.graph.pipeline.RenderPipelineBuffer) OrthographicCamera(com.badlogic.gdx.graphics.OrthographicCamera) Texture(com.badlogic.gdx.graphics.Texture) DefaultFieldOutput(com.gempukku.libgdx.graph.shader.node.DefaultFieldOutput) Array(com.badlogic.gdx.utils.Array) ObjectMap(com.badlogic.gdx.utils.ObjectMap) Lighting3DEnvironment(com.gempukku.libgdx.graph.plugin.lighting3d.Lighting3DEnvironment) DefaultFieldOutput(com.gempukku.libgdx.graph.shader.node.DefaultFieldOutput) TextureDescriptor(com.badlogic.gdx.graphics.g3d.utils.TextureDescriptor) LightColor(com.gempukku.libgdx.graph.plugin.lighting3d.LightColor) ShaderFieldType(com.gempukku.libgdx.graph.shader.field.ShaderFieldType)

Example 2 with LightColor

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

the class AmbientLightShaderNodeBuilder 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 String environmentId = data.getString("id", "");
    commonShaderBuilder.addUniformVariable("u_ambientLight_" + nodeId, "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();
            LightColor ambientColor = lights3DProvider.getAmbientLight(environment, shaderContext.getRenderableModel());
            if (ambientColor != null) {
                shader.setUniform(location, ambientColor.getRed(), ambientColor.getGreen(), ambientColor.getBlue(), 1f);
            } else {
                shader.setUniform(location, 0f, 0f, 0f, 1f);
            }
        }
    }, "Ambient light");
    return LibGDXCollections.singletonMap("ambient", new DefaultFieldOutput(ShaderFieldType.Vector4, "u_ambientLight_" + nodeId));
}
Also used : Lights3DProvider(com.gempukku.libgdx.graph.plugin.lighting3d.provider.Lights3DProvider) Lighting3DEnvironment(com.gempukku.libgdx.graph.plugin.lighting3d.Lighting3DEnvironment) LightColor(com.gempukku.libgdx.graph.plugin.lighting3d.LightColor) Lighting3DPrivateData(com.gempukku.libgdx.graph.plugin.lighting3d.Lighting3DPrivateData) DefaultFieldOutput(com.gempukku.libgdx.graph.shader.node.DefaultFieldOutput)

Example 3 with LightColor

use of com.gempukku.libgdx.graph.plugin.lighting3d.LightColor 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 4 with LightColor

use of com.gempukku.libgdx.graph.plugin.lighting3d.LightColor 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 5 with LightColor

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

Aggregations

LightColor (com.gempukku.libgdx.graph.plugin.lighting3d.LightColor)5 Lighting3DEnvironment (com.gempukku.libgdx.graph.plugin.lighting3d.Lighting3DEnvironment)5 DefaultFieldOutput (com.gempukku.libgdx.graph.shader.node.DefaultFieldOutput)5 Array (com.badlogic.gdx.utils.Array)4 ObjectMap (com.badlogic.gdx.utils.ObjectMap)4 Lighting3DPrivateData (com.gempukku.libgdx.graph.plugin.lighting3d.Lighting3DPrivateData)4 Lights3DProvider (com.gempukku.libgdx.graph.plugin.lighting3d.provider.Lights3DProvider)4 OrthographicCamera (com.badlogic.gdx.graphics.OrthographicCamera)1 Texture (com.badlogic.gdx.graphics.Texture)1 TextureDescriptor (com.badlogic.gdx.graphics.g3d.utils.TextureDescriptor)1 RenderPipelineBuffer (com.gempukku.libgdx.graph.pipeline.RenderPipelineBuffer)1 Directional3DLight (com.gempukku.libgdx.graph.plugin.lighting3d.Directional3DLight)1 Point3DLight (com.gempukku.libgdx.graph.plugin.lighting3d.Point3DLight)1 Spot3DLight (com.gempukku.libgdx.graph.plugin.lighting3d.Spot3DLight)1 ShaderFieldType (com.gempukku.libgdx.graph.shader.field.ShaderFieldType)1