public EffectDirectionalLightVariable(EffectVariable structureVar)
        {
            _StructureVariable = structureVar;

            _DirectionMember = structureVar.GetMemberByName("Direction").AsVector();
            _DiffuseMember = structureVar.GetMemberByName("Diffuse").AsVector();
            _SpecularMember = structureVar.GetMemberByName("Specular").AsVector();
        }
예제 #2
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();
        }
예제 #3
0
        public DrawingManager(DeviceManager deviceManager)
        {
            _device = deviceManager.Device;
            _context = deviceManager.Context;
            _vertexLayouts = deviceManager.VertexLayouts;

            var effect = deviceManager.Effect;

            _standardSmooth = effect.GetTechniqueByName("Standard|Smooth");
            _standardFlat = effect.GetTechniqueByName("Standard|Flat");
            _standardWireframe = effect.GetTechniqueByName("Standard|Wireframe");
            _prelitSmooth = effect.GetTechniqueByName("Prelit|Smooth");
            _prelitFlat = effect.GetTechniqueByName("Prelit|Flat");
            _prelitWireframe = effect.GetTechniqueByName("Prelit|Wireframe");

            _worldMatrix = effect.GetVariableByName("g_WorldMatrix").AsMatrix();
            _postWorldMatrix = effect.GetVariableByName("g_PostWorldMatrix").AsMatrix();
            _viewMatrix = effect.GetVariableByName("g_ViewMatrix").AsMatrix();
            _projectionMatrix = effect.GetVariableByName("g_ProjectionMatrix").AsMatrix();
            _color = effect.GetVariableByName("g_Color").AsVector();
            _opacity = effect.GetVariableByName("g_Opacity").AsScalar();
            _ambient = effect.GetVariableByName("g_Ambient").AsScalar();
            _diffuse = effect.GetVariableByName("g_Diffuse").AsScalar();
            _texture = effect.GetVariableByName("g_Texture").AsShaderResource();
            _mask = effect.GetVariableByName("g_Mask").AsShaderResource();
            _textureSampler = effect.GetVariableByName("g_TextureSampler").AsSampler();
            _hasTexture = effect.GetVariableByName("g_HasTexture").AsScalar();
            _hasMask = effect.GetVariableByName("g_HasMask").AsScalar();
            _isInstanced = effect.GetVariableByName("g_IsInstanced").AsScalar();
            _isColorTinted = effect.GetVariableByName("g_IsColorTinted").AsScalar();
            _globalLight = effect.GetVariableByName("g_GlobalLight");
            _lightViewProjectionMatrix = effect.GetVariableByName("g_LightViewProjectionMatrix").AsMatrix();

            //Set the states to Unknown initially.
            _currentDrawingState = DrawingState.Unknown;
            _currentTopologyState = PrimitiveTopologyState.Unknown;

            //Set the default of the g_PostWorldMatrix to Identity, so it isn't required to be set.
            _postWorldMatrix.SetMatrix(Matrix.Identity);

            //Setup shadow map technique.
            var shadowEffect = deviceManager.ShadowEffect;
            _shadowMapStandard = shadowEffect.GetTechniqueByName("ShadowMapTechnique|Standard");
            _shadowMapPrelit = shadowEffect.GetTechniqueByName("ShadowMapTechnique|Prelit");

            _isShadowInstanced = shadowEffect.GetVariableByName("g_IsInstanced").AsScalar();
            _shadowWorldMatrix = shadowEffect.GetVariableByName("g_WorldMatrix").AsMatrix();
            _shadowHasMask = shadowEffect.GetVariableByName("g_HasMask").AsScalar();
            _shadowMask = shadowEffect.GetVariableByName("g_Mask").AsShaderResource();
            _shadowLightViewProjectionMatrix = shadowEffect.GetVariableByName("g_LightViewProjectionMatrix").AsMatrix();
        }
예제 #4
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";
        }