Exemplo n.º 1
0
 public override void Render(Rendering.Environment environment, Camera cam)
 {
     SpriteRenderer spriteRenderer = renderManager.SpriteRenderer;
     spriteRenderer.Render(texture, WorldTransform, WorldTransform.GetTranslation().x,
            WorldTransform.GetTranslation().y,
             texture.Width * WorldTransform.GetScale().x, texture.Height * WorldTransform.GetScale().y, white);
 }
Exemplo n.º 2
0
 public Game(Renderer renderer)
 {
     cam = new DefaultCamera(inputManager, 55);
     renderManager = new RenderManager(renderer, cam, new Action(() => { Render(); }));
     renderManager.SpriteRenderer = new SpriteRenderer(this);
     physicsWorld = new PhysicsWorld(new PhysicsDebugDraw(cam));
 }
Exemplo n.º 3
0
 public Populator(Camera cam, bool batchGeometry, int seed, float probability)
 {
     this.cam = cam;
     this.batchGeometry = batchGeometry;
     rand = new Random(12345);
     this.probability = probability;
 }
Exemplo n.º 4
0
 public RenderManager(Renderer renderer, Camera cam, Action userRender)
 {
     RenderManager.renderer = renderer;
     this.userRender = userRender;
     postProcessor = new PostProcessor(this, cam);
     depthFbo = new Framebuffer(cam.Width, cam.Height);
 }
Exemplo n.º 5
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);
        }
Exemplo n.º 6
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"));
            }
        }
Exemplo n.º 7
0
 public virtual void Update(Environment environment, Camera cam, Mesh mesh)
 {
     SetDefaultValues();
     SetUniform(APEX_WORLDMATRIX, worldMatrix);
     SetUniform(APEX_VIEWMATRIX, viewMatrix);
     SetUniform(APEX_PROJECTIONMATRIX, projectionMatrix);
     SetUniform(APEX_CAMERAPOSITION, cam.Translation);
     SetUniform(APEX_CAMERADIRECTION, cam.Direction);
 }
Exemplo n.º 8
0
        public void SaveScreenToTexture(Camera cam, Texture toSaveTo)
        {
            toSaveTo.Use();

            Renderer.CopyScreenToTexture2D(cam.Width, cam.Height);

            Texture2D.Clear();
        }
Exemplo n.º 9
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);

            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]);
                }
            }
        }
Exemplo n.º 10
0
 public Populator(Camera cam, bool batchGeometry)
     : this(cam, batchGeometry, 12345)
 {
 }
Exemplo n.º 11
0
 public Populator(Camera cam, bool batchGeometry, int seed)
     : this(cam, batchGeometry, seed, 0.5f)
 {
 }
Exemplo n.º 12
0
 public abstract void DrawTriangle(Camera cam, float x1, float y1, float z1, float x2, float y2, float z2, float x3, float y3, float z3);
Exemplo n.º 13
0
 public virtual void Render(Rendering.Environment environment, Camera cam)
 {
     if (shader == null)
     {
         SetDefaultShader();
     }
     if (mesh != null)
     {
         shader.Use();
         shader.ApplyMaterial(Material);
         shader.SetTransforms(GetWorldMatrix(), cam.ViewMatrix, cam.ProjectionMatrix);
         shader.Update(environment, cam, mesh);
         shader.Render(mesh);
         shader.End();
         Shader.Clear();
     }
 }
Exemplo n.º 14
0
 public PhysicsDebugDraw(Camera cam)
 {
     this.cam = cam;
 }
Exemplo n.º 15
0
 public abstract void SetAudioListenerValues(Camera cam);
Exemplo n.º 16
0
 public NormalMapRenderer(Environment env, Camera cam)
 {
     this.cam = cam;
     this.env = env;
 }
Exemplo n.º 17
0
 public RockPopulator(PhysicsWorld physicsWorld, Camera cam)
     : base(cam, true, 0.42f)
 {
     this.physicsWorld = physicsWorld;
 }
Exemplo n.º 18
0
 public Populator(Camera cam, bool batchGeometry, int seed)
 {
     this.cam = cam;
     this.batchGeometry = batchGeometry;
     rand = new Random(seed);
 }
Exemplo n.º 19
0
        public void Render(Environment env, Camera cam)
        {
            renderer.Viewport(0, 0, cam.Width, cam.Height);

               // RenderDepthTexture(env, cam);

            renderer.ClearColor(backgroundColor.x, backgroundColor.y, backgroundColor.z, backgroundColor.w);
            renderer.Clear(true, true, false);

            foreach (RenderComponent rc in components)
            {
                rc.Render();
                rc.Update();
            }
            postProcessor.Capture();

            RenderBucket(env, cam, Bucket.Sky);
            RenderBucket(env, cam, Bucket.Opaque);
            RenderBucket(env, cam, Bucket.Transparent);
            RenderBucket(env, cam, Bucket.Particle);
            userRender();

            postProcessor.Release();
        }
Exemplo n.º 20
0
 public abstract void DrawLine(Camera cam, float x1, float y1, float z1, float x2, float y2, float z2);
Exemplo n.º 21
0
 public GrassPopulator(PhysicsWorld physicsWorld, Camera cam)
     : base(cam, true)
 {
     this.physicsWorld = physicsWorld;
 }
Exemplo n.º 22
0
 public void RenderBucket(Environment env, Camera cam, Bucket bucket)
 {
     for (int i = 0; i < geometries.Count; i++)
     {
         if (geometries[i].AttachedToRoot && geometries[i].Material.Bucket == bucket)
         {
             geometries[i].Render(env, cam);
         }
     }
 }
Exemplo n.º 23
0
        public void RenderBucketDepth(Environment env, Camera cam, Bucket bucket, DepthRenderMode renderMode)
        {
            for (int i = 0; i < geometries.Count; i++)
            {
                if (geometries[i].AttachedToRoot && geometries[i].Material.Bucket == bucket)
                {
                    if (geometries[i].DepthShader == null)
                    {
                        if (geometries[i].GetShader() == null)
                            geometries[i].SetDefaultShader();
                        ShaderProperties p = new ShaderProperties(geometries[i].ShaderProperties);
                        p.SetProperty("DEPTH", true);
                        geometries[i].DepthShader = ShaderManager.GetShader(typeof(Shaders.DepthShader), p);
                    }
                    if (renderMode == DepthRenderMode.Shadow && geometries[i].Material.GetBool(Material.MATERIAL_CASTSHADOWS))
                    {
                        geometries[i].DepthShader.Use();
                        geometries[i].DepthShader.ApplyMaterial(geometries[i].Material);
                        geometries[i].DepthShader.SetTransforms(geometries[i].GetWorldMatrix(), cam.ViewMatrix, cam.ProjectionMatrix);
                        geometries[i].DepthShader.Update(env, cam, geometries[i].Mesh);
                        geometries[i].DepthShader.Render(geometries[i].Mesh);
                        geometries[i].DepthShader.End();
                    }

                    Shader.Clear();
                    Texture2D.Clear();
                }
            }
        }
Exemplo n.º 24
0
        public void RenderBucketNormals(Environment env, Camera cam, Bucket bucket)
        {
            for (int i = 0; i < geometries.Count; i++)
            {
                if (geometries[i].AttachedToRoot && geometries[i].Material.Bucket == bucket)
                {
                    if (geometries[i].NormalsShader == null)
                    {
                        if (geometries[i].GetShader() == null)
                            geometries[i].SetDefaultShader();
                        ShaderProperties p = new ShaderProperties(geometries[i].ShaderProperties);
                        p.SetProperty("NORMALS", true);
                        geometries[i].NormalsShader = ShaderManager.GetShader(typeof(Shaders.NormalsShader), p);

                    }

                    geometries[i].NormalsShader.Use();
                    geometries[i].NormalsShader.ApplyMaterial(geometries[i].Material);
                    geometries[i].NormalsShader.SetTransforms(geometries[i].GetWorldMatrix(), cam.ViewMatrix, cam.ProjectionMatrix);
                    geometries[i].NormalsShader.Update(env, cam, geometries[i].Mesh);
                    geometries[i].NormalsShader.Render(geometries[i].Mesh);
                    geometries[i].NormalsShader.End();

                    Shader.Clear();
                }
            }
        }
Exemplo n.º 25
0
 public Populator(Camera cam, bool batchGeometry, float probability)
     : this(cam, batchGeometry, 12345, probability)
 {
 }
Exemplo n.º 26
0
        public void RenderDepthTexture(Environment env, Camera cam)
        {
            if (depthFbo.Width != cam.Width || depthFbo.Height != cam.Height)
            {
                depthFbo.Width = cam.Width;
                depthFbo.Height = cam.Height;
                depthFbo.Init();
            }
            depthFbo.Capture();

            renderer.Clear(true, true, false);

            RenderBucketDepth(env, cam, Bucket.Opaque, DepthRenderMode.Depth);
            RenderBucketDepth(env, cam, Bucket.Transparent, DepthRenderMode.Depth);

            depthFbo.Release();
            depthTexture = depthFbo.ColorTexture;
        }
Exemplo n.º 27
0
 public Populator(Camera cam)
     : this(cam, true)
 {
 }
Exemplo n.º 28
0
 public TreePopulator(PhysicsWorld physicsWorld, Camera cam)
     : base(cam, false, 0.4f)
 {
     this.physicsWorld = physicsWorld;
 }