Beispiel #1
0
        public static IShaderEffect Create(ShaderName name)
        {
            IShaderEffect shaderEffect;

            switch (name)
            {
            case ShaderName.Color:
                shaderEffect = new ColorShader();
                break;

            case ShaderName.Ambient:
                shaderEffect = new AmbientShader();
                break;

            case ShaderName.Diffuse:
                shaderEffect = new DiffuseLighting();
                break;

            case ShaderName.Specular:
                shaderEffect = new SpecularLighting();
                break;

            case ShaderName.Multitexture:
                shaderEffect = new Multitexturing();
                break;

            case ShaderName.Texture:
                shaderEffect = new TextureMapping();
                break;

            case ShaderName.Test:
                shaderEffect = new TestShader();
                break;

            case ShaderName.Bumpmaping:
                shaderEffect = new BumpMapping();
                break;

            case ShaderName.ParallaxMapping:
                shaderEffect = new ParallaxMapping();
                break;

            case ShaderName.LightingEffect:
                shaderEffect = new LightingShader();
                break;

            case ShaderName.DirectionalLightingParallaxMapping:
                shaderEffect = new DirectionalLightingParallax();
                break;

            case ShaderName.DepthShader:
                shaderEffect = new DepthShader();
                break;

            default:
                shaderEffect = null;
                break;
            }
            return(shaderEffect);
        }
        // This renders the sorted sector surfaces
        internal void RenderSectorSurfaces(RenderDevice graphics)
        {
            if (!resourcesunloaded)
            {
                ShaderName pass = Renderer.FullBrightness ? ShaderName.display2d_fullbright : ShaderName.display2d_normal;                 //mxd
                foreach (KeyValuePair <ImageData, List <SurfaceEntry> > imgsurfaces in surfaces)
                {
                    graphics.SetShader(pass);
                    graphics.SetTexture(imgsurfaces.Key.Texture);

                    // Go for all surfaces
                    VertexBuffer lastbuffer = null;
                    foreach (SurfaceEntry entry in imgsurfaces.Value)
                    {
                        graphics.SetUniform(UniformName.desaturation, entry.desaturation);

                        // Set the vertex buffer
                        SurfaceBufferSet set = sets[entry.numvertices];
                        if (set.buffers[entry.bufferindex] != lastbuffer)
                        {
                            lastbuffer = set.buffers[entry.bufferindex];
                            graphics.SetVertexBuffer(lastbuffer);
                        }

                        // Draw
                        graphics.Draw(PrimitiveType.TriangleList, entry.vertexoffset + (entry.numvertices * surfacevertexoffsetmul), entry.numvertices / 3);
                    }
                }
                graphics.SetUniform(UniformName.desaturation, 0.0f);
            }
        }
Beispiel #3
0
        //shader name , model type
        public static void Get(ShaderName shaderName, IShape shape)
        {
            //add to the base shapea additional stuff defined by Vector Structure

            indices = shape.Indexes;

            shaderEffect = ShaderFactory.Create(shaderName);
            modelShader  = ModelShaderFactory.Create(shaderEffect.VertexType, shape.Vertexes);

            //var model = new Modelf.Model();
            //model.LoadModel("Cube");

            //modelShader = ModelShaderFactory.Create(shaderEffect.VertexType, model.Data);
        }
Beispiel #4
0
        public static IShaderEffect Create(ShaderName name)
        {
            IShaderEffect shaderEffect;

            switch (name)
            {
                case ShaderName.Color:
                    shaderEffect = new ColorShader();
                    break;
                case ShaderName.Ambient:
                    shaderEffect = new AmbientShader();
                    break;
                case ShaderName.Diffuse:
                    shaderEffect = new DiffuseLighting();
                    break;
                case ShaderName.Specular:
                    shaderEffect = new SpecularLighting();
                    break;
                case ShaderName.Multitexture:
                    shaderEffect = new Multitexturing();
                    break;
                case ShaderName.Texture:
                    shaderEffect = new TextureMapping();
                    break;
                case ShaderName.Test:
                    shaderEffect = new TestShader();
                    break;
                case ShaderName.Bumpmaping:
                    shaderEffect = new BumpMapping();
                    break;
                case ShaderName.ParallaxMapping:
                    shaderEffect = new ParallaxMapping();
                    break;
                case ShaderName.LightingEffect:
                    shaderEffect = new LightingShader();
                    break;
                case ShaderName.DirectionalLightingParallaxMapping:
                    shaderEffect = new DirectionalLightingParallax();
                    break;
                case ShaderName.DepthShader:
                    shaderEffect = new DepthShader();
                    break;
                default:
                    shaderEffect = null;
                    break;
            }
            return shaderEffect;
        }
Beispiel #5
0
        public Bitmap(Device device, IShaderEffect shaderEffect, ShaderName shader, SystemConfiguration winCfg, Vector2 bitmapDimensions)
        {
            screenHeight = winCfg.Height;
            screenWidth  = winCfg.Width;
            bitmapWidth  = bitmapDimensions.X;
            bitmapHeight = bitmapDimensions.Y;

            previousLocation.X = -1;
            previousLocation.Y = -1;

            this.device = device;

            InitializeBuffers();

            //loadTexture
            //new D3DShader();
        }
        public void CompileShader(ShaderName internalName, string groupName, string shaderName)
        {
            ShaderGroup sg;

            if (precompiledGroups.ContainsKey(groupName))
            {
                sg = precompiledGroups[groupName];
            }
            else
            {
                sg = ShaderCompiler.Compile(GetResourceText(groupName));
            }

            Shader s = sg.GetShader(shaderName);

            if (s == null)
            {
                throw new RenderDeviceException(string.Format("Shader {0}::{1} not found", groupName, shaderName));
            }

            /*General.WriteLogLine(string.Format("===========================================\nDBG: loading shader {0} / {1}\n\nVertex source: {2}\n\nFragment source: {3}\n\n===========================================",
             *  groupName, shaderName, s.GetVertexSource(), s.GetFragmentSource()));*/
            RenderDevice_DeclareShader(Handle, internalName, internalName.ToString(), s.GetVertexSource(), s.GetFragmentSource());
        }
        public D3DGraphic(SystemConfiguration windowConfig)
        {
            this.windowConfig = windowConfig;

            ShaderName shaderName = ShaderName.Texture;
            IShape     shape      = new Box2();

            ModelShader.Get(shaderName, shape);

            d3d    = new D3D11(windowConfig);
            camera = new Camera();

            model = new Bitmap(d3d.Device, ModelShader.GetShaderEffect, shaderName, this.windowConfig, new Vector2(256, 256));

            //model = new D3DModel(d3d.Device, ModelShader.GetModelForRender, ModelShader.GetIndexes);
            shader = new D3DShader(d3d.Device, ModelShader.GetShaderEffect, shaderName);

            graph.Add(d3d);
            graph.Add(model);
            graph.Add(shader);

            //camera.Position = new Vector3(-2, 1, -3);
            camera.Position = new Vector3(0.0f, 0.0f, -10.0f);
        }
 static extern bool RenderDevice_SetShader(IntPtr handle, ShaderName name);
 static extern void RenderDevice_DeclareShader(IntPtr handle, ShaderName index, string name, string vertexShader, string fragShader);
 public void SetShader(ShaderName shader)
 {
     RenderDevice_SetShader(Handle, shader);
 }
 public void DeclareShader(ShaderName name, string vertResourceName, string fragResourceName)
 {
     RenderDevice_DeclareShader(Handle, name, name.ToString(), GetResourceText(vertResourceName), GetResourceText(fragResourceName));
 }
Beispiel #12
0
 public void Add(ShaderName name, string vertexFilePath, string geometryShaderFilePath, string fragmentFilePath)
 {
     shaders.AddResource(name, vertexFilePath, geometryShaderFilePath, fragmentFilePath);
 }
Beispiel #13
0
 public Shader Get(ShaderName name)
 {
     return(shaders.GetResource(name));
 }
 public virtual GUID ShaderNameToGUID(ShaderName shaderName)
 {
     return(shaderList[shaderName]);
 }
Beispiel #15
0
        public D3DShader(Device device, IShaderEffect shaderEffect, ShaderName shader)
        {
            this.device = device;
            this.shader = shader;

            try
            {
                vertexShaderByteCode = ShaderBytecode.CompileFromFile(shaderEffect.EffectShaderFileName, shaderEffect.VsFunctionName, shaderEffect.VsVersion.ToString());
            }
            catch (Exception ex)
            {
                throw new Exception("vertexShaderByteCode: " + ex);
            }
            try
            {
                pixelShaderByteCode = ShaderBytecode.CompileFromFile(shaderEffect.EffectShaderFileName, shaderEffect.PsFunctionName, shaderEffect.PsVersion.ToString());
            }
            catch (Exception ex)
            {
                throw new Exception("vertexShaderByteCode: " + ex);
            }

            try
            {
                vertexShader = new VertexShader(device, vertexShaderByteCode);
            }
            catch (Exception ex)
            {
                throw new Exception("vertexShader: " + ex);
            }

            try
            {
                pixelShader = new PixelShader(device, pixelShaderByteCode);
            }
            catch (Exception ex)
            {
                throw new Exception("pixelShader: " + ex);
            }

            // Now setup the layout of the data that goes into the shader.
            // It needs to match the VertexType structure in the Model and in the shader.
            InputElement[] inputElementDesc = InputLayoutFactory.Create(shaderEffect.VertexType);

            CreateInputLayout(inputElementDesc);

            vertexShaderByteCode.Dispose();
            pixelShaderByteCode.Dispose();

            constantMatrixBuffer = GetConstantMatrixBuffer <BufferTypes.WorldViewProj>(device);

            //is there any differnece between loading one shader wih multiple effects
            //and more shaders with only one effect?
            if (shader != ShaderName.Color)
            {
                LoadTextureShader();
            }

            //shader.GetPerObjectBufferType<DiffuseLightBufferType>

            if (shader == ShaderName.ParallaxMapping || shader == ShaderName.Diffuse || shader == ShaderName.Bumpmaping || shader == ShaderName.LightingEffect)
            {
                constantLightBuffer = GetConstantMatrixBuffer <BufferTypes.DiffuseLightBufferType>(device);
            }
            if (shader == ShaderName.Ambient)
            {
                constantLightBuffer = GetConstantMatrixBuffer <BufferTypes.AmbientLightBufferType>(device);
            }
            if (shader == ShaderName.Specular || shader == ShaderName.DirectionalLightingParallaxMapping)
            {
                constantLightBuffer = GetConstantMatrixBuffer <BufferTypes.SpecularLightBufferType>(device);
            }

            if (shader == ShaderName.ParallaxMapping || shader == ShaderName.Bumpmaping || shader == ShaderName.Specular || shader == ShaderName.ParallaxMapping || shader == ShaderName.DirectionalLightingParallaxMapping)
            {
                constantCameraBuffer = GetConstantMatrixBuffer <BufferTypes.CameraBufferType>(device);
            }
        }
 public override string ToString()
 {
     return(ShaderName.ToString());
 }