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