示例#1
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="shader"></param>
        /// <param name="textureId"></param>
        public ShaderPass(WebGlShader shader, string textureId = "tDiffuse")
        {
            this.TextureId = textureId;

            this.Uniforms = (Uniforms)UniformsUtils.Clone(shader.Uniforms);

            this.Material = new ShaderMaterial()
            {
                Uniforms       = this.Uniforms,
                VertexShader   = shader.VertexShader,
                FragmentShader = shader.FragmentShader
            };

            this.RenderToScreen = false;

            this.Enabled   = true;
            this.NeedsSwap = true;
            this.Clear     = false;


            this.camera = new OrthographicCamera(-1, 1, 1, -1, 0, 1);
            this.scene  = new Scene();

            this.quad = new Mesh(new PlaneBufferGeometry(2, 2), null);
            this.scene.Add(this.quad);
        }
示例#2
0
        /// <summary>
        /// Constructor
        /// </summary>
        public CopyShader()
        {
            #region construct uniform variables

            this.Uniforms =
                UniformsUtils.Merge(new List <Uniforms>
            {
                new Uniforms {
                    { "tDiffuse", new Uniform()
                      {
                          { "type", "t" }, { "value", null }
                      } }
                },
                new Uniforms {
                    { "opacity", new Uniform()
                      {
                          { "type", "f" }, { "value", 1.0f }
                      } }
                }
            });
            #endregion

            #region construct VertexShader
            var vs = new List <string>();

            vs.Add("varying vec2 vUv;");

            vs.Add("void main() {");

            vs.Add("vUv = uv;");
            vs.Add("gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );");

            vs.Add("}");

            // join
            this.VertexShader = String.Join("\n", vs).Trim();
            #endregion

            #region construct FragmentShader
            var fs = new List <string>();

            fs.Add("uniform float opacity;");

            fs.Add("uniform sampler2D tDiffuse;");

            fs.Add("varying vec2 vUv;");

            fs.Add("void main() {");

            fs.Add("vec4 texel = texture2D( tDiffuse, vUv );");
            fs.Add("gl_FragColor = opacity * texel;");

            fs.Add("}");

            // join
            this.FragmentShader = String.Join("\n", fs).Trim();
            #endregion
        }
示例#3
0
        /// <summary>
        /// Constructor
        /// </summary>
        public RGBShiftShader()
        {
            #region construct uniform variables

            this.Uniforms =
                UniformsUtils.Merge(new List <Uniforms>
            {
                new Uniforms {
                    { "tDiffuse", new Uniform()
                      {
                          { "type", "t" }, { "value", null }
                      } }
                },
                new Uniforms {
                    { "amount", new Uniform()
                      {
                          { "type", "f" }, { "value", 0.005f }
                      } }
                },
                new Uniforms {
                    { "angle", new Uniform()
                      {
                          { "type", "f" }, { "value", 1.0f }
                      } }
                }
            });
            #endregion

            #region construct VertexShader
            var vs = new List <string>();

            vs.Add("varying vec2 vUv;");

            vs.Add("void main() {");

            vs.Add("vUv = uv;");
            vs.Add("gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );");

            vs.Add("}");

            // join
            this.VertexShader = String.Join("\n", vs).Trim();
            #endregion

            #region construct FragmentShader
            var fs = new List <string>();

            fs.Add("uniform sampler2D tDiffuse;");
            fs.Add("uniform float amount;");
            fs.Add("uniform float angle;");

            fs.Add("varying vec2 vUv;");

            fs.Add("void main() {");

            fs.Add("vec2 offset = amount * vec2( cos(angle), sin(angle));");
            fs.Add("vec4 cr = texture2D(tDiffuse, vUv + offset);");
            fs.Add("vec4 cga = texture2D(tDiffuse, vUv);");
            fs.Add("vec4 cb = texture2D(tDiffuse, vUv - offset);");
            fs.Add("gl_FragColor = vec4(cr.r, cga.g, cb.b, cga.a);");

            fs.Add("}");

            // join
            this.FragmentShader = String.Join("\n", fs).Trim();
            #endregion
        }
示例#4
0
        /// <summary>
        /// Constructor
        /// </summary>
        public DotScreenShader()
        {
            #region construct uniform variables

            this.Uniforms =
                UniformsUtils.Merge(new List <Uniforms>
            {
                new Uniforms {
                    { "tDiffuse", new Uniform()
                      {
                          { "type", "t" }, { "value", null }
                      } }
                },
                new Uniforms {
                    { "tSize", new Uniform()
                      {
                          { "type", "v2" }, { "value", new Vector2(256, 256) }
                      } }
                },
                new Uniforms {
                    { "center", new Uniform()
                      {
                          { "type", "v2" }, { "value", new Vector2(0.5f, 0.5f) }
                      } }
                },
                new Uniforms {
                    { "angle", new Uniform()
                      {
                          { "type", "f" }, { "value", 1.57f }
                      } }
                },
                new Uniforms {
                    { "scale", new Uniform()
                      {
                          { "type", "f" }, { "value", 1.0f }
                      } }
                }
            });
            #endregion

            #region construct VertexShader
            var vs = new List <string>();

            vs.Add("varying vec2 vUv;");

            vs.Add("void main() {");

            vs.Add("vUv = uv;");
            vs.Add("gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );");

            vs.Add("}");

            // join
            this.VertexShader = String.Join("\n", vs).Trim();
            #endregion

            #region construct FragmentShader
            var fs = new List <string>();

            fs.Add("uniform vec2 center;");
            fs.Add("uniform float angle;");
            fs.Add("uniform float scale;");
            fs.Add("uniform vec2 tSize;");

            fs.Add("uniform sampler2D tDiffuse;");

            fs.Add("varying vec2 vUv;");

            fs.Add("float pattern() {");

            fs.Add("float s = sin( angle ), c = cos( angle );");

            fs.Add("vec2 tex = vUv * tSize - center;");
            fs.Add("vec2 point = vec2( c * tex.x - s * tex.y, s * tex.x + c * tex.y ) * scale;");

            fs.Add("return ( sin( point.x ) * sin( point.y ) ) * 4.0;");

            fs.Add("}");

            fs.Add("void main() {");

            fs.Add("vec4 color = texture2D( tDiffuse, vUv );");
            fs.Add("float average = ( color.r + color.g + color.b ) / 3.0;");
            fs.Add("gl_FragColor = vec4( vec3( average * 10.0 - 5.0 + pattern() ), color.a );");

            fs.Add("}");

            // join
            this.FragmentShader = String.Join("\n", fs).Trim();
            #endregion
        }