Exemplo n.º 1
0
        private void setupModMenu()
        {
            MaterialPtr thumbMat = MaterialManager.Singleton.Create("ModThumbnail", "General");

            thumbMat.GetTechnique(0).GetPass(0).CreateTextureUnitState();
            MaterialPtr templateMat = MaterialManager.Singleton.GetByName("ModThumbnail");

            foreach (string itr in modThumb)
            {
                string name = "ModThumb" + (modThumbs.Count + 1).ToString();

                MaterialPtr newMat = templateMat.Clone(name);

                TextureUnitState tus = newMat.GetTechnique(0).GetPass(0).GetTextureUnitState(0);
                if (ResourceGroupManager.Singleton.ResourceExists("General", itr))
                {
                    tus.SetTextureName(itr);
                }
                else
                {
                    tus.SetTextureName("thumb_error.png");
                }

                BorderPanelOverlayElement bp = (BorderPanelOverlayElement)
                                               OverlayManager.Singleton.CreateOverlayElementFromTemplate("SdkTrays/Picture", "BorderPanel", (name));


                bp.HorizontalAlignment = (GuiHorizontalAlignment.GHA_RIGHT);
                bp.VerticalAlignment   = (GuiVerticalAlignment.GVA_CENTER);
                bp.MaterialName        = (name);
                GameManager.Instance.trayMgr.getTraysLayer().Add2D(bp);

                modThumbs.Add(bp);
            }
        }
        protected override void CreateScene()
        {
            mSceneMgr.AmbientLight = new ColourValue(1, 1, 1);
            //Entity ent = mSceneMgr.CreateEntity("Head", "ogrehead.mesh");
            //SceneNode node = mSceneMgr.RootSceneNode.CreateChildSceneNode("HeadNode");
            //node.AttachObject(ent);
            MaterialPtr      mat  = MaterialManager.Singleton.Create("BoxColor", "General", true);
            Technique        tech = mat.GetTechnique(0);
            Pass             pass = tech.GetPass(0);
            TextureUnitState tex  = pass.CreateTextureUnitState();

            tex.SetTextureName("sphax.jpg", TextureType.TEX_TYPE_2D);
            tex.NumMipmaps        = 0;
            tex.TextureAnisotropy = 0;
            tex.SetTextureFiltering(FilterOptions.FO_POINT, FilterOptions.FO_POINT, FilterOptions.FO_POINT);
            //pass.DepthWriteEnabled=false;
            //pass.SetSceneBlending(SceneBlendType.SBT_TRANSPARENT_ALPHA);
            //pass.CullingMode = CullingMode.CULL_NONE;
            //mCamMan = new Tutorials.CameraMan(mCamera,mc);
            //mCameraMan = null;
            mCamera.SetPosition((float)mc.x, (float)mc.y, (float)mc.z);
            mCamera.Pitch(new Degree(mc.pitch).ValueRadians);
            mCamera.Yaw(new Degree(mc.yaw).ValueRadians);
            oldCamPos = mCamera.Position;
        }
Exemplo n.º 3
0
        /// <summary>
        ///
        /// </summary>
        protected void UpdateMaterials()
        {
            for (int o = 0; o < ImpostorYawAngles; o++)
            {
                for (int i = 0; i < ImpostorPitchAngles; i++)
                {
                    Material         m = mMaterial[i, o];
                    Pass             p = m.GetTechnique(0).GetPass(0);
                    TextureUnitState t = p.GetTextureUnitState(0);

                    t.SetTextureName(mTexture.Name);
                }
            }
        }
Exemplo n.º 4
0
        private void SetupFontMaterial()
        {
            Technique        technique    = fontMaterial.CreateTechnique();
            Pass             pass         = technique.CreatePass();
            TextureUnitState texUnitState = pass.CreateTextureUnitState();

            texUnitState.SetTextureName(font.TextureName);
            // texUnitState.SetAlphaOperation(LayerBlendOperation.AlphaBlend);
            // texUnitState.SetTextureFiltering(FilterOptions.Linear);
            texUnitState.TextureAddressing = TextureAddressing.Clamp;
            texUnitState.TextureMatrix     = Matrix4.Identity;
            texUnitState.TextureCoordSet   = 0;

//			renderSystem.SetTextureCoordCalculation( 0, TexCoordCalcMethod.None );
//			renderSystem.SetTextureUnitFiltering(0, FilterOptions.Linear, FilterOptions.Linear, FilterOptions.Point);
//			renderSystem.SetAlphaRejectSettings(0, CompareFunction.AlwaysPass, 0);
//			renderSystem.SetTextureBlendMode( 0, unitState.ColorBlendMode );
//			renderSystem.SetTextureBlendMode( 0, unitState.AlphaBlendMode );
//
//			// enable alpha blending
//			renderSystem.SetSceneBlending(SceneBlendFactor.SourceAlpha, SceneBlendFactor.OneMinusSourceAlpha);
        }
Exemplo n.º 5
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="menu"></param>
        public virtual void ItemSelected(SelectMenu menu)
        {
            if (menu == this.CategoryMenu)                  // category changed, so update the sample menu, carousel, and slider
            {
                for (int i = 0; i < this.Thumbs.Count; i++) // destroy all thumbnails in carousel
                {
                    MaterialManager.Instance.Remove(this.Thumbs[i].Name);
                    Widget.NukeOverlayElement(this.Thumbs[i]);
                }
                this.Thumbs.Clear();

                OverlayManager om = OverlayManager.Instance;
                String         selectedCategory = string.Empty;

                if (menu.SelectionIndex != -1)
                {
                    selectedCategory = menu.SelectedItem;
                }
                else
                {
                    this.TitleLabel.Caption = "";
                    this.DescBox.Text       = "";
                }

                bool all          = selectedCategory == "All";
                var  sampleTitles = new List <string>();
                var  templateMat  = (Material)MaterialManager.Instance.GetByName("SampleThumbnail");

                // populate the sample menu and carousel with filtered samples
                foreach (Sample i in this.LoadedSamples)
                {
                    Collections.NameValuePairList info = i.Metadata;

                    if (all || info["Category"] == selectedCategory)
                    {
                        String name = "SampleThumb" + sampleTitles.Count + 1;

                        // clone a new material for sample thumbnail
                        Material newMat = templateMat.Clone(name);

                        TextureUnitState tus = newMat.GetTechnique(0).GetPass(0).GetTextureUnitState(0);
                        if (ResourceGroupManager.Instance.ResourceExists("Essential", info["Thumbnail"]))
                        {
                            tus.SetTextureName(info["Thumbnail"]);
                        }
                        else
                        {
                            tus.SetTextureName("thumb_error.png");
                        }

                        // create sample thumbnail overlay
                        var bp =
                            (Overlays.Elements.BorderPanel)om.Elements.CreateElementFromTemplate("SdkTrays/Picture", "BorderPanel", name);
                        bp.HorizontalAlignment = HorizontalAlignment.Right;
                        bp.VerticalAlignment   = VerticalAlignment.Center;
                        bp.MaterialName        = name;
                        bp.UserData            = i;
                        this.TrayManager.TraysLayer.AddElement(bp);

                        // add sample thumbnail and title
                        this.Thumbs.Add(bp);
                        sampleTitles.Add(i.Metadata["Title"]);
                    }
                }

                this.CarouselPlace = 0; // reset carousel

                this.SampleMenu.Items = sampleTitles;
                if (this.SampleMenu.ItemsCount != 0)
                {
                    ItemSelected(this.SampleMenu);
                }

                this.SampleSlider.SetRange(1, sampleTitles.Count, sampleTitles.Count);
            }
            else if (menu == this.SampleMenu) // sample changed, so update slider, label and description
            {
                if (this.SampleSlider.Value != menu.SelectionIndex + 1)
                {
                    this.SampleSlider.Value = menu.SelectionIndex + 1;
                }

                var s = (Sample)(this.Thumbs[menu.SelectionIndex].UserData);
                this.TitleLabel.Caption = menu.SelectedItem;
                this.DescBox.Text       = "Category: " + s.Metadata["Category"] + "\nDescription: " + s.Metadata["Description"];

                if (CurrentSample != s)
                {
                    ((Button)this.TrayManager.GetWidget("StartStop")).Caption = "Start Sample";
                }
                else
                {
                    ((Button)this.TrayManager.GetWidget("StartStop")).Caption = "Stop Sample";
                }
            }
            else if (menu == this.RendererMenu) // renderer selected, so update all settings
            {
                while (this.TrayManager.GetWidgetCount(this.RendererMenu.TrayLocation) > 3)
                {
                    this.TrayManager.DestroyWidget(this.RendererMenu.TrayLocation, 3);
                }

                var options = Root.RenderSystems[menu.SelectionIndex].ConfigOptions;

                int i = 0;

                // create all the config option select menus
                foreach (Configuration.ConfigOption it in options)
                {
                    SelectMenu optionMenu = this.TrayManager.CreateLongSelectMenu(TrayLocation.Left, "ConfigOption" + i++, it.Name,
                                                                                  450,
                                                                                  240, 10);
                    optionMenu.Items = (List <string>)it.PossibleValues.Values.ToList();

                    // if the current config value is not in the menu, add it
                    try
                    {
                        optionMenu.SelectItem(it.Value);
                    }
                    catch (Exception)
                    {
                        optionMenu.AddItem(it.Value);
                        optionMenu.SelectItem(it.Value);
                    }
                }

                WindowResized(RenderWindow);
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// Buduje quada o wymaganych parametrach. Quad bedzie mogl byc wyswietlony w przestrzeni 3D. Ma nakladn¹ teksture wg textureName
        /// </summary>
        /// <param name="quadrangle"></param>
        /// <param name="origin"></param>
        /// <param name="textureName"></param>
        public void SetCorners3D(Quadrangle quadrangle, Vector3 origin, String textureName)
        {
            this.quadrangle = quadrangle;
            Vector2 leftBottom  = quadrangle.Peaks[0].ToVector2();
            Vector2 leftTop     = quadrangle.Peaks[1].ToVector2();
            Vector2 rightTop    = quadrangle.Peaks[2].ToVector2();
            Vector2 rightBottom = quadrangle.Peaks[3].ToVector2();

            float extend = 1.25f;


            corners       = new float[4][];
            corners[0]    = new float[3];
            corners[0][0] = extend * rightBottom.x + origin.x;
            corners[0][1] = extend * rightBottom.y + origin.y;
            corners[0][2] = origin.z;


            corners[1]    = new float[3];
            corners[1][0] = extend * rightTop.x + origin.x;
            corners[1][1] = extend * rightTop.y + origin.y;
            corners[1][2] = origin.z;


            corners[2]    = new float[3];
            corners[2][0] = extend * leftTop.x + origin.x;
            corners[2][1] = extend * leftTop.y + origin.y;
            corners[2][2] = origin.z;


            corners[3]    = new float[3];
            corners[3][0] = extend * leftBottom.x + origin.x;
            corners[3][1] = extend * leftBottom.y + origin.y;
            corners[3][2] = origin.z;


            float textureTop    = 0;
            float textureLeft   = 0;
            float textureBottom = 1;
            float textureRight  = 1;

            //      manualObject.RenderQueueGroup = (byte)RenderQueueGroupID.RENDER_QUEUE_MAIN - 1;

            manualObject.Clear();
            manualObject.Begin("Misc/BoundingQuadrangle", RenderOperation.OperationTypes.OT_TRIANGLE_LIST);
            manualObject.Position(origin.x + leftBottom.x, origin.y + leftBottom.y, origin.z);
            manualObject.TextureCoord(textureLeft, textureBottom);
            manualObject.Position(origin.x + leftTop.x, origin.y + leftTop.y, origin.z);
            manualObject.TextureCoord(textureLeft, textureTop);
            manualObject.Position(origin.x + rightTop.x, origin.y + rightTop.y, origin.z);
            manualObject.TextureCoord(textureRight, textureTop);
            manualObject.Position(origin.x + rightBottom.x, origin.y + rightBottom.y, origin.z);
            manualObject.TextureCoord(textureRight, textureBottom);

            /*    manualObject.Position( origin.x + leftBottom.x, origin.y + leftBottom.y,  origin.z);
             *  manualObject.TextureCoord(0, 0);*/
            manualObject.Quad(3, 2, 1, 0);
            manualObject.End();


/*
 *          AxisAlignedBox box = new AxisAlignedBox();
 *          float hwidth = 1.4f * (quadrangle.RightMostX - quadrangle.LeftMostX) * 0.5f;
 *          float hheight = 1.4f * (quadrangle.HighestY - quadrangle.LowestY) * 0.5f;
 *          box.SetMinimum(origin.x - hwidth, origin.y - hheight, origin.z - 10);
 *          box.SetMaximum(origin.x + hwidth, origin.y + hheight, origin.z + 10);
 *
 *          manualObject.BoundingBox = box;
 */
            MaterialPtr mat  = ViewHelper.CloneMaterial("AdMaterial", manualObject.Name + "AdMaterial");
            Pass        pass = mat.GetBestTechnique().GetPass(0);

            pass.DepthWriteEnabled = true;
            pass.SetSceneBlending(SceneBlendType.SBT_TRANSPARENT_ALPHA);

            TextureUnitState state = pass.GetTextureUnitState(0);

            state.SetTextureName(textureName);

            manualObject.SetMaterialName(0, mat.Name);
            manualObject.CastShadows = false;
            OnSetCorners();
            //  manualObject.SetMaterialName(0, "Concrete");
        }
Exemplo n.º 7
0
        void CreateDefaultTechnique( out bool notSupported )
        {
            notSupported = false;

            string sourceFile = "Materials\\Common\\Water.cg_hlsl";

            string vertexSyntax;
            string fragmentSyntax;
            {
                if( RenderSystem.Instance.IsDirect3D() )
                {
                    if( RenderSystem.Instance.HasShaderModel3() )
                    {
                        vertexSyntax = "vs_3_0";
                        fragmentSyntax = "ps_3_0";
                    }
                    else
                    {
                        vertexSyntax = "vs_2_0";
                        fragmentSyntax = "ps_2_0";
                    }
                }
                else
                {
                    vertexSyntax = "arbvp1";
                    fragmentSyntax = "arbfp1";
                }
            }

            if( !RenderSystem.Instance.HasShaderModel2() ||
                !RenderSystem.Instance.Capabilities.UserClipPlanes )
            {
                notSupported = true;
                return;
            }

            BaseMaterial.ReceiveShadows = false;

            Technique tecnhique = BaseMaterial.CreateTechnique();
            Pass pass = tecnhique.CreatePass();

            //generate compileArguments and bind textures
            StringBuilder compileArguments = new StringBuilder( 128 );

            //transparent surface
            if( owner.DeepColor.Alpha != 1 || owner.ShallowColor.Alpha != 1 )
            {
                pass.SourceBlendFactor = SceneBlendFactor.SourceAlpha;
                pass.DestBlendFactor = SceneBlendFactor.OneMinusSourceAlpha;
                pass.DepthWrite = false;

                compileArguments.Append( " -DTRANSPARENT" );
            }

            //disable Direct3D standard fog features
            pass.SetFogOverride( FogMode.None, new ColorValue( 0, 0, 0 ), 0, 0, 0 );

            //bool direct3d = RenderSystem.Instance.Name.Contains( "Direct3D" );
            //compileArguments.Append( direct3d ? " -DDIRECT3D" : " -DOPENGL" );

            //Fog
            FogMode fogMode = SceneManager.Instance.GetFogMode();
            if( fogMode != FogMode.None )
            {
                compileArguments.Append( " -DFOG_ENABLED" );
                compileArguments.Append( " -DFOG_" + fogMode.ToString().ToUpper() );
            }

            //noiseMap
            {
                TextureUnitState state = pass.CreateTextureUnitState();
                state.SetTextureName( "Types\\Special\\WaterPlane\\WaterNoise.dds", Texture.Type.Type2D );
            }

            //reflectionMap
            if( owner.ReflectionLevel != WaterPlane.ReflectionLevels.None )
            {
                compileArguments.Append( " -DREFLECTION_MAP" );

                reflectionMapState = pass.CreateTextureUnitState();
                if( owner.ReflectionTexture != null )
                    reflectionMapState.SetTextureName( owner.ReflectionTexture.Name );
                reflectionMapState.SetTextureAddressingMode( TextureAddressingMode.Clamp );
                reflectionMapState.SetTextureFiltering( FilterOptions.Linear,
                    FilterOptions.Linear, FilterOptions.None );
            }

            //vertex program
            {
                string errorString;

                GpuProgram program = GpuProgramCacheManager.Instance.AddProgram(
                    "WaterPlane_Vertex_", GpuProgramType.VertexProgram, sourceFile,
                    "main_vp", vertexSyntax, compileArguments.ToString(), out errorString );

                if( !string.IsNullOrEmpty( errorString ) )
                    Log.Fatal( errorString );

                if( program != null )
                {
                    GpuProgramParameters parameters = program.DefaultParameters;
                    SetProgramAutoConstants( parameters );
                    pass.VertexProgramName = program.Name;
                }
            }

            //fragment program
            {
                string errorString;

                GpuProgram program = GpuProgramCacheManager.Instance.AddProgram(
                    "WaterPlane_Fragment_", GpuProgramType.FragmentProgram, sourceFile,
                    "main_fp", fragmentSyntax, compileArguments.ToString(), out errorString );

                if( !string.IsNullOrEmpty( errorString ) )
                    Log.Fatal( errorString );

                if( program != null )
                {
                    SetProgramAutoConstants( program.DefaultParameters );
                    pass.FragmentProgramName = program.Name;
                }
            }
        }
Exemplo n.º 8
0
        public void make()
        {
            if (type != tileTypes.wall)
            {
                unique++;
                //create a scene node, off the root scene node
                sn = Program.Instance.sceneManager.RootSceneNode.CreateChildSceneNode();
                //Load the mesh into the entity
                ent = Program.Instance.sceneManager.CreateEntity("tile" + unique, "Floor.mesh");
                //Attach the Entity to the scene node
                sn.AttachObject(ent);
                sn.Position = new Vector3(pos.x * Program.Instance.gameManager.tileSpacing, 0, pos.y * Program.Instance.gameManager.tileSpacing);

                MaterialPtr m = ent.GetSubEntity(0).GetMaterial();
                m.Clone("Bmat" + unique);
                MaterialPtr ma = MaterialManager.Singleton.GetByName("Bmat" + unique);
                Technique t = ma.GetTechnique(0);
                Pass p = t.GetPass(0);
                tus = p.GetTextureUnitState(0);

                switch (type)
                {
                    case tileTypes.corridor:
                        tus.SetTextureName("dirt_" + Program.Instance.random.Next(0, 5).ToString() + ".png");
                        break;
                    case tileTypes.room:
                        tus.SetTextureName("room_" + Program.Instance.random.Next(0, 10).ToString() + ".png");
                        break;
                    case tileTypes.door:
                        tus.SetTextureName("cdoor.png");
                        break;
                    case tileTypes.level_start:
                        tus.SetTextureName("up.png");
                        break;
                    case tileTypes.level_end:
                        tus.SetTextureName("down.png");
                        break;
                }

                ent.GetSubEntity(0).MaterialName = "Bmat" + unique;
            }
            else
            {
                if (pos.x > 0 && pos.y > 0 && pos.x < Program.Instance.gameManager.currentLevel.size.x - 1 && pos.y < Program.Instance.gameManager.currentLevel.size.y - 1)
                {
                    Console.WriteLine("MAKING WALL TILE: " + pos.ToString());
                    bool makeWall = false;
                    if (Program.Instance.gameManager.currentLevel.tiles[(int)pos.x - 1, (int)pos.y].type != tileTypes.wall)
                    {
                        makeWall = true;
                    }
                    if (Program.Instance.gameManager.currentLevel.tiles[(int)pos.x + 1, (int)pos.y].type != tileTypes.wall && !makeWall)
                    {
                        makeWall = true;
                    }
                    if (Program.Instance.gameManager.currentLevel.tiles[(int)pos.x, (int)pos.y - 1].type != tileTypes.wall && !makeWall)
                    {
                        makeWall = true;
                    }
                    if (Program.Instance.gameManager.currentLevel.tiles[(int)pos.x, (int)pos.y + 1].type != tileTypes.wall && !makeWall)
                    {
                        makeWall = true;
                    }

                    if (makeWall)
                    {
                        unique++;
                        //create a scene node, off the root scene node
                        sn = Program.Instance.sceneManager.RootSceneNode.CreateChildSceneNode();
                        //Load the mesh into the entity
                        ent = Program.Instance.sceneManager.CreateEntity("wall" + unique, "wall.mesh");
                        //Attach the Entity to the scene node
                        sn.AttachObject(ent);
                        sn.Position = new Vector3(pos.x * Program.Instance.gameManager.tileSpacing, 0, pos.y * Program.Instance.gameManager.tileSpacing);

                    }
                }

            }
        }
Exemplo n.º 9
0
        private bool initScreen(int i)
        {
            MaterialPtr      overlayMaterial = null;
            TextureUnitState unit            = null;

            animation           = null;
            currentMaterialName = null;
            if (isScreenAnAd[i - 1]) // poczatkowo i = 1
            {
                // pobierz i ustaw na bie¿ac¹
                AdManager.AdStatus status = AdManager.Singleton.GetAd(C_AD_ZONE, 1.0f, out currentAd);

                if (status == AdManager.AdStatus.OK)
                {
                    // pobieranie OK.
                    currentMaterialName = C_AD_MATERIAL;
                    string path = AdManager.Singleton.LoadAdTexture(currentAd);
                    if (path == null)
                    {
                        return(false);
                    }
                    showAdText(viewport);


                    overlayMaterial = MaterialManager.Singleton.GetByName(currentMaterialName);
                    overlayMaterial.Load();
                    unit = overlayMaterial.GetBestTechnique().GetPass(0).GetTextureUnitState(0);

                    unit.SetTextureName(path);
                    AdManager.Singleton.RegisterImpression(currentAd);

                    //   int count;
                    //   count = adAction.Get_Ad_Impression_Counter(currentAd.id);
                    //    Console.WriteLine("Pobrañ: " + count);
                }
                else
                {
                    hideAdText();
                    return(false);
                }
            }
            else
            {
                currentMaterialName = C_TEXTURE_NAME + currentScreen;
                overlayMaterial     = MaterialManager.Singleton.GetByName(currentMaterialName);
                overlayMaterial.Load();
                unit = overlayMaterial.GetBestTechnique().GetPass(0).GetTextureUnitState(0);
                hideAdText();
            }



            textureDimensions = unit.GetTextureDimensions();
            PointD scale = new PointD(1, 1);
            // skaluj overlay tak aby tekstury nie zmienia³y swoich proporcji
            float prop = 1.0f;

            if (isScreenAnAd[currentScreen - 1])
            {
                // reklamy maja zachowac oryginalna rozdzielczosc
                scale = AdSizeUtils.ScaleAdToDisplay(textureDimensions, new PointD(Viewport.ActualWidth, Viewport.ActualHeight), true);
                scale = 0.65f * scale;
            }
            else
            {
                prop = 1.0f / ((1.0f * textureDimensions.first / textureDimensions.second) / (1.0f * Viewport.ActualWidth / Viewport.ActualHeight));
                // wychodzimy poza ekran
                if (scale.Y * prop > 1.0f)
                {
                    float scalingFactor = 1.0f / (scale.Y * prop);
                    scale.X *= scalingFactor; scale.Y *= scalingFactor;
                }

                if (scale.X * prop > 1.0f)
                {
                    float scalingFactor = 1.0f / (scale.X * prop);
                    scale.X *= scalingFactor; scale.Y *= scalingFactor;
                }
            }
            overlay.SetScale(scale.X, scale.Y * prop);



            animation =
                new EffectTextureAnimation(null, unit, screenTimes[i - 1], "QuitAnimation",
                                           VisibilityNodeAnimation.VisibilityType.VISIBLE,
                                           VisibilityNodeAnimation.VisibilityType.VISIBLE);

            animation.Enabled = true;
            animation.Looped  = true;
            OverlayContainer container = overlay.GetChild("Wof/QuitScreen");

            container.MaterialName = currentMaterialName;

            EffectsManager.Singleton.AddCustomEffect(animation);
            lastChange = DateTime.Now;
            return(true);
        }
Exemplo n.º 10
0
        private void CreateShaderMaterials(Quake3Level q3lvl, SceneManager sm)
        {
            // NB this only works for the 'default' shaders for now
            // i.e. those that don't have a .shader script and thus default
            // to just texture + lightmap
            // TODO: pre-parse all .shader files and create lookup for next stage (use ROGL shader_file_t)

            // Material names are shadername#lightmapnumber
            // This is because I like to define materials up front completely
            // rather than combine lightmap and shader dynamically (it's
            // more generic). It results in more materials, but they're small
            // beer anyway. Texture duplication is prevented by infrastructure.
            // To do this I actually need to parse the faces since they have the
            // shader/lightmap combo (lightmap number is not in the shader since
            // it can be used with multiple lightmaps)
            string shaderName;
            int    face = q3lvl.Faces.Length;

            while (face-- > 0)
            {
                // Check to see if existing material
                // Format shader#lightmap
                int shadIdx = q3lvl.Faces[face].shader;

                shaderName = String.Format("{0}#{1}", q3lvl.Shaders[shadIdx].name, q3lvl.Faces[face].lmTexture);
                Material shadMat = sm.GetMaterial(shaderName);

                if (shadMat == null && !bspOptions.useLightmaps)
                {
                    // try the no-lightmap material
                    shaderName = String.Format("{0}#n", q3lvl.Shaders[shadIdx].name);
                    shadMat    = sm.GetMaterial(shaderName);
                }

                if (shadMat == null)
                {
                    // Colour layer
                    // NB no extension in Q3A(doh), have to try shader, .jpg, .tga
                    string tryName = q3lvl.Shaders[shadIdx].name;

                    // Try shader first
                    Quake3Shader shader = (Quake3Shader)Quake3ShaderManager.Instance.GetByName(tryName);

                    if (shader != null)
                    {
                        shadMat = shader.CreateAsMaterial(sm, q3lvl.Faces[face].lmTexture);
                    }
                    else
                    {
                        // No shader script, try default type texture
                        shadMat = sm.CreateMaterial(shaderName);
                        Pass shadPass = shadMat.GetTechnique(0).GetPass(0);

                        // Try jpg
                        TextureUnitState tex = shadPass.CreateTextureUnitState(tryName + ".jpg");
                        tex.Load();

                        if (tex.IsBlank)
                        {
                            // Try tga
                            tex.SetTextureName(tryName + ".tga");
                        }

                        // Set replace on all first layer textures for now
                        tex.SetColorOperation(LayerBlendOperation.Replace);
                        tex.TextureAddressing = TextureAddressing.Wrap;

                        // for ambient lighting
                        tex.ColorBlendMode.source2 = LayerBlendSource.Manual;

                        if (bspOptions.useLightmaps && q3lvl.Faces[face].lmTexture != -1)
                        {
                            // Add lightmap, additive blending
                            tex = shadPass.CreateTextureUnitState(String.Format("@lightmap{0}", q3lvl.Faces[face].lmTexture));

                            // Blend
                            tex.SetColorOperation(LayerBlendOperation.Modulate);

                            // Use 2nd texture co-ordinate set
                            tex.TextureCoordSet = 1;

                            // Clamp
                            tex.TextureAddressing = TextureAddressing.Clamp;
                        }

                        shadMat.CullingMode = CullingMode.None;
                        shadMat.Lighting    = false;
                    }
                }

                shadMat.Load();

                // Copy face data
                BspStaticFaceGroup dest = CopyShaderFaceData(q3lvl, face, shadMat, shadIdx);

                faceGroups[face] = dest;
            }
        }
Exemplo n.º 11
0
        /// <summary>
        ///
        /// </summary>
        protected void Initialize()
        {
            // Create geometry
            int nvertices = this.slices * 4;           // n+1 planes
            int elemsize  = 3 * 3;
            int dsize     = elemsize * nvertices;
            int x;

            var indexData  = new IndexData();
            var vertexData = new VertexData();
            var vertices   = new float[dsize];

            var coords = new float[4, 2]
            {
                {
                    0.0f, 0.0f
                }, {
                    0.0f, 1.0f
                }, {
                    1.0f, 0.0f
                }, {
                    1.0f, 1.0f
                }
            };

            for (x = 0; x < this.slices; x++)
            {
                for (int y = 0; y < 4; y++)
                {
                    float xcoord = coords[y, 0] - 0.5f;
                    float ycoord = coords[y, 1] - 0.5f;
                    float zcoord = -((float)x / (float)(this.slices - 1) - 0.5f);
                    // 1.0f .. a/(a+1)
                    // coordinate
                    vertices[x * 4 * elemsize + y * elemsize + 0] = xcoord * (this.size / 2.0f);
                    vertices[x * 4 * elemsize + y * elemsize + 1] = ycoord * (this.size / 2.0f);
                    vertices[x * 4 * elemsize + y * elemsize + 2] = zcoord * (this.size / 2.0f);
                    // normal
                    vertices[x * 4 * elemsize + y * elemsize + 3] = 0.0f;
                    vertices[x * 4 * elemsize + y * elemsize + 4] = 0.0f;
                    vertices[x * 4 * elemsize + y * elemsize + 5] = 1.0f;
                    // tex
                    vertices[x * 4 * elemsize + y * elemsize + 6] = xcoord * Utility.Sqrt(3.0f);
                    vertices[x * 4 * elemsize + y * elemsize + 7] = ycoord * Utility.Sqrt(3.0f);
                    vertices[x * 4 * elemsize + y * elemsize + 8] = zcoord * Utility.Sqrt(3.0f);
                }
            }

            var faces = new short[this.slices * 6];

            for (x = 0; x < this.slices; x++)
            {
                faces[x * 6 + 0] = (short)(x * 4 + 0);
                faces[x * 6 + 1] = (short)(x * 4 + 1);
                faces[x * 6 + 2] = (short)(x * 4 + 2);
                faces[x * 6 + 3] = (short)(x * 4 + 1);
                faces[x * 6 + 4] = (short)(x * 4 + 2);
                faces[x * 6 + 5] = (short)(x * 4 + 3);
            }

            //setup buffers
            vertexData.vertexStart = 0;
            vertexData.vertexCount = nvertices;

            VertexDeclaration   decl = vertexData.vertexDeclaration;
            VertexBufferBinding bind = vertexData.vertexBufferBinding;
            int offset = 0;

            offset += decl.AddElement(0, 0, VertexElementType.Float3, VertexElementSemantic.Position).Size;
            offset += decl.AddElement(0, offset, VertexElementType.Float3, VertexElementSemantic.Normal).Size;
            offset += decl.AddElement(0, offset, VertexElementType.Float3, VertexElementSemantic.TexCoords).Size;

            HardwareVertexBuffer vertexBuffer = HardwareBufferManager.Instance.CreateVertexBuffer(decl, nvertices,
                                                                                                  BufferUsage.StaticWriteOnly);

            bind.SetBinding(0, vertexBuffer);

            HardwareIndexBuffer indexBuffer = HardwareBufferManager.Instance.CreateIndexBuffer(IndexType.Size16, this.slices * 6,
                                                                                               BufferUsage.StaticWriteOnly);

            indexData.indexBuffer = indexBuffer;
            indexData.indexCount  = this.slices * 6;
            indexData.indexStart  = 0;

            indexBuffer.WriteData(0, indexBuffer.Size, faces, true);
            vertexBuffer.WriteData(0, vertexBuffer.Size, vertices);
            vertices = null;
            faces    = null;

            // Now make the render operation
            renderOperation.operationType = OperationType.TriangleList;
            renderOperation.indexData     = indexData;
            renderOperation.vertexData    = vertexData;
            renderOperation.useIndices    = true;

            // Create a brand new private material
            if (!ResourceGroupManager.Instance.GetResourceGroups().Contains("VolumeRendable"))
            {
                ResourceGroupManager.Instance.CreateResourceGroup("VolumeRendable");
            }

            var material = (Material)MaterialManager.Instance.Create(this.texture, "VolumeRendable");

            // Remove pre-created technique from defaults
            material.RemoveAllTechniques();

            // Create a techinique and a pass and a texture unit
            Technique        technique   = material.CreateTechnique();
            Pass             pass        = technique.CreatePass();
            TextureUnitState textureUnit = pass.CreateTextureUnitState();

            // Set pass parameters
            pass.SetSceneBlending(SceneBlendType.TransparentAlpha);
            pass.DepthWrite      = false;
            pass.CullingMode     = CullingMode.None;
            pass.LightingEnabled = false;
            textureUnit.SetTextureAddressingMode(TextureAddressing.Clamp);
            textureUnit.SetTextureName(this.texture, TextureType.ThreeD);
            textureUnit.SetTextureFiltering(TextureFiltering.Trilinear);

            this.unit     = textureUnit;
            base.material = material;
        }