paroj wrote: ↑Thu Mar 06, 2025 11:32 pm
did you try PSSMShadowCameraSetup.create()?
Yeah, this works.
But if I use SHADOWTYPE_TEXTURE_MODULATIVE_INTEGRATED, it works fine, but the texture doesn’t receive shadows from other entities. And if I use SHADOWTYPE_TEXTURE_ADDITIVE I get an error.
This is how I initialize shadows in the project:
Code: Select all
private void InitShadows()
{
scnMgr.setShadowTechnique(ShadowTechnique.SHADOWTYPE_TEXTURE_ADDITIVE);
//scnMgr.setShadowTechnique(ShadowTechnique.SHADOWTYPE_TEXTURE_MODULATIVE_INTEGRATED);
scnMgr.setShadowTextureCountPerLightType(Light.LightTypes.LT_DIRECTIONAL, 3);
scnMgr.setShadowDirLightTextureOffset(0);
scnMgr.setShadowTextureCount(3);
scnMgr.setShadowTextureSettings(1024, 3, PixelFormat.PF_FLOAT32_R);
var mat = MaterialManager.getSingleton().getByName("PSSM/shadow_caster");
scnMgr.setShadowTextureCasterMaterial(mat);
var pssmSetup = PSSMShadowCameraSetup.create();
scnMgr.setShadowCameraSetup(pssmSetup);
scnMgr.setShadowFarDistance(3000);
scnMgr.setShadowCasterRenderBackFaces(false);
scnMgr.setShadowTextureSelfShadow(true);
}
SHADOWTYPE_TEXTURE_MODULATIVE_INTEGRATED:

SHADOWTYPE_TEXTURE_ADDITIVE:

One more thing, I was searching for something that could help use shared_ptr in SWIG bindings, and I found WeakReference (https://learn.microsoft.com/en-us/dotne ... ew=net-9.0). I don’t know if this could help with memory management between C++ and C#.
[EDIT]
So, my problem is the terrain. When I disable the terrain, I can use any shadow type, but with the terrain on, I get an error.
Code: Select all
public void CreateTerrain()
{
#region CamNode position
pivotNode.setPosition(mTerrainPos + new Vector3(0, 100, 0));
#endregion
#region Terrain Light
Light light = scnMgr.createLight("DirectionalLight");
light.setType(Light.LightTypes.LT_DIRECTIONAL);
light.setDiffuseColour(new ColourValue(1, 1, 1));
light.setSpecularColour(new ColourValue(0.4f, 0.4f, 0.4f));
SceneNode lightNode = scnMgr.getRootSceneNode().createChildSceneNode();
lightNode.setDirection(new Vector3(0.55f, -0.3f, 0.75f).normalisedCopy());
lightNode.attachObject(light);
#endregion
#region Terrain
mTerrainGroup = new TerrainGroup(scnMgr, Terrain.Alignment.ALIGN_X_Z, 1025, 12000);
mTerrainGlobals = new TerrainGlobalOptions();
mTerrainGroup.setOrigin(new Vector3(0, 0, 0));
ConfigureTerrainDefaults(light);
// Define o material padrão antes de carregar o terreno
SetDefaultMaterial();
mTerrainGroup.defineTerrain(0, 0, -1);
mTerrainGroup.loadAllTerrains(true);
mTerrainGroup.freeTemporaryResources();
mainTerrain = mTerrainGroup.getTerrain(0, 0);
MaterialPtr mat = mainTerrain.getMaterial();
shaderGen.createShaderBasedTechnique(mat.getTechnique(0), Variaveis.MSN_SHADERGEN);
RenderState rs = shaderGen.getRenderState(Variaveis.MSN_SHADERGEN, mat.__deref__(), 0);
SubRenderState srs = shaderGen.createSubRenderState(Variaveis.SRS_NORMALMAP);
rs.addTemplateSubRenderState(srs);
srs.setParameter("height_scale", "0.1");
#endregion
}
private void ConfigureTerrainDefaults(Light light)
{
// Configuração global do terreno
mTerrainGlobals.setMaxPixelError(0);
mTerrainGlobals.setCompositeMapDistance(12000);
mTerrainGlobals.setUseRayBoxDistanceCalculation(false);
// Influencia na velocidade do terreno
mTerrainGlobals.setLightMapSize(256);
// Configura iluminação global do terreno
mTerrainGlobals.setLightMapDirection(light.getDerivedDirection());
mTerrainGlobals.setCompositeMapAmbient(scnMgr.getAmbientLight());
mTerrainGlobals.setCompositeMapDiffuse(light.getDiffuseColour());
// Ajuste de altura do skirt do terreno
mTerrainGlobals.setSkirtSize(10);
}
private void SetDefaultMaterial()
{
Terrain.ImportData defaultimp = mTerrainGroup.getDefaultImportSettings();
// Configuração do terreno
defaultimp.worldSize = 12000;
defaultimp.minBatchSize = 33;
defaultimp.maxBatchSize = 65;
// Adicionando camada de textura ao terreno
defaultimp.layerList.Add(new Terrain.LayerInstance());
defaultimp.layerList.Add(new Terrain.LayerInstance());
defaultimp.layerList.Add(new Terrain.LayerInstance());
defaultimp.layerList[0].worldSize = 200;
defaultimp.layerList[0].textureNames.Add("Ground37_diffspec.dds");
defaultimp.layerList[0].textureNames.Add("Ground37_normheight.dds");
defaultimp.layerList[1].worldSize = 200;
defaultimp.layerList[1].textureNames.Add("Ground23_diffspec");
defaultimp.layerList[1].textureNames.Add("Ground23_normheight.dds");
defaultimp.layerList[2].worldSize = 400;
defaultimp.layerList[2].textureNames.Add("Rock20_diffspec.dds");
defaultimp.layerList[2].textureNames.Add("Rock20_normheight.dds");
Image combined = new Image();
combined.loadTwoImagesAsRGBA("Ground23_col.jpg", "Ground23_spec.png", "General");
TextureManager.getSingleton().loadImage("Ground23_diffspec", "General", combined);
}
This is how I initialize the terrain. I'm getting strange errors with the terrain, like this:

Sometimes the terrain just glitches like this, but on other computers, it runs just fine.