Пример #1
0
 public override void Update()
 {
     normalMapTex = normalMapRenderer.NormalMap;
     if (colorTexture != null)
     {
         Texture.ActiveTextureSlot(0);
         colorTexture.Use();
         shader.SetUniform("u_texture", 0);
     }
     if (depthTexture != null)
     {
         Texture.ActiveTextureSlot(1);
         depthTexture.Use();
         shader.SetUniform("u_depthTexture", 1);
     }
     if (normalMapTex != null)
     {
         Texture.ActiveTextureSlot(2);
         normalMapTex.Use();
         shader.SetUniform("u_normalTexture", 2);
     }
     shader.SetUniform("u_viewMatrix", cam.ViewMatrix);
     shader.SetUniform("u_projectionMatrix", cam.ProjectionMatrix);
     shader.SetUniform("u_cameraPosition", cam.Translation);
     shader.SetUniform("u_near", cam.Near);
     shader.SetUniform("u_far", cam.Far);
     shader.SetUniform("u_width", cam.Width);
     shader.SetUniform("u_height", cam.Height);
 }
Пример #2
0
        public override void Update(Environment environment, Camera cam, Mesh mesh)
        {
            base.Update(environment, cam, mesh);
            if (currentMaterial != null)
            {
                Texture diffuseTex = currentMaterial.GetTexture(Material.TEXTURE_DIFFUSE);
                if (diffuseTex != null)
                {
                    Texture.ActiveTextureSlot(0);
                    diffuseTex.Use();
                    SetUniform("Material_DiffuseMap", 0);
                    SetUniform("Material_HasDiffuseMap", 1);
                }
                else
                {
                    SetUniform("Material_HasDiffuseMap", 0);
                }

                Texture normalTex = currentMaterial.GetTexture(Material.TEXTURE_NORMAL);
                if (normalTex != null)
                {
                    Texture.ActiveTextureSlot(1);
                    normalTex.Use();
                    SetUniform("Material_NormalMap", 1);
                    SetUniform("Material_HasNormalMap", 1);
                }
                else
                {
                    SetUniform("Material_HasNormalMap", 0);
                }
            }
        }
Пример #3
0
        public override void Update()
        {
            this.shadowMap0 = parent.ShadowCams[0].ShadowMap;
            this.shadowMap1 = parent.ShadowCams[1].ShadowMap;
            this.shadowMap2 = parent.ShadowCams[2].ShadowMap;
            this.shadowMap3 = parent.ShadowCams[3].ShadowMap;
            this.shadowMapViewProjTrans0 = parent.ShadowCams[0].ViewProjectionMatrix;
            this.shadowMapViewProjTrans1 = parent.ShadowCams[1].ViewProjectionMatrix;
            this.shadowMapViewProjTrans2 = parent.ShadowCams[2].ViewProjectionMatrix;
            this.shadowMapViewProjTrans3 = parent.ShadowCams[3].ViewProjectionMatrix;
            this.splits = parent.Splits;

            camMat.SetToLookAt(cam.Translation, cam.Translation.Add(new Vector3f(0, 0, -1)), cam.Up);
            camMat.MultiplyStore(cam.ProjectionMatrix);
            shader.SetUniform("u_camMat", camMat);
            Texture.ActiveTextureSlot(0);
            shadowMap0.Use();
            Texture.ActiveTextureSlot(1);
            shadowMap1.Use();
            Texture.ActiveTextureSlot(2);
            shadowMap2.Use();
            Texture.ActiveTextureSlot(3);
            shadowMap3.Use();
            Texture.ActiveTextureSlot(4);
            depthTexture.Use();
            Texture.ActiveTextureSlot(5);
            colorTexture.Use();
            Texture.ActiveTextureSlot(6);
            noiseMap.Use();

            shader.SetUniform("u_shadowMap0", 0);
            shader.SetUniform("u_shadowMap1", 1);
            shader.SetUniform("u_shadowMap2", 2);
            shader.SetUniform("u_shadowMap3", 3);
            shader.SetUniform("u_depthTexture", 4);
            shader.SetUniform("u_sceneTexture", 5);
            shader.SetUniform("u_noiseTexture", 6);
            shader.SetUniform("u_shadowMapViewProjTrans0", shadowMapViewProjTrans0);
            shader.SetUniform("u_shadowMapViewProjTrans1", shadowMapViewProjTrans1);
            shader.SetUniform("u_shadowMapViewProjTrans2", shadowMapViewProjTrans2);
            shader.SetUniform("u_shadowMapViewProjTrans3", shadowMapViewProjTrans3);
            shader.SetUniform("u_cameraPosition", cam.Translation);
            shader.SetUniform("u_invViewProj", cam.InverseViewProjectionMatrix);
            shader.SetUniform("u_view", cam.ViewMatrix);
            shader.SetUniform("u_proj", cam.ProjectionMatrix);

            if (debugMode)
            {
                shader.SetUniform("B_debugMode", 1);
            }
            else
            {
                shader.SetUniform("B_debugMode", 0);
            }
            for (int i = 0; i < splits.Length; i++)
            {
                shader.SetUniform("splits[" + i + "]", splits[i]);
            }
        }
Пример #4
0
 public override void Update()
 {
     Texture.ActiveTextureSlot(0);
     colorTexture.Use();
     shader.SetUniform("tex", 0);
     shader.SetUniform("u_scale", scale);
     shader.SetUniform("u_texWidth", cam.Width);
     shader.SetUniform("u_texHeight", cam.Height);
 }
Пример #5
0
        public override void Update()
        {
            screenSize.Set(this.cam.Width, this.cam.Height);

            Texture.ActiveTextureSlot(0);
            this.colorTexture.Use();
            shader.SetUniform("u_sceneTex", 0);

            shader.SetUniform("frameBufSize", screenSize);
        }
Пример #6
0
        public override void Update()
        {
            Texture diffTex = colorTexture;

            if (diffTex != null)
            {
                Texture.ActiveTextureSlot(0);
                diffTex.Use();
                shader.SetUniform("u_texture", 0);
            }
        }
Пример #7
0
        public override void Update(Rendering.Environment environment, Camera cam, Mesh mesh)
        {
            base.Update(environment, cam, mesh);

            if (environment.DirectionalLight != null)
            {
                sunDirNor.Set(environment.DirectionalLight.Direction);
                sunDirNor.NormalizeStore();
            }

            skyTransform.SetTranslation(cam.Translation);
            skyTransform.SetScale(skydomeScale);

            if (currentMaterial != null)
            {
                Texture noiseMap;
                if ((noiseMap = currentMaterial.GetTexture("noise_map")) != null)
                {
                    Texture.ActiveTextureSlot(0);
                    noiseMap.Use();
                    SetUniform("u_noiseMap", 0);
                }
            }

            SetUniform("u_globalTime", environment.ElapsedTime);

            SetUniform("u_world", skyTransform.GetMatrix());
            SetUniform("u_view", cam.ViewMatrix);
            SetUniform("u_proj", cam.ProjectionMatrix);
            SetUniform("v3LightPos", sunDirNor);
            SetUniform("v3InvWavelength", invWavelength4);
            SetUniform("fKrESun", KrESun);
            SetUniform("fKmESun", KmESun);
            SetUniform("fOuterRadius", innerRadius * 1.025f);
            SetUniform("fInnerRadius", innerRadius);
            SetUniform("fOuterRadius2", (innerRadius * 1.025f) * (innerRadius * 1.025f));
            SetUniform("fInnerRadius2", innerRadius * innerRadius);
            SetUniform("fKr4PI", Kr4PI);
            SetUniform("fKm4PI", Km4PI);
            SetUniform("fScale", scale);
            SetUniform("fScaleDepth", scaleDepth);
            SetUniform("fScaleOverScaleDepth", scaleOverScaleDepth);
            SetUniform("fSamples", fSamples);
            SetUniform("nSamples", nSamples);
            SetUniform("fg", G);
            SetUniform("fg2", G * G);
            SetUniform("fExposure", exposure);
            SetUniform("v3CameraPos", cam.Translation);
            SetUniform("fCameraHeight2", cam.Height * cam.Height);
            SetUniform("u_sunColor", this.sunColor);
        }
Пример #8
0
        public override void Update(Environment environment, Camera cam, Mesh mesh)
        {
            base.Update(environment, cam, mesh);

            if (currentMaterial != null)
            {
                Texture2D tex = (Texture2D)currentMaterial.GetTexture(Material.TEXTURE_DIFFUSE);
                if (tex != null)
                {
                    Texture.ActiveTextureSlot(0);
                    tex.Use();
                    SetUniform("u_texture", 0);
                    SetUniform("u_imgWidth", tex.Width);
                    SetUniform("u_imgHeight", tex.Height);
                }
                SetUniform("u_delta", currentMaterial.GetFloat("delta_value"));
            }
        }
Пример #9
0
        public override void Update(Environment environment, Camera cam, Mesh mesh)
        {
            base.Update(environment, cam, mesh);

            SetUniform(ENV_FOGSTART, environment.FogStart);
            SetUniform(ENV_FOGEND, environment.FogEnd);

            if (environment.ShadowsEnabled)
            {
                SetUniform("Env_ShadowsEnabled", 1);
                for (int i = 0; i < 4; i++)
                {
                    Texture.ActiveTextureSlot(3 + i);
                    environment.ShadowMaps[i].Use();
                    SetUniform("Env_ShadowMap" + i.ToString(), 3 + i);
                    SetUniform("Env_ShadowMatrix" + i.ToString(), environment.ShadowMatrices[i]);
                    SetUniform("Env_ShadowMapSplits[" + i.ToString() + "]", environment.ShadowMapSplits[i]);
                }
            }
        }
Пример #10
0
        public override void Update(Environment environment, Camera cam, Mesh mesh)
        {
            base.Update(environment, cam, mesh);

            if (currentMaterial != null)
            {
                Texture envTex = currentMaterial.GetTexture(Material.TEXTURE_ENV);
                if (envTex != null)
                {
                    Texture.ActiveTextureSlot(3);
                    envTex.Use();
                    SetUniform("Material_EnvironmentMap", 3);
                    SetUniform("Material_HasEnvironmentMap", 1);
                }
                else
                {
                    SetUniform("Material_HasEnvironmentMap", 0);
                }
            }
        }
Пример #11
0
 public override void Update()
 {
     normalMapTex = normalMapRenderer.NormalMap;
     if (colorTexture != null)
     {
         Texture.ActiveTextureSlot(0);
         colorTexture.Use();
         shader.SetUniform("u_texture", 0);
     }
     if (depthTexture != null)
     {
         Texture.ActiveTextureSlot(1);
         depthTexture.Use();
         shader.SetUniform("u_depthTexture", 1);
     }
     if (normalMapTex != null)
     {
         Texture.ActiveTextureSlot(2);
         normalMapTex.Use();
         shader.SetUniform("u_normalTexture", 2);
     }
     if (noiseTex != null)
     {
         Texture.ActiveTextureSlot(3);
         noiseTex.Use();
         this.shader.SetUniform("u_rotationNoiseTexture", 3);
     }
     this.shader.SetUniform("u_rotationNoiseScale", noiseScale);
     this.shader.SetUniform("u_kernel", kernel);
     this.shader.SetUniform("u_inverseProjectionMatrix", invProj);
     this.shader.SetUniform("u_projectionMatrix", cam.ProjectionMatrix);
     this.shader.SetUniform("u_radius", 1.0f);
     this.shader.SetUniform("u_view", cam.ViewMatrix);
     this.shader.SetUniform("u_near", cam.Near);
     this.shader.SetUniform("u_far", cam.Far);
     this.shader.SetUniform("distanceThreshold", 0.0001f);
     this.shader.SetUniform("u_resolution", resolution);
     this.shader.SetUniform("u_cameraPosition", cam.Translation);
     this.shader.SetUniform("u_cameraDirection", cam.Direction);
     this.shader.SetUniform("u_invViewProj", cam.InverseViewProjectionMatrix);
 }
Пример #12
0
        public override void Update(Environment environment, Camera cam, Mesh mesh)
        {
            base.Update(environment, cam, mesh);

            environment.DirectionalLight.BindLight(0, this);
            environment.AmbientLight.BindLight(0, this);
            for (int i = 0; i < environment.PointLights.Count; i++)
            {
                environment.PointLights[i].BindLight(i, this);
            }

            SetUniform(ENV_NUMPOINTLIGHTS, environment.PointLights.Count);
            SetUniform(ENV_FOGSTART, environment.FogStart);
            SetUniform(ENV_FOGEND, environment.FogEnd);
            SetUniform(ENV_FOGCOLOR, environment.FogColor);
            SetUniform(APEX_ELAPSEDTIME, environment.ElapsedTime);

            if (currentMaterial != null)
            {
                Texture diffuseTex = currentMaterial.GetTexture(Material.TEXTURE_DIFFUSE);
                if (diffuseTex != null)
                {
                    Texture.ActiveTextureSlot(0);
                    diffuseTex.Use();
                    SetUniform("Material_DiffuseMap", 0);
                    SetUniform("Material_HasDiffuseMap", 1);
                }
                else
                {
                    SetUniform("Material_HasDiffuseMap", 0);
                }

                Texture normalTex = currentMaterial.GetTexture(Material.TEXTURE_NORMAL);
                if (normalTex != null)
                {
                    Texture.ActiveTextureSlot(1);
                    normalTex.Use();
                    SetUniform("Material_NormalMap", 1);
                    SetUniform("Material_HasNormalMap", 1);
                }
                else
                {
                    SetUniform("Material_HasNormalMap", 0);
                }

                Texture heightTex = currentMaterial.GetTexture(Material.TEXTURE_HEIGHT);
                if (heightTex != null)
                {
                    Texture.ActiveTextureSlot(2);
                    heightTex.Use();
                    SetUniform("Material_HeightMap", 2);
                    SetUniform("Material_HasHeightMap", 1);
                }
                else
                {
                    SetUniform("Material_HasHeightMap", 0);
                }

                Texture envTex = currentMaterial.GetTexture(Material.TEXTURE_ENV);
                if (envTex != null)
                {
                    Texture.ActiveTextureSlot(3);
                    envTex.Use();
                    SetUniform("Material_EnvironmentMap", 3);
                    SetUniform("Material_HasEnvironmentMap", 1);
                }
                else
                {
                    SetUniform("Material_HasEnvironmentMap", 0);
                }
            }
            if (environment.ShadowsEnabled)
            {
                SetUniform("Env_ShadowsEnabled", 1);
                for (int i = 0; i < 4; i++)
                {
                    Texture.ActiveTextureSlot(4 + i);
                    environment.ShadowMaps[i].Use();
                    SetUniform("Env_ShadowMap" + i.ToString(), 4 + i);
                    SetUniform("Env_ShadowMatrix" + i.ToString(), environment.ShadowMatrices[i]);
                    SetUniform("Env_ShadowMapSplits[" + i.ToString() + "]", environment.ShadowMapSplits[i]);
                }
            }
        }
Пример #13
0
 public override void Update()
 {
     Texture.ActiveTextureSlot(0);
     colorTexture.Use();
     shader.SetUniform("u_tex", 0);
 }
Пример #14
0
        public override void Update(Rendering.Environment environment, Camera cam, Mesh mesh)
        {
            base.Update(environment, cam, mesh);

            environment.DirectionalLight.BindLight(0, this);
            environment.AmbientLight.BindLight(0, this);
            for (int i = 0; i < environment.PointLights.Count; i++)
            {
                environment.PointLights[i].BindLight(i, this);
            }


            SetUniform(ENV_NUMPOINTLIGHTS, environment.PointLights.Count);
            SetUniform(ENV_FOGSTART, environment.FogStart);
            SetUniform(ENV_FOGEND, environment.FogEnd);
            SetUniform(ENV_FOGCOLOR, environment.FogColor);

            if (currentMaterial != null)
            {
                Texture diffuseTex0 = currentMaterial.GetTexture(TerrainMaterial.TEXTURE_DIFFUSE0);
                if (diffuseTex0 != null)
                {
                    Texture.ActiveTextureSlot(0);
                    diffuseTex0.Use();
                    SetUniform("terrainTexture0", 0);

                    float scale = 16f;

                    /* if (currentMaterial.GetFloat(TerrainMaterial.TEXTURE_SCALE_0) > 0)
                     * {
                     *   scale = currentMaterial.GetFloat(TerrainMaterial.TEXTURE_SCALE_0);
                     * }*/
                    SetUniform("terrainTexture0Scale", scale);
                }

                Texture normalTex0 = currentMaterial.GetTexture(TerrainMaterial.TEXTURE_NORMAL0);
                if (normalTex0 != null)
                {
                    Texture.ActiveTextureSlot(1);
                    normalTex0.Use();
                    SetUniform("terrainTexture0Normal", 1);
                    SetUniform("terrainTexture0HasNormal", 1);
                }
                else
                {
                    SetUniform("terrainTexture0HasNormal", 0);
                }

                Texture slopeTex = currentMaterial.GetTexture(TerrainMaterial.TEXTURE_DIFFUSE_SLOPE);
                if (slopeTex != null)
                {
                    Texture.ActiveTextureSlot(9);
                    slopeTex.Use();
                    SetUniform("slopeTexture", 9);

                    float scale = 16f;

                    /*  if (currentMaterial.GetFloat(TerrainMaterial.TEXTURE_SCALE_SLOPE) > 0)
                     * {
                     *    scale = currentMaterial.GetFloat(TerrainMaterial.TEXTURE_SCALE_SLOPE);
                     * }*/
                    SetUniform("slopeScale", scale);
                }

                Texture slopeNormalTex = currentMaterial.GetTexture(TerrainMaterial.TEXTURE_NORMAL_SLOPE);
                if (slopeNormalTex != null)
                {
                    Texture.ActiveTextureSlot(10);
                    slopeNormalTex.Use();
                    SetUniform("slopeTextureNormal", 10);
                    SetUniform("slopeTextureHasNormal", 1);
                }
                else
                {
                    SetUniform("slopeTextureHasNormal", 0);
                }

                Texture splatTex = currentMaterial.GetTexture(TerrainMaterial.TEXTURE_SPLAT);
                if (splatTex != null)
                {
                    Texture.ActiveTextureSlot(11);
                    splatTex.Use();
                    SetUniform("splatTexture", 11);
                    SetUniform("hasSplatMap", 1);
                }
                else
                {
                    SetUniform("hasSplatMap", 0);
                }
            }
            if (environment.ShadowsEnabled)
            {
                SetUniform("Env_ShadowsEnabled", 1);
                for (int i = 0; i < 4; i++)
                {
                    Texture.ActiveTextureSlot(3 + i);
                    environment.ShadowMaps[i].Use();
                    SetUniform("Env_ShadowMap" + i.ToString(), 3 + i);
                    SetUniform("Env_ShadowMatrix" + i.ToString(), environment.ShadowMatrices[i]);
                    SetUniform("Env_ShadowMapSplits[" + i.ToString() + "]", environment.ShadowMapSplits[i]);
                }
            }
        }