Esempio n. 1
0
		private string GetFragmentShaderSource(ref DefaultFragmentShaderOptions fso)
		{
			var sb = new StringBuilder();

			if (fso.COL_STREAM)
			{
				sb.Append("#define COL_STREAM\n");
			}
			if (fso.FAST_FOG)
			{
				sb.Append("#define FAST_FOG\n");
			}
			if (fso.FOG)
			{
				sb.Append("#define FOG\n");
			}
			if (fso.LIGHT_AMBIENT)
			{
				sb.Append("#define LIGHT_AMBIENT\n");
			}
			if (fso.LIGHT_DIFFUSE)
			{
				sb.Append("#define LIGHT_DIFFUSE\n");
			}
			if (fso.LIGHT_SPECULAR)
			{
				sb.Append("#define LIGHT_SPECULAR\n");
			}
			if (fso.LIGHT_EMISSIVE)
			{
				sb.Append("#define LIGHT_EMISSIVE\n");
			}
			if (fso.UV0_STREAM)
			{
				sb.Append("#define UV0_STREAM\n");
			}
			if (fso.UV1_STREAM)
			{
				sb.Append("#define UV1_STREAM\n");
			}
			if (fso.IW_GX_PLATFORM_TEGRA2)
			{
				sb.Append("#define IW_GX_PLATFORM_TEGRA2\n");
			}
			if (fso.TEX0)
			{
				sb.Append("#define TEX0\n");
			}
			if (fso.TEX1)
			{
				sb.Append("#define TEX1\n");
			}
			if (fso.ALPHA_TEST != 0)
			{
				sb.Append(string.Format("#define ALPHA_TEST {0}\n", fso.ALPHA_TEST));
			}
			sb.Append(string.Format("#define ALPHA_BLEND {0}\n", fso.ALPHA_BLEND));
			sb.Append(string.Format("#define BLEND {0}\n", fso.BLEND));
			sb.Append(string.Format("#define EFFECT_PRESET {0}\n", fso.EFFECT_PRESET));
			sb.Append(this.defaultFragmentShader);
			return sb.ToString();
		}
Esempio n. 2
0
		private ShaderTechniqueArgumentIndices ApplyMaterialShader(IVertexStreamSource mesh)
		{
			if (this.material == null)
			{
				return this.ApplyDefaultMaterial(mesh);
			}

			this.ApplyMaterialTextures();

			var shaderTechnique = this.material.ShaderTechnique.Resource as ShaderTechnique;
			if (shaderTechnique != null)
			{
				var programShader = this.GetShaderProgram(shaderTechnique);
				GL.UseProgram(programShader.ProgramId);
				OpenTKHelper.Assert();

				this.BindShaderArgs(ref programShader);
				return programShader;
			}

			var vso = new DefaultVertexShaderOptions
				{
					BITANGENT_STREAM = mesh.HasStream(Streams.Binormal, 0),
					COL_STREAM = mesh.HasStream(Streams.Color, 0),
					FAST_FOG = false,
					FOG = false,
					//!material.NoFog,
					LIGHT_AMBIENT = this.lighting && this.light.Enabled,
					LIGHT_DIFFUSE = this.lighting && this.light.Enabled && this.IsNotDisabledColor(this.light.Diffuse),
					LIGHT_SPECULAR = this.lighting && this.light.Enabled && this.IsNotDisabledColor(this.light.Specular),
					LIGHT_EMISSIVE = this.lighting && this.light.Enabled,
					NORM_STREAM = mesh.HasStream(Streams.Normal, 0),
					SKIN_MAJOR_BONE = false,
					SKINWEIGHT_STREAM = false,
					SKIN_NORMALS = false,
					TANGENT_STREAM = mesh.HasStream(Streams.Tangent, 0),
					UV0_STREAM = mesh.HasStream(Streams.TexCoord, 0),
					UV1_STREAM = mesh.HasStream(Streams.TexCoord, 1)
				};

			var fso = new DefaultFragmentShaderOptions
				{
					COL_STREAM = mesh.HasStream(Streams.Color, 0),
					FAST_FOG = false,
					FOG = false,
					//!material.NoFog,
					LIGHT_AMBIENT = this.lighting && this.light.Enabled,
					LIGHT_DIFFUSE = this.lighting && this.light.Enabled && this.IsNotDisabledColor(this.light.Diffuse),
					LIGHT_SPECULAR = this.lighting && this.light.Enabled && this.IsNotDisabledColor(this.light.Specular),
					LIGHT_EMISSIVE = this.lighting && this.light.Enabled,
					UV0_STREAM = mesh.HasStream(Streams.TexCoord, 0),
					UV1_STREAM = mesh.HasStream(Streams.TexCoord, 1),
					ALPHA_BLEND = (int)this.material.AlphaMode,
					ALPHA_TEST = (int)this.material.AlphaTestMode,
					BLEND = (int)this.material.BlendMode,
					EFFECT_PRESET = (int)this.material.EffectPreset,
					IW_GX_PLATFORM_TEGRA2 = false,
					TEX0 = !this.material.Texture0.IsEmpty,
					TEX1 = !this.material.Texture1.IsEmpty
				};

			ShaderTechniqueArgumentIndices p = this.shaders.GetProgram(new DefaultProgramOptions(vso, fso));
			GL.UseProgram(p.ProgramId);
			OpenTKHelper.Assert();

			this.BindShaderArgs(ref p);

			return p;
		}
Esempio n. 3
0
		private int GenFragmentShader(DefaultFragmentShaderOptions fso)
		{
			OpenTKHelper.Assert();
			int p;
			if (!this.generatedFragmentShaders.TryGetValue(fso, out p))
			{
				string fragmentShaderSource = this.GetFragmentShaderSource(ref fso);
				p = GenShader(ShaderType.FragmentShader, fragmentShaderSource);
				this.generatedFragmentShaders[fso] = p;
			}
			return p;
		}
Esempio n. 4
0
		private ShaderTechniqueArgumentIndices ApplyDefaultMaterial(IVertexStreamSource mesh)
		{
			var vso = new DefaultVertexShaderOptions
				{
					BITANGENT_STREAM = false,
					//mesh.IsBinormalStreamAvailable,
					COL_STREAM = mesh.HasStream(Streams.Color, 0),
					FAST_FOG = false,
					FOG = false,
					//!material.NoFog,
					LIGHT_AMBIENT = this.lighting && this.light.Enabled,
					LIGHT_DIFFUSE =
						this.lighting && this.light.Enabled
						&& this.IsNotDisabledColor(this.light.Diffuse),
					LIGHT_SPECULAR =
						this.lighting && this.light.Enabled
						&& this.IsNotDisabledColor(this.light.Specular),
					LIGHT_EMISSIVE = this.lighting && this.light.Enabled,
					NORM_STREAM = mesh.HasStream(Streams.Normal, 0),
					SKIN_MAJOR_BONE = false,
					SKINWEIGHT_STREAM = false,
					SKIN_NORMALS = false,
					TANGENT_STREAM = false,
					//mesh.IsTangentStreamAvailable,
					UV0_STREAM = mesh.HasStream(Streams.TexCoord, 0) && this.isTextureSet[0],
					UV1_STREAM = mesh.HasStream(Streams.TexCoord, 1) && this.isTextureSet[1]
				};

			var fso = new DefaultFragmentShaderOptions
				{
					COL_STREAM = mesh.HasStream(Streams.Color, 0),
					FAST_FOG = false,
					FOG = false,
					//!material.NoFog,
					LIGHT_AMBIENT = this.lighting && this.light.Enabled,
					LIGHT_DIFFUSE = this.lighting && this.light.Enabled && this.IsNotDisabledColor(this.light.Diffuse),
					LIGHT_SPECULAR = this.lighting && this.light.Enabled && this.IsNotDisabledColor(this.light.Specular),
					LIGHT_EMISSIVE = this.lighting && this.light.Enabled,
					UV0_STREAM = mesh.HasStream(Streams.TexCoord, 0),
					UV1_STREAM = mesh.HasStream(Streams.TexCoord,1),
					ALPHA_BLEND = (int)AlphaMode.DEFAULT,
					ALPHA_TEST = (int)AlphaTestMode.DISABLED,
					BLEND = (int)BlendMode.MODULATE,
					EFFECT_PRESET = (int)EffectPreset.DEFAULT,
					IW_GX_PLATFORM_TEGRA2 = false,
					TEX0 = this.isTextureSet[0],
					TEX1 = this.isTextureSet[1]
				};

			ShaderTechniqueArgumentIndices p = this.shaders.GetProgram(new DefaultProgramOptions(vso, fso));
			GL.UseProgram(p.ProgramId);
			OpenTKHelper.Assert();

			this.BindShaderArgs(ref p);

			return p;
		}