コード例 #1
0
ファイル: ToeGraphicsContext.cs プロジェクト: gleblebedev/toe
		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;
		}
コード例 #2
0
ファイル: ToeGraphicsContext.cs プロジェクト: gleblebedev/toe
		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;
		}