public void InitShaders(RenderContext rc)
 {
     if (rc != _rc)
     {
         _rc = rc;
         _meshMap = new Dictionary<MeshContainer, Mesh>();
         _matMap = new Dictionary<MaterialContainer, ShaderEffect>();
         _curMat = null;
     }
     if (_curMat == null)
     {
         _curMat = MakeMaterial(new MaterialContainer
         {
             Diffuse = new MatChannelContainer()
             {
                 Color = new float3(0.5f, 0.5f, 0.5f)
             },
             Specular = new SpecularChannelContainer()
             {
                 Color = new float3(1, 1, 1),
                 Intensity = 0.5f,
                 Shininess = 22
             }
         });
         CurMat.AttachToContext(rc);
     }
 }
        public static ShaderEffect GetShaderEffect(RenderContext rc, ITexture baseTexture, ITexture colorMapTexture, float4 lineColor, float2 lineWidth)
        {
            EffectPassDeclaration[] epd =
            {
                new EffectPassDeclaration
                {
                    VS = VsSimpleToonPass1,
                    PS = PsSimpleToonPass1,
                    StateSet = new RenderStateSet
                    {
                        AlphaBlendEnable = false,
                        ZEnable = true
                    }
                },
                new EffectPassDeclaration
                {
                    VS = VsSimpleToonPass2,
                    PS = PsTextureToonPass2,  //The only difference to the previous shader definition
                    StateSet = new RenderStateSet
                    {
                        AlphaBlendEnable = false,
                        ZEnable = true
                    }
                }
            };

            var shaderEffect = new ShaderEffect(epd, new[]
            {
                new EffectParameterDeclaration {Name = "uLineColor", Value = lineColor},
                new EffectParameterDeclaration {Name = "texture1", Value = colorMapTexture},
                new EffectParameterDeclaration {Name = "uLineWidth", Value = lineWidth},
                new EffectParameterDeclaration {Name = "texture2", Value = baseTexture}
            });

            shaderEffect.AttachToContext(rc);

            return shaderEffect;
        }
        public static ShaderEffect GetShaderEffect(RenderContext rc, ITexture iTexture)
        {
            EffectPassDeclaration[] epd =
            {
                new EffectPassDeclaration
                {
                    VS = VsSimpleTexture,
                    PS = PsSimpleTexture,
                    StateSet = new RenderStateSet
                    {
                        AlphaBlendEnable = false,
                        ZEnable = true
                    }
                }
            };

            var shaderEffect = new ShaderEffect(epd, new[]
            {
                new EffectParameterDeclaration {Name = "texture1", Value = iTexture}
            });

            shaderEffect.AttachToContext(rc);

            return shaderEffect;
        }
        public static ShaderEffect GetShaderEffect(RenderContext rc, float4 color)
        {
            EffectPassDeclaration[] epd =
            {
                new EffectPassDeclaration
                {
                    VS = VsSimpleColor,
                    PS = PsSimpleColor,
                    StateSet = new RenderStateSet
                    {
                        AlphaBlendEnable = false,
                        ZEnable = true
                    }
                }
            };

            var shaderEffect = new ShaderEffect(epd, new[]
            {
                new EffectParameterDeclaration {Name = "color", Value = color}
            });

            shaderEffect.AttachToContext(rc);

            return shaderEffect;
        }
        public void SetShader(float4 baseColor, String colorMapTexturePath, float4 lineColor, float2 lineWidth)
        {
            var imgData = _rc.LoadImage(colorMapTexturePath);
            _iTexture1 = _rc.CreateTexture(imgData);

            _shaderEffect = Shader.GetShaderEffect(_rc, baseColor, _iTexture1, lineColor, lineWidth);
        }
        public void SetShader(String texturePath)
        {
            var imgData = _rc.LoadImage(texturePath);
            _iTexture1 = _rc.CreateTexture(imgData);

            _shaderEffect = Shader.GetShaderEffect(_rc, _iTexture1);
        }
 public void SetShader(float4 color)
 {
     _color = color;
     _shaderEffect = Shader.GetShaderEffect(_rc, _color);
 }
 protected override void CreateGUIShader()
 {
     GUIShader = new ShaderEffect(new[]
     {
         new EffectPassDeclaration
         {
             VS = GUIVS,
             PS = IMGPS,
             StateSet = new RenderStateSet
             {
                 AlphaBlendEnable = true,
                 SourceBlend = Blend.SourceAlpha,
                 DestinationBlend = Blend.InverseSourceAlpha,
                 ZEnable = true
             }
         }
     },
         new[] {new EffectParameterDeclaration {Name = "tex", Value = GUITexture}});
 }
        private void InitShader()
        {
            var imgData = RC.LoadImage("Assets/art_billard.jpg");
            var iTex = RC.CreateTexture(imgData);

            _shaderEffect = new ShaderEffect(
                new[]
                {
                    new EffectPassDeclaration
                    {
                        VS = @"
                                attribute vec4 fuColor;
                                attribute vec3 fuVertex;
                                attribute vec3 fuNormal;
                                attribute vec2 fuUV;

                                varying vec4 vColor;
                                varying vec3 vNormal;
                                varying vec2 vUV;

                                uniform mat4 FUSEE_MVP;
                                uniform mat4 FUSEE_ITMV;

                                uniform vec2 uLineWidth;

                                void main()
                                {
                                    vNormal = mat3(FUSEE_ITMV[0].xyz, FUSEE_ITMV[1].xyz, FUSEE_ITMV[2].xyz) * fuNormal;
                                    vNormal = normalize(vNormal);
                                    gl_Position = (FUSEE_MVP * vec4(fuVertex, 1.0) ) + vec4(uLineWidth * vNormal.xy, 0, 0) + vec4(0, 0, 0.06, 0);
                                    vUV = fuUV;
                                }",
                        PS = @"
                                #ifdef GL_ES
                                    precision highp float;
                                #endif

                                uniform vec4 uLineColor;
                                varying vec3 vNormal;

                                void main()
                                {
                                    gl_FragColor = uLineColor;
                                }",
                        StateSet = new RenderStateSet
                        {
                            AlphaBlendEnable = false,
                            ZEnable = true
                        }
                    },
                    new EffectPassDeclaration
                    {
                        VS = @"
                                attribute vec4 fuColor;
                                attribute vec3 fuVertex;
                                attribute vec3 fuNormal;
                                attribute vec2 fuUV;

                                varying vec3 vNormal;
                                varying vec2 vUV;

                                uniform mat4 FUSEE_MVP;
                                uniform mat4 FUSEE_ITMV;

                                void main()
                                {
                                    gl_Position = (FUSEE_MVP * vec4(fuVertex, 1.0) );
                                    vNormal = normalize(mat3(FUSEE_ITMV[0].xyz, FUSEE_ITMV[1].xyz, FUSEE_ITMV[2].xyz) * fuNormal);
                                    vUV = fuUV;
                                }",
                        PS = @"
                                #ifdef GL_ES
                                    precision highp float;
                                #endif

                                uniform sampler2D texture1;

                                varying vec3 vNormal;
                                varying vec2 vUV;

                                void main()
                                {
                                    gl_FragColor = vec4(texture2D(texture1, vNormal.xy * 0.5 + vec2(0.5, 0.5)).rgb, 0.85);
                                }",
                        StateSet = new RenderStateSet
                        {
                            AlphaBlendEnable = false,
                            ZEnable = true,
                        }
                    }
                },
                new[]
                {
                    new EffectParameterDeclaration {Name = "uLineColor", Value = new float4(0, 0, 0, 1)},
                    new EffectParameterDeclaration {Name = "texture1", Value = iTex},
                    new EffectParameterDeclaration {Name = "uLineWidth", Value = new float2(5, 5)}
                });
            _shaderEffect.AttachToContext(RC);
        }
 private void RenderWithLights(Mesh rm, ShaderEffect CurMat)
 {
     if (_lights.Count > 0)
     {
         foreach (LightInfo li in _lights)
         {
             // SetupLight(li);
             CurMat.RenderMesh(rm);
         }
     }
     else
     {
         // No light present - switch on standard light
         CurMat.SetEffectParam(ShaderCodeBuilder.LightColorName, new float3(1, 1, 1));
         // float4 lightDirHom = new float4(0, 0, -1, 0);
         float4 lightDirHom = _rc.InvModelView * new float4(0, 0, -1, 0);
         // float4 lightDirHom = _rc.TransModelView * new float4(0, 0, -1, 0);
         float3 lightDir = lightDirHom.xyz;
         lightDir.Normalize();
         CurMat.SetEffectParam(ShaderCodeBuilder.LightDirectionName, lightDir);
         CurMat.SetEffectParam(ShaderCodeBuilder.LightIntensityName, (float)1);
         CurMat.RenderMesh(rm);
     }
 }
        private ShaderEffect MakeMaterial(MaterialContainer mc)
        {
            ShaderCodeBuilder scb = new ShaderCodeBuilder(mc, null);
            var effectParameters = AssembleEffectParamers(mc, scb);

            ShaderEffect ret = new ShaderEffect(new []
                {
                    new EffectPassDeclaration()
                    {
                        VS = scb.VS,
                        PS = scb.PS,
                        StateSet = new RenderStateSet()
                        {
                            ZEnable = true,
                            AlphaBlendEnable = false
                        }
                    }
                },
                effectParameters
            );
            return ret;
        }
        protected void VisitNodeRender(SceneObjectContainer soc)
        {
            float4x4 origMV = _rc.ModelView;
            ShaderEffect origMat = CurMat;

            if (soc.Material != null)
            {
                var mat = LookupMaterial(soc.Material);
                CurMat = mat;
            }
            _rc.ModelView = _rc.ModelView * soc.Transform.Matrix();

            if (soc.Mesh != null)
            {
                Mesh rm;
                if (!_meshMap.TryGetValue(soc.Mesh, out rm))
                {
                    rm = MakeMesh(soc);
                    _meshMap.Add(soc.Mesh, rm);
                }

                if (null != CurMat.GetEffectParam(ShaderCodeBuilder.LightDirectionName))
                {
                    RenderWithLights(rm, CurMat);
                }
                else
                {
                    CurMat.RenderMesh(rm);
                }
            }

            if (soc.Children != null)
            {
                foreach (var child in soc.Children)
                {
                    VisitNodeRender(child);
                }
            }

            _rc.ModelView = origMV;
            CurMat = origMat;
        }