public SpecularMaterial(ShaderProgram shaderProgram, string texturepath)
 {
     sp = shaderProgram;
     Textureparam = sp.GetShaderParam("texture1");
     SpecularLevel = sp.GetShaderParam("specularLevel");
     Shininess = sp.GetShaderParam("shininess");
     ImageData Image = SceneManager.RC.LoadImage(texturepath);
     Tex = SceneManager.RC.CreateTexture(Image);
 }
 public BumpMaterial(ShaderProgram shaderProgram, string texturepath, string texturepath2)
 {
     sp = shaderProgram;
     NormalTextureparam = sp.GetShaderParam("normalTex");
     Textureparam = sp.GetShaderParam("texture1");
     SpecularLevel = sp.GetShaderParam("specularLevel");
     Shininess = sp.GetShaderParam("shininess");
     ImageData image = SceneManager.RC.LoadImage(texturepath);
     ImageData image2 = SceneManager.RC.LoadImage(texturepath2);
     Tex = SceneManager.RC.CreateTexture(image);
     NormalTex = SceneManager.RC.CreateTexture(image2);
 }
예제 #3
0
        public Level(RenderContext rc, ShaderProgram sp, int id, Stereo3D stereo3D)
        {
            ObjRandom = new Random();

            VColorObj = sp.GetShaderParam("vColor");
            VTextureObj = sp.GetShaderParam("vTexture");

            RContext = rc;

            _stereo3D = stereo3D;
            UseStereo3D = false;

            ConstructLevel(id);
        }
예제 #4
0
        // is called on startup
        public override void Init()
        {
            RC.ClearColor = new float4(0.1f, 0.1f, 0.5f, 1);

            // IMPORTANT: You are supposed to use either one SetWindowSize() or VideoWall(). You can't use both.
            // It's possible to resize a window to fit on a video wall or display.
            // Here are some different variants how to use this functionality. Uncomment to test.
            //SetWindowSize(800, 600);
            SetWindowSize(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height/9 * 2, true, 0, 0);
            //SetWindowSize(Screen.PrimaryScreen.Bounds.Width/9 * 2, Screen.PrimaryScreen.Bounds.Height, true, 0, 0);
            //SetWindowSize(640, 480, false, Screen.PrimaryScreen.Bounds.Width/2 - 640/2, Screen.PrimaryScreen.Bounds.Height/2 - 480/2);
            // IMPORTANT: For video Walls or projector matrices it's possible to let the system do the magic by
            // giving it the number of monitors/projectors per axis and specify some border information.
            // This only works in pseudo-fullscreen mode a.k.a borderless fullscreen-window.
            //VideoWall(0, 0, true, false);

            // This is the old method. More than this could not be done directly in a project code(?)
            //Width = 640;
            //Height = 480;

            // Initialize an ui.
            _guiHandler = new GUIHandler();
            _guiHandler.AttachToContext(RC);

            // Create a new element.
            GUIElement element = new GUIImage("Assets/image.png", 0, 0, -10, 320, 130);

            // Add the element to the gui.
            _guiHandler.Add(element);

            // Add something to render.
            _cube = new Cube();
            _spcolor = MoreShaders.GetDiffuseColorShader(RC);
            _colorParam = _spcolor.GetShaderParam("color");
        }
 public DiffuseMaterial(ShaderProgram shaderProgram, string texturepath)
 {
     sp = shaderProgram;
     Textureparam = sp.GetShaderParam("texture1");
     ImageData Image = SceneManager.RC.LoadImage(texturepath);
     Tex = SceneManager.RC.CreateTexture(Image);
 }
        public PlanetMaterial(ShaderProgram shaderProgram, string texturePath)
        {
            sp = shaderProgram;

            TextureParam = sp.GetShaderParam("texture1");

            var image = SceneManager.RC.LoadImage(texturePath);
            Tex = SceneManager.RC.CreateTexture(image);
        }
예제 #7
0
        public override void Init()
        {
            Input.Instance.InitializeDevices();

            _meshTea = MeshReader.LoadMesh(@"Assets/Teapot.obj.model");

            _spColor = MoreShaders.GetDiffuseColorShader(RC);
            _colorParam = _spColor.GetShaderParam("color");
        }
예제 #8
0
        public override void Init()
        {
            RC.ClearColor = new float4(1, 1, 1, 1);
            _spColor = MoreShaders.GetDiffuseColorShader(RC);
            _colorParam = _spColor.GetShaderParam("color");
            RC.SetShader(_spColor);
            RC.SetShaderParam(_colorParam, new float4(1, 0, 0, 1));
            _watch = new Stopwatch();
            _ser = new FuseeSerializer();
            Debug.WriteLine("Serialisation Example started. \nPress F1 to load Mesh using MeshReader. \nPress F2 to load Mesh using Protobuf.");

            // Example of how to save a Mesh with protobuf to file.
            /*Mesh temp = MeshReader.LoadMesh(@"Assets/Teapot.obj.model");
            using (var file = File.Create(@"Assets/Teapot2.protobuf.model"))
            {
                _ser.Serialize(file,temp);
            }*/
        }
        // is called on startup
        public override void Init()
        {
            _theColor = new float4(0.5f, 0.8f, 0, 1);
            RC.ClearColor = new float4(1, 1, 1, 1);

            // initialize the variables
            _meshTea = MeshReader.LoadMesh(@"Assets/Teapot.obj.model");
            _meshFace = MeshReader.LoadMesh(@"Assets/Face.obj.model");

            _spColor = MoreShaders.GetShader("simple", RC);
            _spTexture = MoreShaders.GetShader("texture", RC);

            _colorParam = _spColor.GetShaderParam("vColor");
            _textureParam = _spTexture.GetShaderParam("texture1");

            // load texture
            var imgData = RC.LoadImage("Assets/world_map.jpg");
            _iTex = RC.CreateTexture(imgData);
        }
예제 #10
0
        // is called on startup
        public override void Init()
        {
            RC.ClearColor = new float4(1, 1, 1, 1);
            skypox = LoadSkybox();
            var img = RC.LoadImage("Assets/skyboxOberflächenfarbe.jpg");
            _iTex = RC.CreateTexture(img);
            // initialize the variables
            _meshTea = MeshReader.LoadMesh(@"Assets/Teapot.obj.model");
            // _meshFace = MeshReader.LoadMesh(@"Assets/coords.obj.model"); ;
            _meshFace = new Cube();

            _spColor = MoreShaders.GetDiffuseColorShader(RC);
            _spTexture = MoreShaders.GetTextureShader(RC);

            _colorParam = _spColor.GetShaderParam("color");
            _textureParam = _spTexture.GetShaderParam("texture1");

            // load texture
            //var imgData = RC.LoadImage("Assets/coords.jpg");
            //_iTex = RC.CreateTexture(imgData);
            _zz = 0.0f;
        }
        // is called on startup
        public override void Init()
        {
            RC.ClearColor = new float4(0.2f, 0.2f, 0.2f, 1);

            _smokeTexture           = RC.CreateShader(_smokeEmitter.VsSimpleTexture, _smokeEmitter.PsSimpleTexture);
            _fireRedTexture         = RC.CreateShader(_fireRedEmitter.VsSimpleTexture, _fireRedEmitter.PsSimpleTexture);
            _fireYellowTexture      = RC.CreateShader(_fireYellowEmitter.VsSimpleTexture, _fireYellowEmitter.PsSimpleTexture);
            _starTexture            = RC.CreateShader(_starEmitter.VsSimpleTexture, _starEmitter.PsSimpleTexture);

            _smokeParam             = _smokeTexture.GetShaderParam("texture1");
            _fireRedParam           = _fireRedTexture.GetShaderParam("texture1");
            _fireYellowParam        = _fireYellowTexture.GetShaderParam("texture1");
            _starParam              = _starTexture.GetShaderParam("texture1");

            // load texture
            var imgSmokeData        = RC.LoadImage("Assets/smoke_particle.png");
            var imgFireRedData      = RC.LoadImage("Assets/fireRed.png");
            var imgFireYellowData   = RC.LoadImage("Assets/fireYellowTexture.png");
            var imgStarData         = RC.LoadImage("Assets/star.png");

            _iSmoke                 = RC.CreateTexture(imgSmokeData);
            _iFireRed               = RC.CreateTexture(imgFireRedData);
            _iFireYellow            = RC.CreateTexture(imgFireYellowData);
            _iStar                  = RC.CreateTexture(imgStarData);

            RC.SetRenderState(new RenderStateSet
            {
                ZEnable = false,
                AlphaBlendEnable = true,
                BlendOperation = BlendOperation.Add,
                SourceBlend = Blend.SourceAlpha,
                DestinationBlend = Blend.InverseSourceAlpha
            });

            // GUIHandler
            _guiHandler = new GUIHandler();
            _guiHandler.AttachToContext(RC);

            // font + text
            _guiFontCabin18 = RC.LoadFont("Assets/Cabin.ttf", 18);
            _guiFontCabin24 = RC.LoadFont("Assets/Cabin.ttf", 24);

            _guiText = new GUIText("Fusee3D Particle System ", _guiFontCabin24, 510, 35);
            _guiText.TextColor = new float4(1, 1, 1, 1);

            _guiHandler.Add(_guiText);

            // panel
            _guiPanel = new GUIPanel("Menu", _guiFontCabin18, 10, 10, 150, 150);
            _guiHandler.Add(_guiPanel);

            // Example 1 button
            _guiExampleOneButton = new GUIButton("Fog", _guiFontCabin18, 25, 40, 100, 25);

            _guiExampleOneButton.OnGUIButtonDown += OnMenuButtonDown;
            _guiExampleOneButton.OnGUIButtonUp += OnMenuButtonUp;
            _guiExampleOneButton.OnGUIButtonEnter += OnMenuButtonEnter;
            _guiExampleOneButton.OnGUIButtonLeave += OnMenuButtonLeave;

            _guiPanel.ChildElements.Add(_guiExampleOneButton);

            // Example 2 button
            _guiExampleTwoButton = new GUIButton("Fire", _guiFontCabin18, 25, 70, 100, 25);

            _guiExampleTwoButton.OnGUIButtonDown += OnMenuButtonDown;
            _guiExampleTwoButton.OnGUIButtonUp += OnMenuButtonUp;
            _guiExampleTwoButton.OnGUIButtonEnter += OnMenuButtonEnter;
            _guiExampleTwoButton.OnGUIButtonLeave += OnMenuButtonLeave;

            _guiPanel.ChildElements.Add(_guiExampleTwoButton);

            // Example 2 button
            _guiExampleThreeButton = new GUIButton("Stars", _guiFontCabin18, 25, 100, 100, 25);

            _guiExampleThreeButton.OnGUIButtonDown += OnMenuButtonDown;
            _guiExampleThreeButton.OnGUIButtonUp += OnMenuButtonUp;
            _guiExampleThreeButton.OnGUIButtonEnter += OnMenuButtonEnter;
            _guiExampleThreeButton.OnGUIButtonLeave += OnMenuButtonLeave;

            _guiPanel.ChildElements.Add(_guiExampleThreeButton);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="RenderContext"/> class.
        /// </summary>
        /// <param name="rci">The <see cref="Fusee.Engine.IRenderContextImp"/>.</param>
        public RenderContext(IRenderContextImp rci)
        {
            _rci = rci;
            View = float4x4.Identity;
            ModelView = float4x4.Identity;
            Projection = float4x4.Identity;

            // Todo: Remove multiple Lights per shader !!!
            _lightParams = new Light[8];
            _lightShaderParams = new LightParamNames[8];

            _currentShaderParams = new MatrixParamNames();
            _updatedShaderParams = false;

            _debugShader = MoreShaders.GetDiffuseColorShader(this);
            _debugColor = _debugShader.GetShaderParam("color");
        }
예제 #13
0
        /// <summary>
        /// Attaches the object to a specific <see cref="RenderContext"/> object.
        /// </summary>
        /// <param name="rc">The <see cref="RenderContext"/> object to be used.</param>
        public void AttachToContext(RenderContext rc)
        {
            _rc = rc;
            _clearColor = rc.ClearColor;

            var imgData = _rc.CreateImage(_screenWidth, _screenHeight, "black");
            _contentLTex = _rc.CreateTexture(imgData);
            _contentRTex = _rc.CreateTexture(imgData);

            // initialize shader and image
            switch (_activeMode)
            {
                case Stereo3DMode.Oculus:
                    _guiLImage = new GUIImage(null, 0, 0, _screenWidth/2, _screenHeight);
                    _guiLImage.AttachToContext(rc);
                    _guiLImage.Refresh();

                    _guiRImage = new GUIImage(null, _screenWidth/2, 0, _screenWidth/2, _screenHeight);
                    _guiRImage.AttachToContext(rc);
                    _guiRImage.Refresh();

                    _shaderProgram = _rc.CreateShader(OculusVs, OculusPs);
                    _shaderTexture = _shaderProgram.GetShaderParam("vTexture");

                    _lensCenterParam = _shaderProgram.GetShaderParam("LensCenter");
                    _screenCenterParam = _shaderProgram.GetShaderParam("ScreenCenter");
                    _scaleParam = _shaderProgram.GetShaderParam("Scale");
                    _scaleInParam = _shaderProgram.GetShaderParam("ScaleIn");
                    _hdmWarpParam = _shaderProgram.GetShaderParam("HmdWarpParam");

                    break;

                case Stereo3DMode.Anaglyph:
                    _shaderProgram = _rc.CreateShader(AnaglyphVs, AnaglyphPs);
                    _shaderTexture = _shaderProgram.GetShaderParam("vTexture");

                    _guiLImage = new GUIImage(null, 0, 0, _screenWidth, _screenHeight);
                    _guiLImage.AttachToContext(rc);
                    _guiLImage.Refresh();

                    break;
            }
        }
예제 #14
0
        public override void Init()
        {
            // is called on startup
            RC.ClearColor = new float4(1, 1, 1, 1);

            // initialize the variables
            _meshTea = MeshReader.LoadMesh(@"Assets/Teapot.obj.model");
            _meshCube = MeshReader.LoadMesh(@"Assets/Cube.obj.model");
            _meshSphere = MeshReader.LoadMesh(@"Assets/Sphere.obj.model");
            _meshCylinder = MeshReader.LoadMesh(@"Assets/Cylinder.obj.model");
            _meshPlatinic = MeshReader.LoadMesh(@"Assets/Platonic.obj.model");
            //RC.CreateShader(Vs, Ps);
            _spColor = RC.CreateShader(Vs, Ps); //MoreShaders.GetShader("simple", RC);
            _spTexture = RC.CreateShader(Vt, Pt);//MoreShaders.GetShader("texture", RC);
            _spCustom = RC.CreateShader(VLin, PLin);
            _colorParam = _spColor.GetShaderParam("vColor");
            _colorCustom = _spCustom.GetShaderParam("vColor");
            _textureParam = _spTexture.GetShaderParam("vTexture");

            // load texture
            var imgData = RC.LoadImage("Assets/world_map.jpg");
            _iTex = RC.CreateTexture(imgData);

            _physic = new Physics();

            _gui= new GUI(RC);
            _gui.SetUp(_physic.GetNumRB(), _physic.GetShapes());
        }
        public override void Init()
        {
            VSync = false;

            // Start the application in demo mode?
            demoMode = true;

            #region MeshImports
            _Geo = new Geometry();
            //_Geo.LoadAsset("Assets/Cube.obj.model");
            //_Geo.LoadAsset("Assets/Cube_quads.obj.model");
            //_Geo.LoadAsset("Assets/Sphere.obj.model");
            //_Geo.LoadAsset("Assets/Sphere_quads.obj.model");
            //_Geo.LoadAsset("Assets/SharedCorners.obj.model");
            //_Geo.LoadAsset("Assets/Cylinder.obj.model");
            //_Geo.LoadAsset("Assets/Cylinder_quads.obj.model");
            //_Geo.LoadAsset("Assets/SharedCorners_pro.obj.model");
            _Geo.LoadAsset("Assets/Teapot.obj.model");

            // Due to copyright reasons, this file will not be delivered with the project.
            //_Geo.LoadAsset("Assets/Hellknight.obj.model");
            #endregion MeshImports

            // Set the smoothing angle for the edge based vertex normal calculation
            // Feel free to test around.
            _Geo._SmoothingAngle = 89.0;

            // The shader colors here are not supposed to be changed. They don't have an effect. If you want to change the shaders
            // then please change the values in the ShaderChanger() method. These ones are just for declaration.
            #region Shaders
            #region TextureShader

            _msDiffuse = MoreShaders.GetDiffuseTextureShader(RC);
            _vLightShaderParam = _msDiffuse.GetShaderParam("texture1");

            //ImageData imgData = RC.LoadImage("Assets/Cube_Mat_uv.jpg");
            ImageData imgData = RC.LoadImage("Assets/world_map.jpg");
            //ImageData imgData = RC.LoadImage("Assets/Teapot_Texture.jpg");

            // Due to copyright reasons, this file will not be delivered with the project.
            //ImageData imgData = RC.LoadImage("Assets/Hellknight.jpg");

            _tex = RC.CreateTexture(imgData);
            #endregion TextureShader

            #region ColorShader

            _spColor = MoreShaders.GetDiffuseColorShader(RC);
            _colorParam = _spColor.GetShaderParam("color");

            RC.SetShader(_spColor);
            RC.SetShaderParam(_colorParam, new float4(0f, 0f, 0f, 1));
            #endregion ColorShader

            #region LightPos

            RC.SetLightActive(0, 0f);
            RC.SetLightAmbient(0, new float4(0.0f, 0.0f, 0.0f, 1.0f));
            RC.SetLightDiffuse(0, new float4(1.0f, 1.0f, 1.0f, 1.0f));
            RC.SetLightDirection(0, new float3(0.0f, -1.0f, 0.0f));

            RC.SetLightActive(1, 0f);
            RC.SetLightAmbient(1, new float4(0.0f, 0.0f, 0.0f, 1.0f));
            RC.SetLightDiffuse(1, new float4(0.5f, 0.5f, 0.5f, 1.0f));
            RC.SetLightDirection(1, new float3(1.0f, 0.0f, 0.0f));

            #endregion LightPos
            #endregion

            // Convert the loaded lfg model to a fusee mesh the first time.
            _lfgmesh = _Geo.ToMesh();

            RC.ClearColor = new float4(0.2f, 0.2f, 0.2f, 1f);

            // TODO: For Benchmarking only.
            _ShaderType = 1;
            runDemoAnimation = true;
            _Geo._DoCalcVertexNormals = true;
        }
예제 #16
0
        public override void Init()
        {
            // Set ToonShaderEffect
            _shaderEffect.AttachToContext(RC);

            // Setup GUI

            // GUIHandler
            _guiHandler = new GUIHandler();
            _guiHandler.AttachToContext(RC);

            // font + text
            _guiFontCabin18 = RC.LoadFont("Assets/Cabin.ttf", 18);
            _guiFontCabin24 = RC.LoadFont("Assets/Cabin.ttf", 24);

            _guiText = new GUIText("FUSEE Shader Demo", _guiFontCabin24, 30, Height - 30)
            {
                TextColor = new float4(1, 1, 1, 1)
            };

            _guiHandler.Add(_guiText);

            // image
            _guiImage = new GUIImage("Assets/repbg.jpg", 0, 0, -5, Width, Height);
            _guiHandler.Add(_guiImage);
            _borderImage = new GUIImage("Assets/redbg.png", 0, 0, -4, 230, 32);
            //_guiHandler.Add(_borderImage);

            //* Menu1: Select Shader
            _panelSelectShader = new GUIPanel("Select Shader", _guiFontCabin24, 10, 10, 230, 230);
            _panelSelectShader.ChildElements.Add(_borderImage);
            _guiHandler.Add(_panelSelectShader);

            //** Possible Shader Buttons
            _btnDiffuseColorShader = new GUIButton("Diffuse Color", _guiFontCabin18, 25, 40, 180, 25);
            _btnTextureShader = new GUIButton("Texture Only", _guiFontCabin18, 25, 70, 180, 25);
            _btnDiffuseTextureShader = new GUIButton("Diffuse Texture", _guiFontCabin18, 25, 100, 180, 25);
            _btnDiffuseBumpTextureShader = new GUIButton("Diffuse Bump Texture", _guiFontCabin18, 25, 130, 180, 25);
            _btnSpecularTexture = new GUIButton("Specular Texture", _guiFontCabin18, 25, 160, 180, 25);
            _btnToon = new GUIButton("Toon", _guiFontCabin18, 25, 190, 180, 25);

            //*** Add Handlers
            _btnDiffuseColorShader.OnGUIButtonDown += OnMenuButtonDown;
            _btnDiffuseColorShader.OnGUIButtonUp += OnMenuButtonUp;
            _btnDiffuseColorShader.OnGUIButtonEnter += OnMenuButtonEnter;
            _btnDiffuseColorShader.OnGUIButtonLeave += OnMenuButtonLeave;

            _btnTextureShader.OnGUIButtonDown += OnMenuButtonDown;
            _btnTextureShader.OnGUIButtonUp += OnMenuButtonUp;
            _btnTextureShader.OnGUIButtonEnter += OnMenuButtonEnter;
            _btnTextureShader.OnGUIButtonLeave += OnMenuButtonLeave;

            _btnDiffuseTextureShader.OnGUIButtonDown += OnMenuButtonDown;
            _btnDiffuseTextureShader.OnGUIButtonUp += OnMenuButtonUp;
            _btnDiffuseTextureShader.OnGUIButtonEnter += OnMenuButtonEnter;
            _btnDiffuseTextureShader.OnGUIButtonLeave += OnMenuButtonLeave;

            _btnDiffuseBumpTextureShader.OnGUIButtonDown += OnMenuButtonDown;
            _btnDiffuseBumpTextureShader.OnGUIButtonUp += OnMenuButtonUp;
            _btnDiffuseBumpTextureShader.OnGUIButtonEnter += OnMenuButtonEnter;
            _btnDiffuseBumpTextureShader.OnGUIButtonLeave += OnMenuButtonLeave;

            _btnSpecularTexture.OnGUIButtonDown += OnMenuButtonDown;
            _btnSpecularTexture.OnGUIButtonUp += OnMenuButtonUp;
            _btnSpecularTexture.OnGUIButtonEnter += OnMenuButtonEnter;
            _btnSpecularTexture.OnGUIButtonLeave += OnMenuButtonLeave;

            _btnToon.OnGUIButtonDown += OnMenuButtonDown;
            _btnToon.OnGUIButtonUp += OnMenuButtonUp;
            _btnToon.OnGUIButtonEnter += OnMenuButtonEnter;
            _btnToon.OnGUIButtonLeave += OnMenuButtonLeave;

            //**** Add Buttons to Panel
            _panelSelectShader.ChildElements.Add(_btnDiffuseColorShader);
            _panelSelectShader.ChildElements.Add(_btnTextureShader);
            _panelSelectShader.ChildElements.Add(_btnDiffuseTextureShader);
            _panelSelectShader.ChildElements.Add(_btnDiffuseBumpTextureShader);
            _panelSelectShader.ChildElements.Add(_btnSpecularTexture);
            _panelSelectShader.ChildElements.Add(_btnToon);

            //* Menu3: Select Mesh
            _panelSelectMesh = new GUIPanel("Select Mesh", _guiFontCabin24, 270, 10, 230, 130);
            _panelSelectMesh.ChildElements.Add(_borderImage);
            _guiHandler.Add(_panelSelectMesh);

            //** Possible Meshes
            _btnCube = new GUIButton("Cube", _guiFontCabin18, 25, 40, 180, 25);
            _btnSphere = new GUIButton("Sphere", _guiFontCabin18, 25, 70, 180, 25);
            _btnTeapot = new GUIButton("Teapot", _guiFontCabin18, 25, 100, 180, 25);
            _panelSelectMesh.ChildElements.Add(_btnCube);
            _panelSelectMesh.ChildElements.Add(_btnSphere);
            _panelSelectMesh.ChildElements.Add(_btnTeapot);

            //** Add handlers
            _btnCube.OnGUIButtonDown += OnMenuButtonDown;
            _btnCube.OnGUIButtonUp += OnMenuButtonUp;
            _btnCube.OnGUIButtonEnter += OnMenuButtonEnter;
            _btnCube.OnGUIButtonLeave += OnMenuButtonLeave;

            _btnSphere.OnGUIButtonDown += OnMenuButtonDown;
            _btnSphere.OnGUIButtonUp += OnMenuButtonUp;
            _btnSphere.OnGUIButtonEnter += OnMenuButtonEnter;
            _btnSphere.OnGUIButtonLeave += OnMenuButtonLeave;

            _btnTeapot.OnGUIButtonDown += OnMenuButtonDown;
            _btnTeapot.OnGUIButtonUp += OnMenuButtonUp;
            _btnTeapot.OnGUIButtonEnter += OnMenuButtonEnter;
            _btnTeapot.OnGUIButtonLeave += OnMenuButtonLeave;

            //* Menu2: Light Settings
            _panelLightSettings = new GUIPanel("Light Settings", _guiFontCabin24, 530, 10, 230, 130);
            _panelLightSettings.ChildElements.Add(_borderImage);
            _guiHandler.Add(_panelLightSettings);

            //** Possible Light Settings
            _btnDirectionalLight = new GUIButton("Directional Light", _guiFontCabin18, 25, 40, 180, 25);
            _btnPointLight = new GUIButton("Point Light", _guiFontCabin18, 25, 70, 180, 25);
            _btnSpotLight = new GUIButton("Spot Light", _guiFontCabin18, 25, 100, 180, 25);
            _panelLightSettings.ChildElements.Add(_btnDirectionalLight);
            _panelLightSettings.ChildElements.Add(_btnPointLight);
            _panelLightSettings.ChildElements.Add(_btnSpotLight);

            //*** Add Handlers
            _btnDirectionalLight.OnGUIButtonDown += OnMenuButtonDown;
            _btnDirectionalLight.OnGUIButtonUp += OnMenuButtonUp;
            _btnDirectionalLight.OnGUIButtonEnter += OnMenuButtonEnter;
            _btnDirectionalLight.OnGUIButtonLeave += OnMenuButtonLeave;

            _btnPointLight.OnGUIButtonDown += OnMenuButtonDown;
            _btnPointLight.OnGUIButtonUp += OnMenuButtonUp;
            _btnPointLight.OnGUIButtonEnter += OnMenuButtonEnter;
            _btnPointLight.OnGUIButtonLeave += OnMenuButtonLeave;

            _btnSpotLight.OnGUIButtonDown += OnMenuButtonDown;
            _btnSpotLight.OnGUIButtonUp += OnMenuButtonUp;
            _btnSpotLight.OnGUIButtonEnter += OnMenuButtonEnter;
            _btnSpotLight.OnGUIButtonLeave += OnMenuButtonLeave;

            // Setup 3D Scene
            // Load Images and Assign iTextures
            var imgTexture = RC.LoadImage("Assets/crateTexture.jpg");
            var imgBumpTexture = RC.LoadImage("Assets/crateNormal.jpg");
            _texCube = RC.CreateTexture(imgTexture);
            _texBumpCube = RC.CreateTexture(imgBumpTexture);

            imgTexture = RC.LoadImage("Assets/earthTexture.jpg");
            imgBumpTexture = RC.LoadImage("Assets/earthNormal.jpg");
            _texSphere = RC.CreateTexture(imgTexture);
            _texBumpSphere = RC.CreateTexture(imgBumpTexture);

            imgTexture = RC.LoadImage("Assets/porcelainTexture.png");
            imgBumpTexture = RC.LoadImage("Assets/normalRust.jpg");
            _texTeapot = RC.CreateTexture(imgTexture);
            _texBumpTeapot = RC.CreateTexture(imgBumpTexture);

            _currentTexture = _texCube;
            _currentBumpTexture = _texBumpCube;

            // Load Meshes
            _meshCube = MeshReader.LoadMesh(@"Assets/Cube.obj.model");
            _meshSphere = MeshReader.LoadMesh(@"Assets/Sphere.obj.model");
            _meshTeapot = MeshReader.LoadMesh(@"Assets/Teapot.obj.model");

            // Set current Mesh and Update GUI
            _currentMesh = _meshCube;
            _btnCube.ButtonColor = ColorHighlightedButton;

            // Setup Shaderprograms and Update GUI
            _shaderDiffuseColor = MoreShaders.GetDiffuseColorShader(RC);
            _shaderDiffuseTexture = MoreShaders.GetDiffuseTextureShader(RC);
            _shaderTexture = MoreShaders.GetSkyboxShader(RC);
            _shaderDiffuseBumpTexture = MoreShaders.GetBumpDiffuseShader(RC);
            _shaderSpecularTexture = MoreShaders.GetSpecularShader(RC);
            _btnDiffuseColorShader.ButtonColor = ColorHighlightedButton;
            _currentShader = _shaderDiffuseColor;
            RC.SetShader(_shaderDiffuseColor);

            // Setup ShaderParams
            _paramColor = _shaderDiffuseColor.GetShaderParam("color");

            // Setup Light and Update GUI
            RC.SetLightActive(0, 1);
            RC.SetLightPosition(0, new float3(5.0f, 0.0f, -2.0f));
            RC.SetLightAmbient(0, new float4(0.2f, 0.2f, 0.2f, 1.0f));
            RC.SetLightSpecular(0, new float4(0.1f, 0.1f, 0.1f, 1.0f));
            RC.SetLightDiffuse(0, new float4(0.8f, 0.8f, 0.8f, 1.0f));
            RC.SetLightDirection(0, new float3(-1.0f, 0.0f, 0.0f));
            RC.SetLightSpotAngle(0, 10);

            _btnDirectionalLight.ButtonColor = ColorHighlightedButton;
        }
예제 #17
0
        // is called on startup
        public override void Init()
        {
            // ColorUint constructor test
            ColorUint ui1 = new ColorUint((uint) 4711);
            ColorUint ui2 = new ColorUint((byte)42, (byte)43, (byte)44, (byte)45);
            ColorUint u3 = new ColorUint((float)1, (float)43, (float)44, (float)45);

            RC.ClearColor = new float4(1f, 1f, 1f, 1);

            // initialize the variables
            _meshTea = MeshReader.LoadMesh(@"Assets/Teapot.obj.model");

            _shaderEffect.AttachToContext(RC);

            _spColor = MoreShaders.GetDiffuseColorShader(RC);
            _colorParam = _spColor.GetShaderParam("vColor");

            /*
            RC.SetRenderState(RenderState.ZEnable, (uint) 1);
            RC.SetRenderState(RenderState.AlphaBlendEnable, (uint) 1);
            RC.SetRenderState(RenderState.BlendFactor, (uint)new ColorUint(0.25f, 0.25f, 0.25f, 0.25f));
            RC.SetRenderState(RenderState.BlendOperation, (uint)(BlendOperation.Add));
            RC.SetRenderState(RenderState.SourceBlend, (uint)(Blend.BlendFactor));
            RC.SetRenderState(RenderState.DestinationBlend, (uint)(Blend.InverseBlendFactor));
            */

            RC.SetRenderState(new RenderStateSet
                {
                    AlphaBlendEnable = true,
                    BlendFactor = new float4(0.5f, 0.5f, 0.5f, 0.5f),
                    BlendOperation = BlendOperation.Add,
                    SourceBlend = Blend.BlendFactor,
                    DestinationBlend = Blend.InverseBlendFactor
                });
            RC.SetRenderState(RenderState.AlphaBlendEnable, (uint)0);
        }
예제 #18
0
        private void OnMenuButtonUp(GUIButton sender, MouseEventArgs mea)
        {
            sender.BorderWidth = 1;
            if (!IsButtonSelected(sender))
            {
                sender.ButtonColor = ColorHighlightedButton;
            }

            switch (sender.Text)
            {
                case "Diffuse Color":
                    _textShaderName = sender.Text;
                    DeselectOtherButtonsFromPanel(_panelSelectShader, sender);
                    _currentShader = _shaderDiffuseColor;
                    _paramColor = _currentShader.GetShaderParam("color");
                    break;

                case "Texture Only":
                    _textShaderName = sender.Text;
                    DeselectOtherButtonsFromPanel(_panelSelectShader, sender);
                    _currentShader = _shaderTexture;
                    _paramTexture = _currentShader.GetShaderParam("texture1");
                    break;

                case "Diffuse Texture":
                    _textShaderName = sender.Text;
                    DeselectOtherButtonsFromPanel(_panelSelectShader, sender);
                    _currentShader = _shaderDiffuseTexture;
                    _paramTexture = _currentShader.GetShaderParam("texture1");
                    break;

                case "Diffuse Bump Texture":
                    _textShaderName = sender.Text;
                    DeselectOtherButtonsFromPanel(_panelSelectShader, sender);
                    _currentShader = _shaderDiffuseBumpTexture;
                    _paramTexture = _currentShader.GetShaderParam("texture1");
                    _paramBumpTexture = _currentShader.GetShaderParam("normalTex");
                    _paramSpecular = _currentShader.GetShaderParam("specularLevel");
                    _paramShininess = _currentShader.GetShaderParam("shininess");
                    break;

                case "Specular Texture":
                    _textShaderName = sender.Text;
                    DeselectOtherButtonsFromPanel(_panelSelectShader, sender);
                    _currentShader = _shaderSpecularTexture;
                    _paramTexture = _currentShader.GetShaderParam("texture1");
                    _paramSpecular = _currentShader.GetShaderParam("specularLevel");
                    _paramShininess = _currentShader.GetShaderParam("shininess");
                    break;

                case "Toon":
                    _textShaderName = sender.Text;
                    DeselectOtherButtonsFromPanel(_panelSelectShader, sender);
                    break;

                case "Cube":
                    DeselectOtherButtonsFromPanel(_panelSelectMesh, sender);
                    SetMesh(_meshCube);
                    _currentTexture = _texCube;
                    _currentBumpTexture = _texBumpCube;
                    break;

                case "Sphere":
                    DeselectOtherButtonsFromPanel(_panelSelectMesh, sender);
                    SetMesh(_meshSphere);
                    _currentTexture = _texSphere;
                    _currentBumpTexture = _texBumpSphere;
                    break;

                case "Teapot":
                    DeselectOtherButtonsFromPanel(_panelSelectMesh, sender);
                    SetMesh(_meshTeapot);
                    _currentTexture = _texTeapot;
                    _currentBumpTexture = _texBumpTeapot;
                    break;

                case "Directional Light":
                    DeselectOtherButtonsFromPanel(_panelLightSettings, sender);
                    RC.SetLightActive(0, 1);
                    break;

                case "Point Light":
                    DeselectOtherButtonsFromPanel(_panelLightSettings, sender);
                    RC.SetLightActive(0, 2);
                    break;

                case "Spot Light":
                    DeselectOtherButtonsFromPanel(_panelLightSettings, sender);
                    RC.SetLightActive(0, 3);
                    break;
            }
        }
예제 #19
0
        // is called on startup
        public override void Init()
        {
            //TestSerialize();
            //TestDeserialize();

            // GUI initialization
            _zVal = 500;
            _guiHandler = new GUIHandler();
            _guiHandler.AttachToContext(RC);

            _guiFuseeLink = new GUIButton(6, 6, 157, 87);
            _guiFuseeLink.ButtonColor = new float4(0, 0, 0, 0);
            _guiFuseeLink.BorderColor = new float4(0, 0.6f, 0.2f, 1);
            _guiFuseeLink.BorderWidth = 0;
            _guiFuseeLink.OnGUIButtonDown += _guiFuseeLink_OnGUIButtonDown;
            _guiFuseeLink.OnGUIButtonEnter += _guiFuseeLink_OnGUIButtonEnter;
            _guiFuseeLink.OnGUIButtonLeave += _guiFuseeLink_OnGUIButtonLeave;
            _guiHandler.Add(_guiFuseeLink);

            _guiFuseeLogo = new GUIImage("Assets/FuseeLogo150.png", 10, 10, -5, 150, 80);
            _guiHandler.Add(_guiFuseeLogo);

            _guiLatoBlack = RC.LoadFont("Assets/Lato-Black.ttf", 14);
            _guiSubText = new GUIText("FUSEE 3D Scene Viewer", _guiLatoBlack, 100, 100);
            _guiSubText.TextColor = new float4(0.05f, 0.25f, 0.15f, 0.8f);
            _guiHandler.Add(_guiSubText);

            // Scene loading
            SceneContainer scene;
            var ser = new Serializer();
            using (var file = File.OpenRead(@"Assets/Model.fus"))
            {
                scene = ser.Deserialize(file, null, typeof(SceneContainer)) as SceneContainer;
            }
            _sr = new SceneRenderer(scene, "Assets");
            AdjustModelScaleOffset();
            _guiSubText.Text = "FUSEE 3D Scene";
            if (scene.Header.CreatedBy != null || scene.Header.CreationDate != null)
            {
                _guiSubText.Text += " created";
                if (scene.Header.CreatedBy != null)
                {
                    _guiSubText.Text += " by " + scene.Header.CreatedBy;
                }
                if (scene.Header.CreationDate != null)
                {
                    _guiSubText.Text += " on " + scene.Header.CreationDate;
                }
            }

            _subtextWidth = GUIText.GetTextWidth(_guiSubText.Text, _guiLatoBlack);
            _subtextHeight = GUIText.GetTextHeight(_guiSubText.Text, _guiLatoBlack);

            _sColor = MoreShaders.GetDiffuseColorShader(RC);
            RC.SetShader(_sColor);
            _colorParam = _sColor.GetShaderParam("color");
            RC.SetShaderParam(_colorParam, new float4(1, 1, 1, 1));
            RC.ClearColor = new float4(1, 1, 1, 1);
        }