use of com.badlogic.gdx.graphics.g3d.environment.DirectionalLight in project libgdx by libgdx.
the class ViewportTest3 method create.
public void create() {
modelBatch = new ModelBatch();
modelBuilder = new ModelBuilder();
environment = new Environment();
environment.set(new ColorAttribute(ColorAttribute.AmbientLight, 0.3f, 0.3f, 0.3f, 1.f));
shadowLight = new DirectionalLight();
shadowLight.set(0.8f, 0.8f, 0.8f, -0.5f, -1f, 0.7f);
environment.add(shadowLight);
modelBatch = new ModelBatch();
camera = new PerspectiveCamera();
camera.fieldOfView = 67;
camera.near = 0.1f;
camera.far = 300f;
camera.position.set(0, 0, 100);
camera.lookAt(0, 0, 0);
viewports = ViewportTest1.getViewports(camera);
viewport = viewports.first();
names = ViewportTest1.getViewportNames();
name = names.first();
ModelBuilder modelBuilder = new ModelBuilder();
Model boxModel = modelBuilder.createBox(50f, 50f, 50f, new Material(ColorAttribute.createDiffuse(Color.GREEN)), Usage.Position | Usage.Normal);
boxInstance = new ModelInstance(boxModel);
boxInstance.transform.rotate(1, 0, 0, 30);
boxInstance.transform.rotate(0, 1, 0, 30);
Gdx.input.setInputProcessor(new InputAdapter() {
public boolean keyDown(int keycode) {
if (keycode == Input.Keys.SPACE) {
int index = (viewports.indexOf(viewport, true) + 1) % viewports.size;
name = names.get(index);
viewport = viewports.get(index);
resize(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
}
return false;
}
});
}
use of com.badlogic.gdx.graphics.g3d.environment.DirectionalLight in project nhglib by VoidZombie.
the class ShaderUtils method createPrefix.
public static String createPrefix(Renderable renderable, boolean skinned) {
String prefix = "";
final int n = renderable.meshPart.mesh.getVertexAttributes().size();
for (int i = 0; i < n; i++) {
final VertexAttribute attr = renderable.meshPart.mesh.getVertexAttributes().get(i);
if (attr.usage == VertexAttributes.Usage.BoneWeight) {
prefix += "#define boneWeight" + attr.unit + "Flag\n";
}
}
if (skinned) {
prefix += "#define skinningFlag\n";
}
Environment environment = renderable.environment;
// Ambient lighting
ColorAttribute ambientLightAttribute = (ColorAttribute) environment.get(ColorAttribute.AmbientLight);
if (ambientLightAttribute != null) {
prefix += "#define ambientLighting\n";
}
// Directional lighting
DirectionalLightsAttribute directionalLightsAttribute = (DirectionalLightsAttribute) environment.get(DirectionalLightsAttribute.Type);
if (directionalLightsAttribute != null) {
Array<DirectionalLight> directionalLights = directionalLightsAttribute.lights;
if (directionalLights.size > 0) {
prefix += "#define numDirectionalLights " + directionalLights.size + "\n";
}
}
// Point lighting
PointLightsAttribute pointLightsAttribute = (PointLightsAttribute) environment.get(PointLightsAttribute.Type);
if (pointLightsAttribute != null) {
Array<PointLight> pointLights = pointLightsAttribute.lights;
if (pointLights.size > 0) {
prefix += "#define numPointLights " + pointLights.size + "\n";
}
}
// Spot lighting
SpotLightsAttribute spotLightsAttribute = (SpotLightsAttribute) environment.get(SpotLightsAttribute.Type);
if (spotLightsAttribute != null) {
Array<SpotLight> spotLights = spotLightsAttribute.lights;
if (spotLights.size > 0) {
prefix += "#define numSpotLights " + spotLights.size + "\n";
}
}
return prefix;
}
Aggregations