Search in sources :

Example 1 with BasicShader

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

the class TextureRegionShaderFieldType method addAsVertexAttribute.

@Override
public GraphShaderNodeBuilder.FieldOutput addAsVertexAttribute(VertexShaderBuilder vertexShaderBuilder, 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();
    vertexShaderBuilder.addUniformVariable(textureVariableName, "sampler2D", false, new UniformRegistry.UniformSetter() {

        @Override
        public void set(BasicShader shader, int location, ShaderContext shaderContext) {
            Object value = 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());
    return new DefaultFieldOutput(ShaderFieldType.TextureRegion, uvTransformAttributeName, 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 2 with BasicShader

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

the class TextureRegionShaderFieldType method addAsLocalUniform.

@Override
public GraphShaderNodeBuilder.FieldOutput addAsLocalUniform(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", false, new UniformRegistry.UniformSetter() {

        @Override
        public void set(BasicShader shader, int location, ShaderContext shaderContext) {
            Object value = shaderContext.getLocalProperty(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", false, new UniformRegistry.UniformSetter() {

        @Override
        public void set(BasicShader shader, int location, ShaderContext shaderContext) {
            Object value = shaderContext.getLocalProperty(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 3 with BasicShader

use of com.gempukku.libgdx.graph.shader.BasicShader 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 4 with BasicShader

use of com.gempukku.libgdx.graph.shader.BasicShader 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)

Aggregations

Texture (com.badlogic.gdx.graphics.Texture)4 TextureRegion (com.badlogic.gdx.graphics.g2d.TextureRegion)4 TextureDescriptor (com.badlogic.gdx.graphics.g3d.utils.TextureDescriptor)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 DefaultFieldOutput (com.gempukku.libgdx.graph.shader.node.DefaultFieldOutput)4 VertexAttribute (com.badlogic.gdx.graphics.VertexAttribute)2