Exemplo n.º 1
0
        public void RenderBeforeChildren(RenderEventArgs arg, LightBase light)
        {
            ICamera camera     = arg.Camera;
            mat4    projection = camera.GetProjectionMatrix();
            mat4    view       = camera.GetViewMatrix();
            mat4    model      = this.GetModelMatrix();

            RenderMethod  method  = this.RenderUnit.Methods[1];
            ShaderProgram program = method.Program;

            // matrix.
            program.SetUniform("mvpMat", projection * view * model);
            //program.SetUniform("projectionMat", projection);
            //program.SetUniform("viewMat", view);
            program.SetUniform("modelMat", model);
            program.SetUniform("normalMat", glm.transpose(glm.inverse(model)));
            // light info.
            light.SetBlinnPhongUniforms(program);
            // material.
            program.SetUniform("material.diffuse", this.Color);
            program.SetUniform("material.specular", this.Color);
            program.SetUniform("material.shiness", this.Shiness);
            // eye pos.
            program.SetUniform("eyePos", camera.Position); // camera's position in world space.
            // use blinn phong or not?
            program.SetUniform("blinn", this.BlinnPhong);

            method.Render();
        }
Exemplo n.º 2
0
        /// <summary>
        /// Creates a <see cref="LightPositionNode"/> which displays and updates light's position.
        /// </summary>
        /// <param name="light"></param>
        /// <param name="initAngle"></param>
        /// <returns></returns>
        public static LightPositionNode Create(CSharpGL.LightBase light, float initAngle = 0)
        {
            var model    = new Sphere(0.3f, 2, 3);
            var vs       = new VertexShader(vertexCode);
            var fs       = new FragmentShader(fragmentCode);
            var provider = new ShaderArray(vs, fs);
            var map      = new AttributeMap();

            map.Add(inPosition, Sphere.strPosition);
            var builder = new RenderMethodBuilder(provider, map, new PolygonModeSwitch(PolygonMode.Line));
            var node    = new LightPositionNode(model, Sphere.strPosition, builder);

            node.Initialize();
            node.light         = light;
            node.RotationAngle = initAngle;

            return(node);
        }
Exemplo n.º 3
0
        public void CastShadow(ShadowMappingCastShadowEventArgs arg)
        {
            if (!this.IsInitialized)
            {
                this.Initialize();
            }

            LightBase light      = arg.Light;
            mat4      projection = light.GetProjectionMatrix();
            mat4      view       = light.GetViewMatrix();
            mat4      model      = this.GetModelMatrix();

            var           method  = this.RenderUnit.Methods[0]; // shadowmapBuilder
            ShaderProgram program = method.Program;

            program.SetUniform(mvpMatrix, projection * view * model);

            method.Render();
        }
 /// <summary>
 ///
 /// </summary>
 /// <param name="light"></param>
 /// <returns></returns>
 public static mat4 GetViewMatrix(this LightBase light)
 {
     if (light is TSpotLight)
     {
         return(GetViewMatrix(light as TSpotLight));
     }
     else if (light is DirectionalLight)
     {
         return(GetViewMatrix(light as DirectionalLight));
     }
     else if (light is SpotLight)
     {
         return(GetViewMatrix(light as SpotLight));
     }
     else
     {
         throw new System.Exception(string.Format("Not expected light type:[{0}].", light.GetType()));
     }
 }
Exemplo n.º 5
0
        private void LightTheScene(LightBase light, Scene scene, ActionParams param)
        {
            // cast shadow from specified light.
            {
                this.lightEquipment.Begin(param.Viewport);

                var arg = new ShadowMappingCastShadowEventArgs(light);
                //this.colorMask.On();
                CastShadow(scene.RootNode, arg);
                //this.colorMask.Off();
                this.lightEquipment.End();
            }

            // light up the scene with specified light.
            {
                var arg = new ShadowMappingUnderLightEventArgs(param, scene.Camera, this.lightEquipment.BindingTexture, light);
                this.blend.On();
                RenderUnderLight(this.scene.RootNode, arg);
                this.blend.Off();
            }
        }
 // lightUpRoutine:
 // 0: PointLight;  1: DirectionalLight;
 // 2: SpotLight;
 // 3: XSpotLight;  4: NXSpotLight;
 // 5: YSpotLight;  6: NYSpotLight;
 // 7: ZSpotLight;  8: NZSpotLight;
 /// <summary>
 ///
 /// </summary>
 /// <param name="light"></param>
 /// <param name="program"></param>
 public static void SetBlinnPhongUniforms(this LightBase light, ShaderProgram program)
 {
     if (light is PointLight)
     {
         SetUniforms(light as PointLight, program);
     }
     else if (light is DirectionalLight)
     {
         SetUniforms(light as DirectionalLight, program);
     }
     else if (light is SpotLight)
     {
         SetUniforms(light as SpotLight, program);
     }
     else if (light is TSpotLight)
     {
         SetUniforms(light as TSpotLight, program);
     }
     else
     {
         throw new System.Exception(string.Format("Not expected light type:[{0}].", light.GetType()));
     }
 }
Exemplo n.º 7
0
 public void RenderAfterChildren(RenderEventArgs arg, LightBase light)
 {
 }
Exemplo n.º 8
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ShadowMappingCastShadowEventArgs"/> class.
 /// </summary>
 public ShadowMappingCastShadowEventArgs(LightBase light)
 {
     this.Light = light;
 }
Exemplo n.º 9
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ShadowMappingUnderLightEventArgs"/> class.
 /// </summary>
 public ShadowMappingUnderLightEventArgs(ActionParams param, ICamera camera, Texture shadowMap, LightBase light)
     : base(param, camera)
 {
     this.ShadowMap = shadowMap;
     this.Light     = light;
 }
Exemplo n.º 10
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="sceneNodeBase"></param>
        /// <param name="arg"></param>
        /// <param name="light"></param>
        private static void RenderBlinnPhong(SceneNodeBase sceneNodeBase, RenderEventArgs arg, LightBase light)
        {
            if (sceneNodeBase != null)
            {
                var        node     = sceneNodeBase as IBlinnPhong;
                ThreeFlags flags    = (node != null) ? node.EnableRendering : ThreeFlags.None;
                bool       before   = (node != null) && ((flags & ThreeFlags.BeforeChildren) == ThreeFlags.BeforeChildren);
                bool       children = (node == null) || ((flags & ThreeFlags.Children) == ThreeFlags.Children);
                bool       after    = (node != null) && ((flags & ThreeFlags.AfterChildren) == ThreeFlags.AfterChildren);

                if (before)
                {
                    node.RenderBeforeChildren(arg, light);
                }

                if (children)
                {
                    foreach (var item in sceneNodeBase.Children)
                    {
                        RenderBlinnPhong(item, arg, light);
                    }
                }

                if (after)
                {
                    node.RenderAfterChildren(arg, light);
                }
            }
        }
Exemplo n.º 11
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="param"></param>
 /// <param name="camera"></param>
 /// <param name="light"></param>
 public ShadowVolumeExtrudeEventArgs(ActionParams param, ICamera camera, LightBase light)
     : base(param, camera)
 {
     this.Light = light;
 }
Exemplo n.º 12
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ShadowMappingCastShadowEventArgs"/> class.
 /// </summary>
 /// <param name="param"></param>
 /// <param name="camera"></param>
 /// <param name="light"></param>
 public ShadowMappingCastShadowEventArgs(ActionParams param, ICamera camera, LightBase light)
     : base(param, camera)
 {
     this.Light = light;
 }