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; }
public VertexBufferRenderData(IVertexStreamSource mesh, IEnumerable<IVertexIndexSource> submeshes) { var position = mesh.GetStreamReader<Vector3>(Streams.Position, 0); var normal = mesh.GetStreamReader<Vector3>(Streams.Normal, 0); var tangent = mesh.GetStreamReader<Vector3>(Streams.Tangent, 0); var binormal = mesh.GetStreamReader<Vector3>(Streams.Binormal, 0); var texcoord0 = mesh.GetStreamReader<Vector3>(Streams.TexCoord, 0); var texcoord1 = mesh.GetStreamReader<Vector3>(Streams.TexCoord, 1); var color = mesh.GetStreamReader<Vector4>(Streams.Color, 0); if (position != null) this.v = new List<Vector3>(mesh.Count); if (normal != null) this.n = new List<Vector3>(mesh.Count); if (binormal != null) this.b = new List<Vector3>(mesh.Count); if (tangent != null) this.t = new List<Vector3>(mesh.Count); if (texcoord0 != null) this.uv0 = new List<Vector3>(mesh.Count); if (texcoord1 != null) this.uv1 = new List<Vector3>(mesh.Count); if (color != null) this.c = new List<Vector4>(mesh.Count); foreach (var subMesh in submeshes) { var positionIndices = subMesh.GetIndexReader(Streams.Position, 0); var normalIndices = subMesh.GetIndexReader(Streams.Normal, 0); var binormalIndices = subMesh.GetIndexReader(Streams.Binormal, 0); var tangentIndices = subMesh.GetIndexReader(Streams.Tangent, 0); var colorIndices = subMesh.GetIndexReader(Streams.Color, 0); var uv0Indices = subMesh.GetIndexReader(Streams.TexCoord, 0); var uv1Indices = subMesh.GetIndexReader(Streams.TexCoord, 1); for (int i = 0; i < positionIndices.Count; ++i) { if (position != null && positionIndices != null) { this.v.Add(position[positionIndices[i]]); } if (normal != null && normalIndices != null) { this.n.Add(normal[normalIndices[i]]); } if (binormal != null && binormalIndices != null) { this.n.Add(binormal[binormalIndices[i]]); } if (tangent != null && tangentIndices != null) { this.t.Add(tangent[tangentIndices[i]]); } if (color != null && colorIndices != null) { this.c.Add(color[colorIndices[i]]); } if (texcoord0 != null && uv0Indices != null) { this.uv0.Add(texcoord0[uv0Indices[i]]); } if (texcoord1 != null && uv1Indices != null) { this.uv1.Add(texcoord1[uv1Indices[i]]); } } } if (v != null) { v = v.ToArray(); } if (n!= null) { n = n.ToArray(); } if (b != null) { b = b.ToArray(); } if (t != null) { t = t.ToArray(); } if (c != null) { c = c.ToArray(); } if (uv0 != null) { uv0 = uv0.ToArray(); } if (uv1 != null) { uv1 = uv1.ToArray(); } //this.t = null; //if (tangent != null) //{ // this.t = tangent.ToArray(); //} //this.b = null; //if (binormal != null) //{ // this.b = binormal.ToArray(); //} //this.uv0 = texcoord0 != null ? texcoord0.ToArray() : null; //this.uv1 = texcoord1 != null ? texcoord1.ToArray() : null; //if (color != null) //{ // this.c = new byte[mesh.Count*4]; // int j = 0; // foreach (var col in color) // { // this.c[j] = col.R; // ++j; // this.c[j] = col.G; // ++j; // this.c[j] = col.B; // ++j; // this.c[j] = col.A; // ++j; // } //} //else //{ // this.c = null; //} }
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; }