Example #1
0
		private string GetVertexShaderSource(ref DefaultVertexShaderOptions fso)
		{
			var sb = new StringBuilder();

			if (fso.BITANGENT_STREAM)
			{
				sb.Append("#define BITANGENT_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.NORM_STREAM)
			{
				sb.Append("#define NORM_STREAM\n");
			}
			if (fso.SKIN_MAJOR_BONE)
			{
				sb.Append("#define SKIN_MAJOR_BONE\n");
			}
			if (fso.SKINWEIGHT_STREAM)
			{
				sb.Append("#define SKINWEIGHT_STREAM\n");
			}
			if (fso.SKIN_NORMALS)
			{
				sb.Append("#define SKIN_NORMALS\n");
			}
			if (fso.TANGENT_STREAM)
			{
				sb.Append("#define TANGENT_STREAM\n");
			}
			if (fso.UV0_STREAM)
			{
				sb.Append("#define UV0_STREAM\n");
			}
			if (fso.UV1_STREAM)
			{
				sb.Append("#define UV1_STREAM\n");
			}
			if (fso.COL_STREAM)
			{
				sb.Append("#define COL_STREAM\n");
			}
			sb.Append(this.defaultVertexShader);
			return sb.ToString();
		}
Example #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;
		}
Example #3
0
		private int GenVertexShader(DefaultVertexShaderOptions fso)
		{
			OpenTKHelper.Assert();
			int p;
			if (!this.generatedVertexShaders.TryGetValue(fso, out p))
			{
				ShaderType fragmentShader = ShaderType.VertexShader;
				string fragmentShaderSource = this.GetVertexShaderSource(ref fso);
				p = GenShader(fragmentShader, fragmentShaderSource);
				this.generatedVertexShaders[fso] = p;
			}
			return p;
		}
Example #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;
		}