libGDX 3D阴影 [英] libGDX 3D Shadows
本文介绍了libGDX 3D阴影的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
即时通讯使用libGDX,这是一个桌面项目。
Im using libGDX and this is a Desktop project.
我有2个型号,一个是性格,其他的地图,你可以在下面的图片中看到:
I have 2 models, one is the character and the other is the map, as you can see in the image below:
我的问题是:
我如何突出人物的地板上的影子?
How do I project the shadow of the character on the floor?
正如你所看到的字符没有阴影,因此周围环境光。我有什么用,或我怎么做到这一点?我应该假的阴影还是有实际的方式来投射阴影?
As you can see the character doesn't have a shadow, thus the Ambience Light. What do I have to use or how do I achieve this? Should I fake a shadow or is there a real way to project shadows?
有任何意见或sugestions欢迎。
Any comments or sugestions are welcome.
推荐答案
您可以使用下面的code:
You can use following code:
Environment environment;
DirectionalShadowLight shadowLight;
@Override
public void show() {
modelBatch = new ModelBatch();
environment = new Environment();
environment.set(new ColorAttribute(ColorAttribute.AmbientLight, 1.0f, 1f, .6f, 1f));
environment.add((shadowLight = new DirectionalShadowLight(1024, 1024, 60f, 60f, .1f, 50f))
.set(1f, 1f, 1f, 40.0f, -35f, -35f));
environment.shadowMap = shadowLight;
shadowBatch = new ModelBatch(new DepthShaderProvider());
}
@Override
public void render(float delta) {
//create shadow texture
shadowLight.begin(Vector3.Zero, camera.direction);
shadowBatch.begin(shadowLight.getCamera());
shadowBatch.render(instances);
shadowBatch.end();
shadowLight.end();
//render scene
Gdx.gl.glClearColor(0, 0, 0, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT | GL20.GL_DEPTH_BUFFER_BIT);
modelBatch.begin(cam);
modelBatch.render(instances, environment); //environment has shadowMap!
modelBatch.end();
}
这篇关于libGDX 3D阴影的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文