
com.gempukku.libgdx.graph.plugin.lighting3d.producer.AmbientLightShaderNodeBuilder Maven / Gradle / Ivy
package com.gempukku.libgdx.graph.plugin.lighting3d.producer;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.utils.JsonValue;
import com.badlogic.gdx.utils.ObjectMap;
import com.badlogic.gdx.utils.ObjectSet;
import com.gempukku.libgdx.graph.plugin.lighting3d.Lighting3DEnvironment;
import com.gempukku.libgdx.graph.plugin.lighting3d.Lighting3DPrivateData;
import com.gempukku.libgdx.graph.shader.BasicShader;
import com.gempukku.libgdx.graph.shader.GraphShader;
import com.gempukku.libgdx.graph.shader.GraphShaderContext;
import com.gempukku.libgdx.graph.shader.ShaderContext;
import com.gempukku.libgdx.graph.shader.ShaderFieldType;
import com.gempukku.libgdx.graph.shader.UniformRegistry;
import com.gempukku.libgdx.graph.shader.builder.CommonShaderBuilder;
import com.gempukku.libgdx.graph.shader.node.ConfigurationCommonShaderNodeBuilder;
import com.gempukku.libgdx.graph.shader.node.DefaultFieldOutput;
import com.gempukku.libgdx.graph.util.LibGDXCollections;
public class AmbientLightShaderNodeBuilder extends ConfigurationCommonShaderNodeBuilder {
public AmbientLightShaderNodeBuilder() {
super(new AmbientLightShaderNodeConfiguration());
}
@Override
protected ObjectMap buildCommonNode(boolean designTime, String nodeId, final JsonValue data, ObjectMap inputs, ObjectSet producedOutputs, CommonShaderBuilder commonShaderBuilder, GraphShaderContext graphShaderContext, GraphShader graphShader) {
commonShaderBuilder.addUniformVariable("u_ambientLight", "vec3", true,
new UniformRegistry.UniformSetter() {
@Override
public void set(BasicShader shader, int location, ShaderContext shaderContext) {
Lighting3DEnvironment environment = shaderContext.getPrivatePluginData(Lighting3DPrivateData.class).getEnvironment(data.getString("id", ""));
if (environment != null && environment.getAmbientColor() != null) {
Color ambientColor = environment.getAmbientColor();
shader.setUniform(location, ambientColor.r, ambientColor.g, ambientColor.b);
} else {
shader.setUniform(location, 0f, 0f, 0f);
}
}
});
return LibGDXCollections.singletonMap("ambient", new DefaultFieldOutput(ShaderFieldType.Vector3, "u_ambientLight"));
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy