Exemple #1
0
        public BTerrainCompositeTexture getCompositeTexture(int width, int height)
        {
            BTerrainCompositeTexture tex = null;

            for (int i = 0; i < cMaxNumLevels; i++)
            {
                if (mCaches[i].mWidth == width && mCaches[i].mHeight == height)
                {
                    return(mCaches[i].getCompositeTexture());
                }
            }
            //we didn't find a free texture, try for a used one

            return(null);
        }
Exemple #2
0
        //CLM USED FOR EXPORT
        public unsafe void convertLayersToTexturingDataHandle(BTerrainLayerContainer input, List <Texture> tempAlphaTextures, BTerrainCompositeTexture output, int minXVert, int minZVert, int lod, int channelCount)
        {
            //  BTerrainLayerContainer input = node.mLayerContainer;
            //  BTerrainCompositeTexture output = node.getTextureData(lod).mCompositeTexture;

            Viewport vp = new Viewport();

            vp.X      = output.mXPixelOffset;
            vp.Y      = output.mYPixelOffset;
            vp.Width  = output.mWidth;
            vp.Height = output.mWidth;
            vp.MinZ   = 0;
            vp.MaxZ   = 1;
            BRenderDevice.getDevice().Viewport = vp;

            Microsoft.DirectX.Direct3D.Effect shader = TerrainGlobals.getTexturing().mCompositeShader;
            shader.Begin(0);
            shader.BeginPass(0);

            for (int i = 0; i < channelCount; i++)
            {
                for (int k = 0; k < output.mNumMips; k++)
                {
                    //actually render
                    Surface compositeTarget = null;
                    float   scale           = 1;

                    try
                    {
                        if (output.UsingAtlas == false)
                        {
                            compositeTarget = output.mTextures[i].GetSurfaceLevel(k);
                            BRenderDevice.getDevice().SetRenderTarget(0, compositeTarget);
                        }
                        else
                        {
                            BTerrainCompositeAtlasTexture atlas = output.mAtlas;

                            if (atlas.mTextures[i].Disposed == true)
                            {
                                atlas.reCreate();
                            }

                            scale           = atlas.mAtlasScale;
                            compositeTarget = atlas.mTextures[i].GetSurfaceLevel(k);
                            BRenderDevice.getDevice().SetRenderTarget(0, compositeTarget);
                        }


                        {
                            BTerrainTexturingLayer.eLayerType lastType = BTerrainTexturingLayer.eLayerType.cLayer_Splat;

                            float layerInc = 1.0f / (float)(cMaxNumBlends - 1);// (float)input.getNumLayers();
                            for (int j = 0; j < input.getNumLayers(); j++)
                            {
                                //    BRenderDevice.getDevice().Clear(ClearFlags.ZBuffer | ClearFlags.Target, unchecked((int)0xFFFF0000), 1.0f, 0);

                                //compose a splat
                                shader.SetValue(mShaderContribOverride, 1);
                                shader.SetValue(mShaderAlphaOverride, 1);
                                if (input.giveLayer(j).mLayerType == BTerrainTexturingLayer.eLayerType.cLayer_Splat)
                                {
                                    if (lastType != BTerrainTexturingLayer.eLayerType.cLayer_Splat)
                                    {
                                        shader.EndPass();
                                        shader.BeginPass(0);
                                        lastType = BTerrainTexturingLayer.eLayerType.cLayer_Splat;
                                    }

                                    if (TerrainGlobals.getEditor().getRenderMode() == BTerrainEditor.eEditorRenderMode.cRenderTextureSelectRender)
                                    {
                                        if (TerrainGlobals.getEditor().getMode() != BTerrainEditor.eEditorMode.cModeTexEdit)
                                        {
                                            if (j == 0)
                                            {
                                                shader.SetValue(mShaderContribOverride, 0);
                                                shader.SetValue(mShaderAlphaOverride, 0);
                                            }
                                            else
                                            {
                                                continue;
                                            }
                                        }
                                        else
                                        {
                                            if (input.giveLayer(j).mActiveTextureIndex != TerrainGlobals.getTerrainFrontEnd().SelectedTextureIndex)
                                            {
                                                shader.SetValue(mShaderContribOverride, 0);
                                            }
                                            else
                                            {
                                                shader.SetValue(mShaderContribOverride, 1);
                                            }
                                            shader.SetValue(mShaderAlphaOverride, 0);
                                        }
                                    }


                                    float targetLayer = (float)(j * layerInc);
                                    shader.SetValue(mShaderNumLayersHandle, targetLayer);
                                    shader.SetValue(mShaderAlphaTexArrayHandle, tempAlphaTextures[j]);


                                    //lock in our target texture
                                    BTerrainActiveTextureContainer active = TerrainGlobals.getTexturing().getActiveTexture(input.giveLayer(j).mActiveTextureIndex);
                                    if (active == null)
                                    {
                                        compositeTarget.Dispose();
                                        continue;
                                    }

                                    shader.SetValue(mShaderTexArrayHandle, active.mTexChannels[i].mTexture);
                                    float[] uvs = new float[2];
                                    uvs[0] = active.mUScale;
                                    uvs[1] = active.mVScale;

                                    shader.SetValue(mShaderLayerUV, uvs);
                                }
                                else //compose a decal
                                {
                                    if (lastType != BTerrainTexturingLayer.eLayerType.cLayer_Decal)
                                    {
                                        shader.EndPass();
                                        shader.BeginPass(1);
                                        lastType = BTerrainTexturingLayer.eLayerType.cLayer_Decal;
                                    }

                                    bool doWhite = false;
                                    if (TerrainGlobals.getEditor().getRenderMode() == BTerrainEditor.eEditorRenderMode.cRenderTextureSelectRender)
                                    {
                                        if (TerrainGlobals.getEditor().getMode() == BTerrainEditor.eEditorMode.cModeTexEdit)
                                        {
                                            shader.SetValue(mShaderContribOverride, 0);
                                        }
                                        else if (TerrainGlobals.getEditor().getMode() == BTerrainEditor.eEditorMode.cModeDecalEdit)
                                        {
                                            doWhite = true;
                                            if (TerrainGlobals.getTexturing().getActiveDecalInstance(input.giveLayer(j).mActiveTextureIndex).mActiveDecalIndex != TerrainGlobals.getTerrainFrontEnd().SelectedDecalIndex)
                                            {
                                                shader.SetValue(mShaderContribOverride, 0);
                                            }
                                            else
                                            {
                                                shader.SetValue(mShaderContribOverride, 1);
                                                shader.SetValue(mShaderAlphaOverride, 1);
                                            }
                                        }
                                    }

                                    //Grab our decal instance
                                    BTerrainDecalInstance decal = getActiveDecalInstance(input.giveLayer(j).mActiveTextureIndex);
                                    if (decal == null)
                                    {
                                        compositeTarget.Dispose();
                                        continue;
                                    }
                                    Vector4 selColor = new Vector4(1, 1, 1, 1);
                                    if (decal.mIsSelected)
                                    {
                                        selColor.Y = 0.75f;
                                        selColor.Z = 0.75f;
                                    }
                                    shader.SetValue(mShaderColorOverload, selColor);



                                    //grab the decal we care about
                                    BTerrainActiveDecalContainer active = getActiveDecal(decal.mActiveDecalIndex);
                                    if (active == null)
                                    {
                                        compositeTarget.Dispose();
                                        continue;
                                    }
                                    if (doWhite)
                                    {
                                        shader.SetValue(mShaderAlphaTexArrayHandle, tempAlphaTextures[0]);
                                    }
                                    else
                                    {
                                        shader.SetValue(mShaderAlphaTexArrayHandle, tempAlphaTextures[j]);
                                    }
                                    shader.SetValue(mShaderAlphaTexDecalHandle, active.mTexChannels[(int)BTerrainTexturing.eTextureChannels.cOpacity].mTexture);
                                    shader.SetValue(mShaderTexDecalHandle, active.mTexChannels[i].mTexture);

                                    float[] decalDat = new float[4];
                                    decalDat[0] = decal.mRotation;


                                    //compute our U and V offset
                                    float vertsToHighResPixelSpaceRatio = BTerrainTexturing.getTextureWidth() / BTerrainQuadNode.cMaxWidth;
                                    decalDat[1] = (decal.mTileCenter.X - (minXVert * vertsToHighResPixelSpaceRatio)) / BTerrainTexturing.getTextureWidth();
                                    decalDat[2] = (decal.mTileCenter.Y - (minZVert * vertsToHighResPixelSpaceRatio)) / BTerrainTexturing.getTextureHeight();

                                    decalDat[3] = 0;

                                    shader.SetValue(mShaderLayerDecalData, decalDat);

                                    float[] uvs = new float[2];
                                    uvs[0] = decal.mUScale;
                                    uvs[1] = decal.mVScale;
                                    shader.SetValue(mShaderLayerUV, uvs);
                                }

                                shader.CommitChanges();
                                BRenderDevice.getDevice().Viewport = vp;
                                BRenderDevice.getDevice().DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, 4, 0, 2);
                            }

                            shader.EndPass();
                            shader.BeginPass(0);
                        }
                    }
                    catch (Direct3DXException e)
                    {
                        CoreGlobals.getErrorManager().SendToErrorWarningViewer("An error has occured during the compositing process");
                    }
                    finally
                    {
                        if (compositeTarget != null)
                        {
                            compositeTarget.Dispose();
                        }
                    }
                }
            }
            shader.EndPass();
            shader.End();
        }
Exemple #3
0
        //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;
        }