[SOLVED] terrain splat and shadow pass

Hello,



I have a little problem with texture splatting and shadows:



shadow.jpg



the gray surface is a TerrainPage. Splatted textures cover the shadow cast on the terrain.



How can i tune the splat pass to see shadows through splatted textures?



Here’s what the program does.



Terrain rendering uses a PassNode. The first pass applies a material state to show the terrain when it has no textures:


MaterialState material = bindings.getRenderer().createMaterialState();
material.setEmissive(new ColorRGBA(0f, 0, 0, 1));
material.setSpecular(new ColorRGBA(0, 0, 0, 1));
material.setAmbient(new ColorRGBA(.5f, .5f, .5f, .5f));
material.setDiffuse(new ColorRGBA(.5f, .5f, .5f, .5f));
PassNodeState opaqueState = new PassNodeState();
opaqueState.setPassState(material);
passNodeTerrain.addPass(opaqueState);//passNodeTerrain is the PassNode that renders the TerrainPage



Each subsequent pass is built as in TestTerrainSplatting:

Splat TextureState

TextureState ts = bindings.getRenderer().createTextureState();
Texture t0 = TextureManager.loadTexture(image,
        Texture.MinificationFilter.Trilinear, Texture.MagnificationFilter.Bilinear, false);
t0.setImageLocation(imageUid);
t0.setWrap(Texture.WrapMode.Repeat);
t0.setApply(Texture.ApplyMode.Modulate);
t0.setScale(new Vector3f(90, 90, 1.0f));
ts.setTexture(t0, 0);
if (alpha != null) {
    addAlphaSplat(ts, layerIndex, alpha);
}
return ts;



addAlphaSplat(...)

Texture t1 = new Texture2D();
t1.setMinificationFilter(Texture.MinificationFilter.Trilinear);
t1.setMagnificationFilter(Texture.MagnificationFilter.Bilinear);
t1.setImage(alpha);
t1.setWrap(Texture.WrapMode.Repeat);
t1.setApply(Texture.ApplyMode.Combine);
t1.setCombineFuncRGB(Texture.CombinerFunctionRGB.Replace);
t1.setCombineSrc0RGB(Texture.CombinerSource.Previous);
t1.setCombineOp0RGB(Texture.CombinerOperandRGB.SourceColor);
t1.setCombineFuncAlpha(Texture.CombinerFunctionAlpha.Replace);
t1.setImageLocation("PassLayer" + layerIndex);
ts.setTexture(t1, ts.getNumberOfSetTextures());



BlendState applied to the PassNodeState with splat and alpha textures

BlendState as = bindings.getRenderer().createBlendState();
as.setBlendEnabled(true);
as.setSourceFunction(BlendState.SourceFunction.SourceAlpha);
as.setDestinationFunction(BlendState.DestinationFunction.OneMinusSourceAlpha);
as.setTestEnabled(true);
as.setTestFunction(BlendState.TestFunction.GreaterThan);
as.setEnabled(true);



There is no lightmap.

Looking at the picture i think that shadows are there and i just need to say to the splat layers that they have to "blend" someway with those shadows.

I noticed that if the alpha mask values are not fully opaque the shadows can be seen through the splat layer:

shadow2.jpg

Thanks.

Problem solved switching the ShadowRenderPass from Additive to Modulative.



As a note, in Modulative mode the alpha component of the ambient color of the shadow caster light seems to control the opacity of the shadows (lower alpha = darker shadow) whereas in Additive mode the alpha component is irrelevant.