use of com.gempukku.libgdx.graph.shader.ShaderContext 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);
}
use of com.gempukku.libgdx.graph.shader.ShaderContext 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);
}
use of com.gempukku.libgdx.graph.shader.ShaderContext 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);
}
use of com.gempukku.libgdx.graph.shader.ShaderContext 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);
}
Aggregations