private void PrepareShaderProgram() { if (program != null) { return; } // TODO: We need to tweak shadow quality settings var lightSourceAvailable = lightSource != null; var spec = new CommonMaterialProgramSpec { SkinEnabled = skinEnabled, DiffuseTextureEnabled = diffuseTexture != null, FogMode = FogMode, ProcessLightning = ProcessLightning, RecieveShadows = RecieveShadows, ShadowMapSize = lightSourceAvailable ? lightSource.ShadowMapSize : IntVector2.Zero, SmoothShadows = true, HighQualitySmoothShadows = lightSourceAvailable && lightSource.ShadowMapQuality > ShadowMapTextureQuality.Medium }; if (programCache.TryGetValue(spec, out program)) { return; } program = new CommonMaterialProgram(spec); programCache[spec] = program; }
private static Sampler[] GetSamplers(CommonMaterialProgramSpec spec) { return(new[] { new Sampler { Name = "u_DiffuseTexture", Stage = DiffuseTextureStage } }); }
private static Shader[] GetShaders(CommonMaterialProgramSpec spec) { var preamble = BuildPreamble(spec); return(new Shader[] { new VertexShader(preamble + VertexShader), new FragmentShader(preamble + FragmentShader) }); }
private static string BuildPreamble(CommonMaterialProgramSpec spec) { var preamble = ""; if (spec.ShadowRenderingMode) { preamble += "#define SHADOWS_RENDERING_MODE\n"; } if (spec.SkinEnabled) { preamble += "#define SKIN_ENABLED\n"; } if (spec.DiffuseTextureEnabled) { preamble += "#define DIFFUSE_TEXTURE_ENABLED\n"; } switch (spec.SkinningMode) { case SkinningMode.Linear: preamble += "#define LINEAR_SKINNING\n"; break; case SkinningMode.DualQuaternion: preamble += "#define DUAL_QUATERNION_SKINNING\n"; break; } if (spec.FogMode != FogMode.None) { preamble += "#define FOG_ENABLED\n"; if (spec.FogMode == FogMode.Linear) { preamble += "#define FOG_LINEAR\n"; } else if (spec.FogMode == FogMode.Exp) { preamble += "#define FOG_EXP\n"; } else if (spec.FogMode == FogMode.ExpSquared) { preamble += "#define FOG_EXP_SQUARED\n"; } } return(preamble); }
private void PrepareShaderProgram() { if (program != null) { return; } var spec = new CommonMaterialProgramSpec { SkinEnabled = skinEnabled, DiffuseTextureEnabled = diffuseTexture != null, FogMode = FogMode }; if (programCache.TryGetValue(spec, out program)) { return; } program = new CommonMaterialProgram(spec); programCache[spec] = program; }
public CommonMaterialProgram(CommonMaterialProgramSpec spec) : base(GetShaders(spec), GetAttribLocations(), GetSamplers(spec)) { }