Search in sources :

Example 61 with DefaultFieldOutput

use of com.gempukku.libgdx.graph.shader.node.DefaultFieldOutput 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 62 with DefaultFieldOutput

use of com.gempukku.libgdx.graph.shader.node.DefaultFieldOutput in project gdx-graph by MarcinSc.

the class TextureRegionShaderFieldType method addAsFragmentAttribute.

@Override
public GraphShaderNodeBuilder.FieldOutput addAsFragmentAttribute(VertexShaderBuilder vertexShaderBuilder, FragmentShaderBuilder fragmentShaderBuilder, JsonValue data, final PropertySource propertySource) {
    final TextureDescriptor<Texture> textureDescriptor = new TextureDescriptor<>();
    if (data.has("minFilter"))
        textureDescriptor.minFilter = Texture.TextureFilter.valueOf(data.getString("minFilter"));
    if (data.has("magFilter"))
        textureDescriptor.magFilter = Texture.TextureFilter.valueOf(data.getString("magFilter"));
    if (data.has("uWrap"))
        textureDescriptor.uWrap = Texture.TextureWrap.valueOf(data.getString("uWrap"));
    if (data.has("vWrap"))
        textureDescriptor.vWrap = Texture.TextureWrap.valueOf(data.getString("vWrap"));
    String textureVariableName = propertySource.getUniformName();
    String uvTransformAttributeName = propertySource.getAttributeName();
    String uvTransformVariableName = propertySource.getVariableName();
    fragmentShaderBuilder.addUniformVariable(textureVariableName, "sampler2D", false, new UniformRegistry.UniformSetter() {

        @Override
        public void set(BasicShader shader, int location, ShaderContext shaderContext) {
            Object value = shaderContext.getLocalProperty(propertySource.getPropertyName());
            value = propertySource.getValueToUse(value);
            if (value == null)
                value = new TextureRegion(shader.getDefaultTexture());
            textureDescriptor.texture = ((TextureRegion) value).getTexture();
            shader.setUniform(location, textureDescriptor);
        }
    }, "Texture property - " + propertySource.getPropertyName());
    vertexShaderBuilder.addAttributeVariable(new VertexAttribute(1024, 4, uvTransformAttributeName), "vec4", "TextureUV property - " + propertySource.getPropertyName());
    if (!vertexShaderBuilder.hasVaryingVariable(uvTransformVariableName)) {
        vertexShaderBuilder.addVaryingVariable(uvTransformVariableName, "vec4");
        vertexShaderBuilder.addMainLine(uvTransformVariableName + " = " + uvTransformAttributeName + ";");
        fragmentShaderBuilder.addVaryingVariable(uvTransformVariableName, "vec4");
    }
    return new DefaultFieldOutput(ShaderFieldType.TextureRegion, uvTransformVariableName, textureVariableName);
}
Also used : BasicShader(com.gempukku.libgdx.graph.shader.BasicShader) Texture(com.badlogic.gdx.graphics.Texture) DefaultFieldOutput(com.gempukku.libgdx.graph.shader.node.DefaultFieldOutput) TextureRegion(com.badlogic.gdx.graphics.g2d.TextureRegion) UniformRegistry(com.gempukku.libgdx.graph.shader.UniformRegistry) VertexAttribute(com.badlogic.gdx.graphics.VertexAttribute) ShaderContext(com.gempukku.libgdx.graph.shader.ShaderContext) TextureDescriptor(com.badlogic.gdx.graphics.g3d.utils.TextureDescriptor)

Example 63 with DefaultFieldOutput

use of com.gempukku.libgdx.graph.shader.node.DefaultFieldOutput in project gdx-graph by MarcinSc.

the class TextureRegionShaderFieldType method addAsGlobalUniform.

@Override
public GraphShaderNodeBuilder.FieldOutput addAsGlobalUniform(CommonShaderBuilder commonShaderBuilder, JsonValue data, final PropertySource propertySource) {
    final String name = propertySource.getPropertyName();
    final TextureDescriptor<Texture> textureDescriptor = new TextureDescriptor<>();
    if (data.has("minFilter"))
        textureDescriptor.minFilter = Texture.TextureFilter.valueOf(data.getString("minFilter"));
    if (data.has("magFilter"))
        textureDescriptor.magFilter = Texture.TextureFilter.valueOf(data.getString("magFilter"));
    if (data.has("uWrap"))
        textureDescriptor.uWrap = Texture.TextureWrap.valueOf(data.getString("uWrap"));
    if (data.has("vWrap"))
        textureDescriptor.vWrap = Texture.TextureWrap.valueOf(data.getString("vWrap"));
    String textureVariableName = propertySource.getUniformName();
    String uvTransformVariableName = "u_uvTransform_" + propertySource.getPropertyIndex();
    commonShaderBuilder.addUniformVariable(textureVariableName, "sampler2D", true, new UniformRegistry.UniformSetter() {

        @Override
        public void set(BasicShader shader, int location, ShaderContext shaderContext) {
            Object value = shaderContext.getGlobalProperty(name);
            value = propertySource.getValueToUse(value);
            if (value == null)
                value = new TextureRegion(shader.getDefaultTexture());
            textureDescriptor.texture = ((TextureRegion) value).getTexture();
            shader.setUniform(location, textureDescriptor);
        }
    }, "Texture property - " + name);
    commonShaderBuilder.addUniformVariable(uvTransformVariableName, "vec4", true, new UniformRegistry.UniformSetter() {

        @Override
        public void set(BasicShader shader, int location, ShaderContext shaderContext) {
            Object value = shaderContext.getGlobalProperty(name);
            value = propertySource.getValueToUse(value);
            if (value == null)
                value = new TextureRegion(shader.getDefaultTexture());
            TextureRegion region = (TextureRegion) value;
            shader.setUniform(location, region.getU(), region.getV(), region.getU2() - region.getU(), region.getV2() - region.getV());
        }
    }, "Texture UV property - " + name);
    return new DefaultFieldOutput(getName(), uvTransformVariableName, textureVariableName);
}
Also used : BasicShader(com.gempukku.libgdx.graph.shader.BasicShader) Texture(com.badlogic.gdx.graphics.Texture) DefaultFieldOutput(com.gempukku.libgdx.graph.shader.node.DefaultFieldOutput) TextureRegion(com.badlogic.gdx.graphics.g2d.TextureRegion) UniformRegistry(com.gempukku.libgdx.graph.shader.UniformRegistry) ShaderContext(com.gempukku.libgdx.graph.shader.ShaderContext) TextureDescriptor(com.badlogic.gdx.graphics.g3d.utils.TextureDescriptor)

Example 64 with DefaultFieldOutput

use of com.gempukku.libgdx.graph.shader.node.DefaultFieldOutput in project gdx-graph by MarcinSc.

the class ValueVector2ShaderNodeBuilder method buildCommonNode.

@Override
protected ObjectMap<String, ? extends FieldOutput> buildCommonNode(boolean designTime, String nodeId, JsonValue data, ObjectMap<String, FieldOutput> inputs, ObjectSet<String> producedOutputs, CommonShaderBuilder commonShaderBuilder, GraphShaderContext graphShaderContext, GraphShader graphShader) {
    float v1 = data.getFloat("v1");
    float v2 = data.getFloat("v2");
    return LibGDXCollections.singletonMap("value", new DefaultFieldOutput(ShaderFieldType.Vector2, "vec2(" + format(v1) + ", " + format(v2) + ")"));
}
Also used : DefaultFieldOutput(com.gempukku.libgdx.graph.shader.node.DefaultFieldOutput)

Example 65 with DefaultFieldOutput

use of com.gempukku.libgdx.graph.shader.node.DefaultFieldOutput in project gdx-graph by MarcinSc.

the class Vector4ShaderFieldType method addAsFragmentAttribute.

@Override
public GraphShaderNodeBuilder.FieldOutput addAsFragmentAttribute(VertexShaderBuilder vertexShaderBuilder, FragmentShaderBuilder fragmentShaderBuilder, JsonValue data, PropertySource propertySource) {
    String attributeName = propertySource.getAttributeName();
    String variableName = propertySource.getVariableName();
    vertexShaderBuilder.addAttributeVariable(new VertexAttribute(1024, 4, attributeName), getShaderType(), "Vector4 property - " + propertySource.getPropertyName());
    if (!vertexShaderBuilder.hasVaryingVariable(variableName)) {
        vertexShaderBuilder.addVaryingVariable(variableName, getShaderType());
        vertexShaderBuilder.addMainLine(variableName + " = " + attributeName + ";");
        fragmentShaderBuilder.addVaryingVariable(variableName, getShaderType());
    }
    return new DefaultFieldOutput(getName(), variableName);
}
Also used : VertexAttribute(com.badlogic.gdx.graphics.VertexAttribute) DefaultFieldOutput(com.gempukku.libgdx.graph.shader.node.DefaultFieldOutput)

Aggregations

DefaultFieldOutput (com.gempukku.libgdx.graph.shader.node.DefaultFieldOutput)106 ShaderFieldType (com.gempukku.libgdx.graph.shader.field.ShaderFieldType)43 ObjectMap (com.badlogic.gdx.utils.ObjectMap)17 VertexAttribute (com.badlogic.gdx.graphics.VertexAttribute)7 Texture (com.badlogic.gdx.graphics.Texture)6 TextureDescriptor (com.badlogic.gdx.graphics.g3d.utils.TextureDescriptor)6 Array (com.badlogic.gdx.utils.Array)6 LightColor (com.gempukku.libgdx.graph.plugin.lighting3d.LightColor)5 Lighting3DEnvironment (com.gempukku.libgdx.graph.plugin.lighting3d.Lighting3DEnvironment)5 TextureRegion (com.badlogic.gdx.graphics.g2d.TextureRegion)4 Lighting3DPrivateData (com.gempukku.libgdx.graph.plugin.lighting3d.Lighting3DPrivateData)4 Lights3DProvider (com.gempukku.libgdx.graph.plugin.lighting3d.provider.Lights3DProvider)4 BasicShader (com.gempukku.libgdx.graph.shader.BasicShader)4 ShaderContext (com.gempukku.libgdx.graph.shader.ShaderContext)4 UniformRegistry (com.gempukku.libgdx.graph.shader.UniformRegistry)4 JsonValue (com.badlogic.gdx.utils.JsonValue)2 BoneTransformFieldType (com.gempukku.libgdx.graph.plugin.boneanimation.property.BoneTransformFieldType)2 ClampMethod (com.gempukku.libgdx.graph.shader.ClampMethod)2 Color (com.badlogic.gdx.graphics.Color)1 OrthographicCamera (com.badlogic.gdx.graphics.OrthographicCamera)1