Пример #1
0
        private void Init()
        {
            //Setup shader model version and default compiling options,
            //also set the relative directory where the shaders are located
            ShaderRepository.SetupD3D10_SM40("Shaders");

            //Create an instance of the GraphicDeviceFactory.
            //The GraphicDeviceFactory abstract class is used to creates GraphicDevices without worrying about the native implementation.
            //This sample use a Direc3D10 native implementation, therefore an instance of a GraphicManager10 is created
            GraphicDeviceFactory devFactory = new IgneelD3D10.GraphicManager10();

            //A GraphicDevice is created using a WindowContext containing rendering and display settings.
            device = devFactory.CreateDevice(new WindowContext(Handle)
            {
                BackBufferWidth    = Width,
                BackBufferHeight   = Height,
                BackBufferFormat   = Format.R8G8B8A8_UNORM,
                DepthStencilFormat = Format.D24_UNORM_S8_UINT,
                FullScreen         = false,
                Sampling           = new Multisampling(1, 0),
                Presentation       = PresentionInterval.Default
            });

            //Create a ShaderProgram using the input layout definition provided by the SphereVertex struct
            //and the code for the vertex and pixel shaders located in the VertexShaderVS and PixelShaderPS files.
            //As a convention the last 2 characters in the filename specify the type of shader to load.
            shaderProgram = device.CreateProgram <SphereVertex>("VertexShaderVS", "PixelShaderPS");

            //Get a typed mapping using the ProgramMapping interface for the ShaderProgram uniform variables and textures
            input = shaderProgram.Map <ProgramMapping>();

            //The application blending state allowing transparency blend
            device.Blend = device.CreateBlendState(new BlendDesc(
                                                       blendEnable: true,
                                                       srcBlend: Blend.SourceAlpha,
                                                       destBlend: Blend.InverseSourceAlpha));

            //The application depth testing state
            device.DepthTest = device.CreateDepthStencilState(new DepthStencilStateDesc(
                                                                  depthFunc: Comparison.Less));

            //The application rasterizer state
            device.Rasterizer = device.CreateRasterizerState(new RasterizerDesc(
                                                                 cull: CullMode.Back,
                                                                 fill: FillMode.Solid));

            //Default texture sampling settings
            diffuseSampler = device.CreateSamplerState(new SamplerDesc(
                                                           addressU: TextureAddressMode.Wrap,
                                                           addressV: TextureAddressMode.Wrap,
                                                           filter: Filter.MinPointMagMipLinear));

            //Load the textures
            diffuseTexture   = device.CreateTexture2DFromFile("Textures/Earth_Diffuse.dds");
            nightTexture     = device.CreateTexture2DFromFile("Textures/Earth_Night.dds");
            normalMapTexture = device.CreateTexture2DFromFile("Textures/Earth_NormalMap.dds");
            reflectionMask   = device.CreateTexture2DFromFile("Textures/Earth_ReflectionMask.dds");

            //Create transformation matrices
            world      = Matrix.Identity;
            view       = Matrix.LookAt(cameraPosition, new Vector3(0, 0, 1), Vector3.UnitY);
            projection = Matrix.PerspectiveFovLh((float)Width / (float)Height, Igneel.Numerics.PIover6, 1, 1000);

            CreateSphere();
        }