Exemplo n.º 1
0
        public override void render()
        {
            BRenderDevice.getDevice().SetRenderState(RenderStates.AlphaBlendEnable, true);
            BRenderDevice.getDevice().SetRenderState(RenderStates.SourceBlend, (int)Microsoft.DirectX.Direct3D.Blend.SourceAlpha);
            BRenderDevice.getDevice().SetRenderState(RenderStates.DestinationBlend, (int)Microsoft.DirectX.Direct3D.Blend.InvSourceAlpha);

            Texture            mask = TerrainGlobals.getTerrainFrontEnd().getSelectedMaskTexture();
            SurfaceDescription sd   = mask.GetLevelDescription(0);

            float validRadius             = sd.Width / 2;
            List <BTerrainQuadNode> nodes = new List <BTerrainQuadNode>();
            int closestX = 0;
            int closestZ = 0;

            {
                // in this node, find the CLOSEST vertex to this actual position.
                BTerrainEditor.findClosestVertex(ref closestX, ref closestZ, ref TerrainGlobals.getEditor().mBrushIntersectionPoint, TerrainGlobals.getEditor().mBrushIntersectionNode);

                TerrainGlobals.getTerrain().getQuadNodeRoot().getTileBoundsIntersection(nodes, (int)(closestX - validRadius),
                                                                                        (int)(closestX + validRadius),
                                                                                        (int)(closestZ - validRadius),
                                                                                        (int)(closestZ + validRadius));
            }
            for (int i = 0; i < nodes.Count; i++)
            {
                nodes[i].renderCursor();
            }


            BRenderDevice.getDevice().SetRenderState(RenderStates.AlphaBlendEnable, false);
        }
Exemplo n.º 2
0
 private void PropertiesWindow_Load(object sender, EventArgs e)
 {
     Stroke = TerrainGlobals.getTerrainFrontEnd().GetMainBrushStroke();
 }
Exemplo n.º 3
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();
        }
Exemplo n.º 4
0
 //----------------------------
 public int getLODLevel(Vector3 center)
 {
     return((int)mLODData.getLODLevel(center, TerrainGlobals.getTerrainFrontEnd().mCameraManager.mEye));
 }
Exemplo n.º 5
0
        unsafe public int newVisualHandle(float minX, float minZ, float maxX, float maxZ, Vector3 center, Vector3 BBmin, Vector3 BBmax)
        {
            int lod = (int)mLODData.getLODLevel(center, TerrainGlobals.getTerrainFrontEnd().mCameraManager.mEye);

            return(newVisualHandle(minX, minZ, maxX, maxZ, center, BBmin, BBmax, lod));
        }
Exemplo n.º 6
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);
                    }
                }
            }
        }
Exemplo n.º 7
0
        public override bool applyToDstImg(BTerrainQuadNode node, int x, int z, bool selectionMode, bool alternate)
        {
            BTerrainLayerContainer       layers = node.mLayerContainer;
            BTerrainActiveDecalContainer decal  = TerrainGlobals.getTexturing().getActiveDecal(TerrainGlobals.getTerrainFrontEnd().SelectedDecalIndex);

            bool changed = false;



            return(changed);
        }
Exemplo n.º 8
0
        public bool init(int decalIndex)
        {
            mDecalArrayIndex = decalIndex;

            BTerrainActiveDecalContainer decal = TerrainGlobals.getTexturing().getActiveDecal(TerrainGlobals.getTerrainFrontEnd().SelectedDecalIndex);
            SurfaceDescription           sd    = decal.mTexChannels[0].mTexture.GetLevelDescription(0);

            mDecalRadius = sd.Width / 2;
            mDecalWidth  = sd.Width;
            mDecalHeight = sd.Height;
            return(true);
        }