Пример #1
0
        public int addActiveTexture(String filename)
        {
            for (int i = 0; i < mActiveTextures.Count; i++)
            {
                if (mActiveTextures[i].mFilename == filename)
                {
                    return(i);
                }
            }

            BTerrainActiveTextureContainer atc = new BTerrainActiveTextureContainer();

            atc.mFilename = filename;
            atc.loadTextures();
            mActiveTextures.Add(atc);

            BRenderDevice.getTextureManager().addWatchedTexture(filename, activeTextureReloaded);
            return(mActiveTextures.Count - 1);
        }
Пример #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();
        }
Пример #3
0
        public static void MaskCurrentTexture(bool bUseTextureFade)
        {
            int totalNumVerts = TerrainGlobals.getTerrain().getNumXVerts();
            int i             = -1;

            int selTexIndex = TerrainGlobals.getTerrainFrontEnd().SelectedTextureIndex;

            BTerrainActiveTextureContainer activeTex = TerrainGlobals.getTexturing().getActiveTexture(TerrainGlobals.getTerrainFrontEnd().SelectedTextureIndex);

            if (activeTex.mMatHasMask == false)
            {
                return;
            }

            Image img = Image.FromFile(activeTex.getMaskFileName());

            if (img == null)
            {
                return;
            }
            IMask m = CreateMask(img);

            if (m == null)
            {
                return;
            }
            img.Dispose();

            for (int x = 0; x < totalNumVerts; x++)
            {
                for (int z = 0; z < totalNumVerts; z++)
                {
                    float baseValue;
                    float factor = 0;
                    if (checkBaseWritePermission(x, z, out baseValue) == false)
                    {
                        continue;
                    }
                    BTerrainTextureVector vec = TerrainGlobals.getEditor().giveTextureDataAtVertex(x, z);

                    if (vec.containsID(selTexIndex, BTerrainTexturingLayer.eLayerType.cLayer_Splat))
                    {
                        int splatindex = vec.giveLayerIndex(selTexIndex, BTerrainTexturingLayer.eLayerType.cLayer_Splat);

                        float layeralpha = vec.mLayers[splatindex].mAlphaContrib / 255f;
                        float maskAlpha  = 0;
                        if (layeralpha == 0)
                        {
                            continue;
                        }


                        maskAlpha = m.GetMaskWeight(((z % 64) * 64) + (x % 64));
                        //layeralpha = m.GetMaskWeight((( x) * totalNumVerts) + ( z));
                        if (bUseTextureFade)
                        {
                            maskAlpha = maskAlpha * layeralpha;
                        }
                        if (maskAlpha == 0)
                        {
                            continue;
                        }

                        i++;

                        addSelectedVert(x, z, maskAlpha);
                    }
                }
            }
        }