use of io.github.voidzombie.nhglib.graphics.lights.NhgLight in project nhglib by VoidZombie.
the class TiledForwardShader method render.
@Override
public void render(Renderable renderable) {
for (int light = 0; light < lightsToRender.size; light++) {
NhgLight nhgLight = lightsToRender.get(light);
String lightUniform = "u_lightsList[" + light + "].";
Vector3 viewSpacePosition = getViewSpacePosition(nhgLight);
Vector3 viewSpaceDirection = getViewSpaceDirection(nhgLight);
shaderProgram.setUniformi(lightUniform + "type", nhgLight.type.ordinal());
shaderProgram.setUniformf(lightUniform + "position", viewSpacePosition);
shaderProgram.setUniformf(lightUniform + "direction", viewSpaceDirection);
shaderProgram.setUniformf(lightUniform + "intensity", nhgLight.intensity);
shaderProgram.setUniformf(lightUniform + "innerAngle", nhgLight.innerAngle);
shaderProgram.setUniformf(lightUniform + "outerAngle", nhgLight.outerAngle);
VectorPool.freeVector3(viewSpacePosition, viewSpaceDirection);
}
updateBones(renderable);
super.render(renderable);
}
use of io.github.voidzombie.nhglib.graphics.lights.NhgLight in project nhglib by VoidZombie.
the class TiledForwardShader method createLightTexture.
private void createLightTexture() {
int i;
for (i = 0; i < 100; i++) {
lightsFrustum.get(i).clear();
}
for (i = 0; i < lightsToRender.size; i++) {
NhgLight light = lightsToRender.get(i);
frustums.checkFrustums(light.position, light.radius, lightsFrustum, i);
color.set(light.color);
color.a = light.radius / 255f;
lightInfoPixmap.setColor(color);
lightInfoPixmap.drawPixel(0, i);
}
lightInfoTexture.draw(lightInfoPixmap, 0, 0);
for (int row = 0; row < 100; row++) {
int column = 0;
float r = lightsFrustum.get(row).size;
color.set(r / 255.0f, 0, 0, 0);
lightPixmap.setColor(color);
lightPixmap.drawPixel(column, row);
column++;
for (int k = 0; k < lightsFrustum.get(row).size; k++) {
int j = (lightsFrustum.get(row).get(k));
color.set(((float) j) / 255.0f, 0, 0, 0);
lightPixmap.setColor(color);
lightPixmap.drawPixel(column, row);
column++;
}
}
lightTexture.draw(lightPixmap, 0, 0);
}
use of io.github.voidzombie.nhglib.graphics.lights.NhgLight in project nhglib by VoidZombie.
the class LightComponentJson method parse.
@Override
public void parse(JsonValue jsonValue) {
GraphicsSystem graphicsSystem = entities.getEntitySystem(GraphicsSystem.class);
LightComponent lightComponent = entities.createComponent(entity, LightComponent.class);
LightType lightType = LightType.fromString(jsonValue.getString("lightType"));
float range = jsonValue.getFloat("range", 1f);
float intensity = jsonValue.getFloat("intensity", 1f);
float innerAngle = jsonValue.getFloat("innerAngle", 0f);
float outerAngle = jsonValue.getFloat("outerAngle", 0f);
if (innerAngle > outerAngle) {
innerAngle = outerAngle;
}
if (range < 1.0f) {
range = 1.0f;
}
JsonValue colorJson = jsonValue.get("color");
Color color = new Color(colorJson.getFloat("r"), colorJson.getFloat("g"), colorJson.getFloat("b"), colorJson.getFloat("a"));
/*JsonValue directionJson = jsonValue.get("direction");
Vector3 direction = VectorPool.getVector3();
if (directionJson != null) {
direction.set(
directionJson.getFloat("x"),
directionJson.getFloat("y"),
directionJson.getFloat("z"));
}*/
NhgLight light = null;
switch(lightType) {
case DIRECTIONAL_LIGHT:
light = NhgLight.directional(intensity, color);
break;
case POINT_LIGHT:
light = NhgLight.point(intensity, range, color);
break;
case SPOT_LIGHT:
light = NhgLight.spot(intensity, range, innerAngle, outerAngle, color);
break;
}
if (light == null)
return;
Environment environment = graphicsSystem.getEnvironment();
NhgLightsAttribute attribute = (NhgLightsAttribute) environment.get(NhgLightsAttribute.Type);
if (attribute == null) {
attribute = new NhgLightsAttribute();
environment.set(attribute);
}
attribute.lights.add(light);
lightComponent.light = light;
lightComponent.type = lightType;
output = lightComponent;
}
Aggregations