Пример #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="uniforms"></param>
        /// <param name="key"></param>
        /// <param name="value"></param>
        public static void SetValue(Uniforms uniforms, string key, object value)
        {
            Uniform entry = null;

            if (uniforms.TryGetValue(key, out entry))
            {
                entry["value"] = value;
            }
        }
Пример #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="original"></param>
        /// <returns></returns>
        public Uniforms Copy(Uniforms original)
        {
            var destination = new Uniforms();

            foreach (var entry in original)
            {
                destination.Add(entry.Key, new Uniform().Copy(entry.Value));
            }

            return(destination);
        }
Пример #3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="uniforms"></param>
        /// <returns></returns>
        public static Uniforms Merge(List <Uniforms> uniforms)
        {
            var merged = new Uniforms();

            foreach (var uniform in uniforms)
            {
                // var tmp = uniform.clone();

                foreach (var kvp in uniform)
                {
                    merged.Add(kvp.Key, kvp.Value);
                }
            }
            return(merged);
        }
Пример #4
0
 /// <summary>
 ///
 /// </summary>
 /// <returns></returns>
 public static object Clone(Uniforms uniforms)
 {
     return(new Uniforms().Copy(uniforms));
 }
Пример #5
0
        /// <summary>
        ///
        /// </summary>
        private Shader PhongShader()
        {
            var shader = new Shader();

            #region construct uniform variables

            var tt = new Uniforms {
                { "ambient", new Uniform()
                  {
                      { "type", "c" }, { "value", Color.White }
                  } }
            };

            shader.Uniforms =
                UniformsUtils.Merge(new List <Uniforms>
            {
                this.UniformsLib["common"],
                this.UniformsLib["bump"],
                this.UniformsLib["normalmap"],
                this.UniformsLib["fog"],
                this.UniformsLib["lights"],
                this.UniformsLib["shadowmap"],

                new Uniforms {
                    { "ambient", new Uniform()
                      {
                          { "type", "c" }, { "value", Color.White }
                      } }
                },
                new Uniforms {
                    { "emissive", new Uniform()
                      {
                          { "type", "c" }, { "value", Color.Black }
                      } }
                },
                new Uniforms {
                    { "specular", new Uniform()
                      {
                          { "type", "c" }, { "value", Color.DimGray }
                      } }
                },
                new Uniforms {
                    { "shininess", new Uniform()
                      {
                          { "type", "f" }, { "value", 30.0f }
                      } }
                },
                new Uniforms {
                    { "wrapRGB", new Uniform()
                      {
                          { "type", "v3" }, { "value", new Vector3(1, 1, 1) }
                      } }
                }
            });

            #endregion

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

            vs.Add("#define PHONG");

            vs.Add("varying vec3 vViewPosition;");
            vs.Add("varying vec3 vNormal;");

            vs.Add(this.getChunk("map_pars_vertex"));
            vs.Add(this.getChunk("lightmap_pars_vertex"));
            vs.Add(this.getChunk("envmap_pars_vertex"));
            vs.Add(this.getChunk("lights_phong_pars_vertex"));
            vs.Add(this.getChunk("color_pars_vertex"));
            vs.Add(this.getChunk("morphtarget_pars_vertex"));
            vs.Add(this.getChunk("skinning_pars_vertex"));
            vs.Add(this.getChunk("shadowmap_pars_vertex"));
            vs.Add(this.getChunk("logdepthbuf_pars_vertex"));

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

            vs.Add(this.getChunk("map_vertex"));
            vs.Add(this.getChunk("lightmap_vertex"));
            vs.Add(this.getChunk("color_vertex"));

            vs.Add(this.getChunk("morphnormal_vertex"));
            vs.Add(this.getChunk("skinbase_vertex"));
            vs.Add(this.getChunk("skinnormal_vertex"));
            vs.Add(this.getChunk("defaultnormal_vertex"));

            vs.Add("	vNormal = normalize( transformedNormal );");

            vs.Add(this.getChunk("morphtarget_vertex"));
            vs.Add(this.getChunk("skinning_vertex"));
            vs.Add(this.getChunk("default_vertex"));
            vs.Add(this.getChunk("logdepthbuf_vertex"));

            vs.Add("	vViewPosition = -mvPosition.xyz;");

            vs.Add(this.getChunk("worldpos_vertex"));
            vs.Add(this.getChunk("envmap_vertex"));
            vs.Add(this.getChunk("lights_phong_vertex"));
            vs.Add(this.getChunk("shadowmap_vertex"));

            vs.Add("}");

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

            #endregion

            #region fragmentShader

            var fs = new List <string>();

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

            fs.Add("uniform vec3 ambient;");
            fs.Add("uniform vec3 emissive;");
            fs.Add("uniform vec3 specular;");
            fs.Add("uniform float shininess;");

            fs.Add(this.getChunk("color_pars_fragment"));
            fs.Add(this.getChunk("map_pars_fragment"));
            fs.Add(this.getChunk("alphamap_pars_fragment"));
            fs.Add(this.getChunk("lightmap_pars_fragment"));
            fs.Add(this.getChunk("envmap_pars_fragment"));
            fs.Add(this.getChunk("fog_pars_fragment"));
            fs.Add(this.getChunk("lights_phong_pars_fragment"));
            fs.Add(this.getChunk("shadowmap_pars_fragment"));
            fs.Add(this.getChunk("bumpmap_pars_fragment"));
            fs.Add(this.getChunk("normalmap_pars_fragment"));
            fs.Add(this.getChunk("specularmap_pars_fragment"));
            fs.Add(this.getChunk("logdepthbuf_pars_fragment"));

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

            fs.Add("	gl_FragColor = vec4( vec3( 1.0 ), opacity );");

            fs.Add(this.getChunk("logdepthbuf_fragment"));
            fs.Add(this.getChunk("map_fragment"));
            fs.Add(this.getChunk("alphamap_fragment"));
            fs.Add(this.getChunk("alphatest_fragment"));
            fs.Add(this.getChunk("specularmap_fragment"));

            fs.Add(this.getChunk("lights_phong_fragment"));

            fs.Add(this.getChunk("lightmap_fragment"));
            fs.Add(this.getChunk("color_fragment"));
            fs.Add(this.getChunk("envmap_fragment"));
            fs.Add(this.getChunk("shadowmap_fragment"));

            fs.Add(this.getChunk("linear_to_gamma_fragment"));

            fs.Add(this.getChunk("fog_fragment"));

            fs.Add("}");

            // join
            shader.FragmentShader = String.Join("\n", fs).Trim();

            #endregion

            return(shader);
        }