예제 #1
0
        private void BuildFX()
        {
            SharpDX.D3DCompiler.ShaderBytecode compiledShader = null;
            try
            {
                compiledShader = new SharpDX.D3DCompiler.ShaderBytecode(System.IO.File.ReadAllBytes("fx/lighting.fxo"));
                _fx            = new D3D11.Effect(Device, compiledShader);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                return;
            }
            finally
            {
                Util.ReleaseCom(ref compiledShader);
            }

            _tech                     = _fx.GetTechniqueByName("LightTech");
            _fxWVP                    = _fx.GetVariableByName("gWorldViewProj").AsMatrix();
            _fxWorld                  = _fx.GetVariableByName("gWorld").AsMatrix();
            _fxWIT                    = _fx.GetVariableByName("gWorldInvTranspose").AsMatrix();
            _fxEyePosW                = _fx.GetVariableByName("gEyePosW").AsVector();
            _fxDirLight               = _fx.GetVariableByName("gDirLight");
            _fxPointLight             = _fx.GetVariableByName("gPointLight");
            _fxSpotLight              = _fx.GetVariableByName("gSpotLight");
            _fxMaterial               = _fx.GetVariableByName("gMaterial");
            _fxDiffuseMap             = _fx.GetVariableByName("gDiffuseMap").AsShaderResource();
            _fxRefractiveMap          = _fx.GetVariableByName("gRefractiveMap").AsShaderResource();
            _fxClipPlane              = _fx.GetVariableByName("gClipPlane").AsVector();
            _fxReflectViewProj        = _fx.GetVariableByName("gReflectViewProj").AsMatrix();
            _fxReflectiveMap          = _fx.GetVariableByName("gReflectiveMap").AsShaderResource();
            _fxgRefractionPositionMap = _fx.GetVariableByName("gRefractionPositionMap").AsShaderResource();
            _fxUseStructBuf           = _fx.GetVariableByName("gUseStructBuf").AsScalar();
            _fxSolutionSR             = _fx.GetVariableByName("gSolution").AsShaderResource();
        }
예제 #2
0
        public WavesSimulator(IntPtr hInst)
            : base(hInst)
        {
            //Geometry Related Buffers
            _ballIB   = null;
            _ballVB   = null;
            _groundVB = null;
            _groundIB = null;
            _wavesVB  = null;
            _wavesIB  = null;


            _ballIndexCount   = 0;
            _groundIndexCount = 0;

            //WVP Matrices
            _groundWorld = Matrix.Identity;
            _wavesWorld  = Matrix.Translation(0, -2.0f, 0);
            _ballWorld   = Matrix.Translation(-30, 15, 0);
            _view        = Matrix.Identity;
            _proj        = Matrix.Identity;
            _reflectView = Matrix.Identity;

            //Rendering Effects Related
            _fx                       = null;
            _fxWVP                    = null;
            _tech                     = null;
            _fxWorld                  = null;
            _fxWIT                    = null;
            _fxEyePosW                = null;
            _fxDirLight               = null;
            _fxPointLight             = null;
            _fxSpotLight              = null;
            _fxMaterial               = null;
            _fxDiffuseMap             = null;
            _fxRefractiveMap          = null;
            _fxClipPlane              = null;
            _fxReflectiveMap          = null;
            _fxReflectViewProj        = null;
            _fxUseStructBuf           = null;
            _fxgRefractionPositionMap = null;

            //Textures and Views
            refractText             = null;
            refractRenderTargetView = null;
            refractResourceView     = null;

            reflectRenderTargetView = null;
            reflectResourceView     = null;
            reflectText             = null;

            positionMapRenderTargetView = null;
            positionMapResourceView     = null;
            positionMapText             = null;

            _groundMapSRV = null;
            _groundMap    = null;

            //Input Format
            _inputLayout = null;


            //Camera Related
            _theta        = 1.5f * MathF.PI;
            _phi          = 0.1f * MathF.PI;
            _radius       = 200.0f;
            _lastMousePos = new System.Drawing.Point(0, 0);
            _eyePosW      = new Vector3();


            //Shading and Lighting
            _alphaBlend = null;

            _dirLight = new DirectionalLight
            {
                Ambient   = new Color4(0.2f, 0.2f, 0.2f, 1),
                Diffuse   = new Color4(0.5f, 0.5f, 0.5f, 1),
                Specular  = new Color4(0.5f, 0.5f, 0.5f, 1),
                Direction = new Vector3(0.57735f, -0.57735f, 0.57735f)
            };

            _pointLight = new PointLight
            {
                Ambient     = new Color4(0.3f, 0.3f, 0.3f, 1),
                Diffuse     = new Color4(0.7f, 0.7f, 0.7f, 1),
                Specular    = new Color4(0.7f, 0.7f, 0.7f, 1),
                Attenuation = new Vector3(0.1f, 0.1f, 0.1f),
                Range       = 25.0f
            };
            _spotLight = new SpotLight
            {
                Ambient     = new Color4(0, 0, 0, 0),
                Diffuse     = new Color4(1.0f, 1.0f, 1.0f, 1),
                Specular    = Color.White,
                Attenuation = new Vector3(1.0f, 0.0f, 0.0f),
                Spot        = 96.0f,
                Range       = 10000.0f
            };


            _landMaterial = new Material
            {
                Ambient  = new Color4(1f, 1f, 1f, 1.0f),
                Diffuse  = new Color4(1, 1, 1, 1.0f),
                Specular = new Color4(0.2f, 0.2f, 0.2f, 16.0f),
                Reflect  = new Color4(1.0f, 1f, 1f, 1f)
            };
            _wavesMaterial = new Material
            {
                Ambient  = new Color4(1, 1, 1, 0.8f),
                Diffuse  = new Color4(0.137f, 0.42f, 0.556f, 1.0f),
                Specular = new Color4(0.8f, 0.8f, 0.8f, 96.0f),
                Reflect  = new Color4(2f, 1, 1, 1) //R component of Reflect is used for Gama Correction in Effect
            };


            _disposed         = false;
            MainWindowCaption = "Waves Simulator";
        }