Example #1
0
        private void CreateDevice()
        {
            //Tell the API were the folder containing the shader's code are ,and the ShaderModel
            ShaderRepository.SetupD3D10_SM40("Shaders");

            //Instantiate GraphicDeviceFactory in this case we are using Direct3D10 so an instance of GraphicManager10 is required
            var devFactory = new IgneelD3D10.GraphicManager10();

            //Create de GraphicDevice passsing a GraphicDeviceDesc containing device configuration and
            //and the rendering environment. In this case we use the WindowContext because this is a WindowsForms application
            device = devFactory.CreateDevice(new GraphicDeviceDesc(new WindowContext(Handle)
            {
                BackBufferWidth    = Width,
                BackBufferHeight   = Height,
                BackBufferFormat   = Format.R8G8B8A8_UNORM_SRGB,
                DepthStencilFormat = Format.D24_UNORM_S8_UINT,
                FullScreen         = false,
                Sampling           = new Multisampling(1, 0),
                Presentation       = PresentionInterval.Default
            }
                                                                   ));

            //Creates a ShaderProgram passsing the files containing the shader's code for the VertexShader and PixelShader stages
            shaderProgram = device.CreateProgram <TriangleVertex>("VertexShaderVS", "PixelShaderPS");

            //Retrieve a type safe mapping for setting the uniforms variables
            input = shaderProgram.Map <ProgramMapping>();

            //Set pipeline states
            blendState       = device.CreateBlendState(new BlendDesc(blendEnable: false, srcBlend: Blend.SourceAlpha, destBlend: Blend.InverseSourceAlpha));
            depthStenciState = device.CreateDepthStencilState(new DepthStencilStateDesc(depthFunc: Comparison.Less));
            cullingState     = device.CreateRasterizerState(new RasterizerDesc(cull: CullMode.Back));

            device.Blend      = blendState;
            device.Rasterizer = cullingState;
            device.DepthTest  = depthStenciState;
        }
Example #2
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();
        }