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); }
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); }
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(); } }
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]); } } }