static public bool isChunkUsed(BTerrainQuadNode node) { for (int i = 0; i < mQNChunks.Count; i++) { if (mQNChunks[i].mOwnerNodeDesc.mMinXVert == node.getDesc().mMinXVert&& mQNChunks[i].mOwnerNodeDesc.mMinZVert == node.getDesc().mMinZVert) { return(true); } } return(false); }
void renderLeafNode(BTerrainQuadNode node) { int lod = (int)BTerrainVisual.eLODLevel.cLOD0; BTerrainQuadNodeDesc desc = node.getDesc(); float scale = TerrainGlobals.getTerrain().getTileScale() * ((int)Math.Pow(2, lod)); Vector4 DataVals = new Vector4(2 * (BTerrainQuadNode.getMaxNodeWidth() >> lod), scale, desc.mMinXVert, desc.mMinZVert); mTerrainGPUShader.mShader.SetValue(mShaderDataValsHandle, DataVals); mTerrainGPUShader.mShader.CommitChanges(); BRenderDevice.getDevice().DrawPrimitives(PrimitiveType.TriangleList, 0, (int)mNumPrims); }
//CLM USED FOR GAME public unsafe void convertLayersToTexturingDataHandle(BTerrainLayerContainer input, BTerrainCompositeTexture output, BTerrainQuadNode node, int lod) { //lock in our alpha texture BTerrainQuadNodeDesc desc = node.getDesc(); int numlayers = input.getNumLayers(); BTerrainLayerContainer tContainer = TerrainGlobals.getEditor().generateContainerFromTexDeformations(desc.mMinXVert, desc.mMinZVert); if (tContainer == null) { tContainer = input; } tContainer.toTextureArray(ref mTempAlphaTextures, desc.mMinXVert, desc.mMinZVert); convertLayersToTexturingDataHandle(tContainer, mTempAlphaTextures, output, desc.mMinXVert, desc.mMinZVert, lod, (int)BTerrainTexturing.eTextureChannels.cSplatChannelCount); tContainer = null; }
//------------------------------------------ //called to apply a texutre directly to a masked area public unsafe bool applyToMask(BTerrainQuadNode node) { bool changed = false; BTerrainQuadNodeDesc desc = node.getDesc(); changed = Texturing_LayerEditor.setIndexToMaskedArea(node, desc.mMinXVert, desc.mMinZVert, desc.mMaxXVert, desc.mMaxZVert, (char)mTexArrayIndex); if (changed) { //node.getTextureData().free(); for (int i = 0; i < Terrain.BTerrainTexturing.cMaxNumLevels; i++) { node.getTextureData(i).free(); } } return(changed); }
//---------------------------------------------- unsafe static public bool setMaskAlphaToTextureBlending(BTerrainQuadNode node, uint dstImgWidth, uint dstImgHeight, UInt32 *mskImg, uint mskImgWidth, uint mskImgHeight, float intensity, int xpos, int ypos, bool alternate) { BTerrainQuadNodeDesc desc = node.getDesc(); bool changed = false; //create our position in the dst img, adjust for boundries int mskMaxX = (int)mskImgWidth; if (mskImgWidth + xpos >= dstImgWidth) { mskMaxX -= ((int)mskImgWidth) + xpos - ((int)dstImgWidth); } int mskMaxY = (int)mskImgHeight; if (mskImgHeight + ypos >= dstImgHeight) { mskMaxY -= ((int)mskImgHeight) + ypos - ((int)dstImgHeight); } int mskMinX = 0; int mskMinY = 0; if (xpos < 0) { mskMinX = -xpos; } if (ypos < 0) { mskMinY = -ypos; } //validate extents... if (mskMinX > mskImgWidth || mskMinY > mskImgHeight) { return(false); } int minX = (int)(desc.m_min.X / TerrainGlobals.getTerrain().getTileScale()); int maxX = (int)(desc.m_max.X / TerrainGlobals.getTerrain().getTileScale()); int minZ = (int)(desc.m_min.Z / TerrainGlobals.getTerrain().getTileScale()); int maxZ = (int)(desc.m_max.Z / TerrainGlobals.getTerrain().getTileScale()); for (int x = minX; x <= maxX; x++) { for (int z = minZ; z <= maxZ; z++) { int maskX = x - minX + mskMinX; int maskY = z - minZ + mskMinY; int mIP = maskX * ((int)mskImgWidth) + maskY; char alpha = (char)(((mskImg[mIP] & 0xFF000000) >> 24)); float factor = alpha / 255.0f * intensity;; int vertIndex = (int)(x * TerrainGlobals.getTerrain().getNumZVerts() + z); float curWeight = Masking.getCurrSelectionMaskWeights().GetMaskWeight(vertIndex); float newWeight; if (!alternate) { newWeight = (curWeight > factor) ? curWeight : factor; } else//CLM Changes to erasing.. { newWeight = BMathLib.Clamp(curWeight - factor, 0, 1); } Masking.addSelectedVert(x, z, newWeight); changed = true; } } return(changed); }
unsafe static public bool setMaskAlphaToLayer(BTerrainQuadNode node, UInt32 *mskImg, uint mskImgWidth, uint mskImgHeight, float alphaScalar, int terrainGridX, int terrainGridZ, char index) { bool changed = false; uint dstImgWidth = BTerrainTexturing.getAlphaTextureWidth(); uint dstImgHeight = BTerrainTexturing.getAlphaTextureWidth(); float vertsToPixelsRatio = BTerrainTexturing.getAlphaTextureWidth() / (float)BTerrainQuadNode.getMaxNodeWidth(); int minxvert = node.getDesc().mMinXVert; int minzvert = node.getDesc().mMinZVert; int maxxvert = node.getDesc().mMaxXVert; int maxzvert = node.getDesc().mMaxZVert; BTerrainLayerContainer layers = node.mLayerContainer; int layerIndex = layers.giveLayerIndex(index, BTerrainTexturingLayer.eLayerType.cLayer_Splat); if (TerrainGlobals.getEditor().mEraseTextureInstead&& layerIndex == 0) { return(false); } // layers.removeRedundantLayers();//CLM is this still needed?!??! if (layerIndex == -1) { if (TerrainGlobals.getEditor().mEraseTextureInstead) //we're erasing, and the texture doesn't exist.. { return(false); } //i don't exist yet. newSplatLayerEverywhere(index); layerIndex = layers.giveLayerIndex(index, BTerrainTexturingLayer.eLayerType.cLayer_Splat); BTerrainTexturingLayer tLayer = layers.giveLayer(layerIndex); for (int x = 0; x < BTerrainTexturing.getAlphaTextureWidth(); x++) { for (int z = 0; z < BTerrainTexturing.getAlphaTextureWidth(); z++) { float curWeight = TerrainGlobals.getTerrain().getSoftSelectionWeight(terrainGridX, terrainGridZ); if (!BMathLib.compare(curWeight, 0.0f)) { int cX = (int)((x * vertsToPixelsRatio) + minxvert); int cZ = (int)((z * vertsToPixelsRatio) + minzvert); curWeight = BMathLib.Clamp(curWeight, 0, 1); int dIP = x + ((int)BTerrainTexturing.getAlphaTextureHeight()) * z; byte alphaMapVal = giveBrushAlphaValue(mskImg, mskImgWidth, mskImgHeight, minxvert, minzvert, maxxvert, maxzvert, cX, cZ, terrainGridX, terrainGridZ); byte val = (byte)(alphaMapVal * alphaScalar * curWeight); tLayer.mAlphaLayer[dIP] = val; } } } changed = true; } else { BTerrainTexturingLayer tLayer = layers.giveLayer(layerIndex); //this layer already exists. //If a pixel exists above me, subtract me from it, rather than adding to me. for (int x = 0; x < BTerrainTexturing.getAlphaTextureWidth(); x++) { for (int z = 0; z < BTerrainTexturing.getAlphaTextureWidth(); z++) { //find the closest vert int cX = (int)((x * vertsToPixelsRatio) + minxvert); int cZ = (int)((z * vertsToPixelsRatio) + minzvert); int dIP = x + ((int)BTerrainTexturing.getAlphaTextureHeight()) * z; float curWeight = TerrainGlobals.getTerrain().getSoftSelectionWeight(terrainGridX, terrainGridZ); if (!BMathLib.compare(curWeight, 0.0f)) { changed = true; curWeight = BMathLib.Clamp(curWeight, 0, 1); byte alphaMapVal = giveBrushAlphaValue(mskImg, mskImgWidth, mskImgHeight, minxvert, minzvert, maxxvert, maxzvert, cX, cZ, terrainGridX, terrainGridZ); byte val = (byte)(alphaMapVal * alphaScalar * curWeight); valToLayerColumn(layers, tLayer, dIP, val, layerIndex); } } } } layers.removeBlankLayers(); return(changed); }