Search in sources :

Example 1 with MapWritablePropertyContainer

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

the class GraphModelsImpl method registerTag.

public void registerTag(String tag, GraphShader shader) {
    if (modelsByTag.containsKey(tag))
        throw new IllegalStateException("There is already a shader with tag: " + tag);
    modelsByTag.put(tag, new ObjectSet<GraphModel>());
    propertiesByTag.put(tag, shader.getProperties());
    propertiesForTag.put(tag, new MapWritablePropertyContainer());
}
Also used : GraphModel(com.gempukku.libgdx.graph.plugin.models.GraphModel) MapWritablePropertyContainer(com.gempukku.libgdx.graph.shader.property.MapWritablePropertyContainer)

Example 2 with MapWritablePropertyContainer

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

the class SpriteShaderTestScene method initializeScene.

@Override
public void initializeScene() {
    camera = new OrthographicCamera();
    pipelineRenderer = loadPipelineRenderer();
    ArrayValuePerVertex<Vector2> uvPerVertex = new ArrayValuePerVertex<>(new Vector2(0, 0), new Vector2(1, 0), new Vector2(0, 1), new Vector2(1, 1));
    GraphModels graphModels = pipelineRenderer.getPluginData(GraphModels.class);
    spriteBatch = new MultiPageSpriteBatchModel(true, 2, graphModels, "Test");
    MapWritablePropertyContainer sprite1 = new MapWritablePropertyContainer();
    sprite1.setValue("Position", new Vector3(0, 0, -10));
    sprite1.setValue("UV", uvPerVertex);
    ArrayValuePerVertex<Vector2> colorPerVertex = new ArrayValuePerVertex<>(new Vector2(0, 1), new Vector2(1, 0), new Vector2(0, 0), new Vector2(1, 1));
    sprite1.setValue("Vertex Color", colorPerVertex);
    MapWritablePropertyContainer sprite2 = new MapWritablePropertyContainer();
    sprite2.setValue("Position", new Vector3(150, 0, -10));
    sprite2.setValue("UV", uvPerVertex);
    spriteBatch.addSprite(new DefaultRenderableSprite(sprite1));
    spriteBatch.addSprite(new DefaultRenderableSprite(sprite2));
    graphModels.setGlobalProperty("Test", "Color", new Vector2(1f, 1f));
}
Also used : DefaultRenderableSprite(com.gempukku.libgdx.graph.util.sprite.DefaultRenderableSprite) GraphModels(com.gempukku.libgdx.graph.plugin.models.GraphModels) Vector2(com.badlogic.gdx.math.Vector2) OrthographicCamera(com.badlogic.gdx.graphics.OrthographicCamera) Vector3(com.badlogic.gdx.math.Vector3) MapWritablePropertyContainer(com.gempukku.libgdx.graph.shader.property.MapWritablePropertyContainer) ArrayValuePerVertex(com.gempukku.libgdx.graph.util.ArrayValuePerVertex) MultiPageSpriteBatchModel(com.gempukku.libgdx.graph.util.sprite.MultiPageSpriteBatchModel)

Example 3 with MapWritablePropertyContainer

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

the class ParticlesShaderTestScene method createEffect.

private void createEffect(GraphParticleEffects particleEffects, Vector3 center, float size) {
    SpherePositionGenerator positionGenerator = new SpherePositionGenerator();
    positionGenerator.getCenter().set(center);
    positionGenerator.setRadius(0.3f);
    DefaultParticleGenerator particleGenerator = new DefaultParticleGenerator(timeKeeper, 1f, 0, 10);
    particleGenerator.setPositionGenerator(positionGenerator);
    MapWritablePropertyContainer properties = new MapWritablePropertyContainer();
    properties.setValue("Size", size);
    CommonPropertiesParticleEffectAdapter particleEffectAdapter = new CommonPropertiesParticleEffectAdapter(particleEffects, Vector3.Zero, null, properties);
    particleEffectAdapter.addTag("Test", particleGenerator);
    particleEffectAdapter.startEffect("Test");
}
Also used : DefaultParticleGenerator(com.gempukku.libgdx.graph.util.particles.generator.DefaultParticleGenerator) SpherePositionGenerator(com.gempukku.libgdx.graph.util.particles.generator.SpherePositionGenerator) CommonPropertiesParticleEffectAdapter(com.gempukku.libgdx.graph.util.particles.CommonPropertiesParticleEffectAdapter) MapWritablePropertyContainer(com.gempukku.libgdx.graph.shader.property.MapWritablePropertyContainer)

Example 4 with MapWritablePropertyContainer

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

the class ModelShaderPreviewWidget method createShader.

private void createShader(final Graph<? extends GraphNode, ? extends GraphConnection, ? extends GraphProperty> graph) {
    try {
        timeKeeper = new DefaultTimeKeeper();
        graphShader = GraphShaderBuilder.buildModelShader("Test", WhitePixel.sharedInstance.texture, graph, true);
        frameBuffer = new FrameBuffer(Pixmap.Format.RGBA8888, width, height, false);
        createModel();
        MapWritablePropertyContainer globalPropertyContainer = new MapWritablePropertyContainer();
        for (GraphProperty property : graph.getProperties()) {
            if (property.getLocation() == PropertyLocation.Global_Uniform) {
                ShaderFieldType propertyType = ShaderFieldTypeRegistry.findShaderFieldType(property.getType());
                globalPropertyContainer.setValue(property.getName(), propertyType.convertFromJson(property.getData()));
            }
        }
        shaderContext.setGlobalPropertyContainer(globalPropertyContainer);
        localPropertyContainer = new MapWritablePropertyContainer();
        for (GraphProperty property : graph.getProperties()) {
            if (property.getLocation() == PropertyLocation.Uniform) {
                ShaderFieldType propertyType = ShaderFieldTypeRegistry.findShaderFieldType(property.getType());
                Object value = propertyType.convertFromJson(property.getData());
                if (propertyType.isTexture()) {
                    if (value != null) {
                        try {
                            Texture texture = new Texture(Gdx.files.absolute((String) value));
                            graphShader.addManagedResource(texture);
                            localPropertyContainer.setValue(property.getName(), new TextureRegion(texture));
                        } catch (Exception exp) {
                            localPropertyContainer.setValue(property.getName(), WhitePixel.sharedInstance.textureRegion);
                        }
                    } else {
                        localPropertyContainer.setValue(property.getName(), WhitePixel.sharedInstance.textureRegion);
                    }
                }
            }
        }
        shaderContext.setTimeProvider(timeKeeper);
        shaderInitialized = true;
    } catch (Exception exp) {
        exp.printStackTrace();
        if (graphShader != null)
            graphShader.dispose();
    }
}
Also used : DefaultTimeKeeper(com.gempukku.libgdx.graph.util.DefaultTimeKeeper) TextureRegion(com.badlogic.gdx.graphics.g2d.TextureRegion) GraphProperty(com.gempukku.libgdx.graph.data.GraphProperty) FrameBuffer(com.badlogic.gdx.graphics.glutils.FrameBuffer) MapWritablePropertyContainer(com.gempukku.libgdx.graph.shader.property.MapWritablePropertyContainer) ShaderFieldType(com.gempukku.libgdx.graph.shader.field.ShaderFieldType)

Example 5 with MapWritablePropertyContainer

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

the class GraphParticleEffectsImpl method registerEffect.

public void registerEffect(String tag, ParticlesGraphShader shader) {
    if (effectsConfiguration.containsKey(tag))
        throw new IllegalStateException("Duplicate particle effect with tag - " + tag);
    Array<VertexAttribute> vertexAttributeArray = new Array<>(VertexAttribute.class);
    for (ObjectMap.Entry<String, BasicShader.Attribute> attribute : shader.getAttributes()) {
        String attributeName = attribute.key;
        vertexAttributeArray.add(new VertexAttribute(1024, attribute.value.getComponentCount(), attributeName));
    }
    VertexAttributes vertexAttributes = new VertexAttributes(vertexAttributeArray.toArray());
    effectsConfiguration.put(tag, new ParticleEffectConfiguration(vertexAttributes, shader.getProperties(), shader.getMaxNumberOfParticles()));
    globalProperties.put(tag, new MapWritablePropertyContainer());
    effectsByTag.put(tag, new ObjectSet<GraphParticleEffectImpl>());
}
Also used : VertexAttribute(com.badlogic.gdx.graphics.VertexAttribute) VertexAttributes(com.badlogic.gdx.graphics.VertexAttributes) MapWritablePropertyContainer(com.gempukku.libgdx.graph.shader.property.MapWritablePropertyContainer) Array(com.badlogic.gdx.utils.Array) ObjectMap(com.badlogic.gdx.utils.ObjectMap) VertexAttribute(com.badlogic.gdx.graphics.VertexAttribute)

Aggregations

MapWritablePropertyContainer (com.gempukku.libgdx.graph.shader.property.MapWritablePropertyContainer)6 OrthographicCamera (com.badlogic.gdx.graphics.OrthographicCamera)1 VertexAttribute (com.badlogic.gdx.graphics.VertexAttribute)1 VertexAttributes (com.badlogic.gdx.graphics.VertexAttributes)1 TextureRegion (com.badlogic.gdx.graphics.g2d.TextureRegion)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 FrameBuffer (com.badlogic.gdx.graphics.glutils.FrameBuffer)1 Vector2 (com.badlogic.gdx.math.Vector2)1 Vector3 (com.badlogic.gdx.math.Vector3)1 Array (com.badlogic.gdx.utils.Array)1 ObjectMap (com.badlogic.gdx.utils.ObjectMap)1 GraphProperty (com.gempukku.libgdx.graph.data.GraphProperty)1 GraphModel (com.gempukku.libgdx.graph.plugin.models.GraphModel)1 GraphModelInstance (com.gempukku.libgdx.graph.plugin.models.GraphModelInstance)1 GraphModels (com.gempukku.libgdx.graph.plugin.models.GraphModels)1 ShaderFieldType (com.gempukku.libgdx.graph.shader.field.ShaderFieldType)1 ArrayValuePerVertex (com.gempukku.libgdx.graph.util.ArrayValuePerVertex)1