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());
}
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));
}
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");
}
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();
}
}
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>());
}
Aggregations