protected void setMaterialState() { GL.Enable(EnableCap.ColorMaterial); // turn off per-vertex color GL.Color4(this.MainColor); // setup the base color values... var colorMat = this.colorMaterial ?? _defaultColorMat; SSColorMaterial.applyColorMaterial(colorMat); if (textureMaterial != null) { GL.ActiveTexture(TextureUnit.Texture0); GL.Enable(EnableCap.Texture2D); if (textureMaterial.ambientTex != null || textureMaterial.diffuseTex != null) { // fall back onto the diffuse texture in the absence of ambient SSTexture tex = textureMaterial.diffuseTex ?? textureMaterial.ambientTex; GL.BindTexture(TextureTarget.Texture2D, tex.TextureID); } else { GL.BindTexture(TextureTarget.Texture2D, 0); } } }
public static void applyColorMaterial(SSColorMaterial colorMat) { colorMat = colorMat ?? defaultColorMat; GL.Material(MaterialFace.Front, MaterialParameter.Ambient, colorMat.ambientColor); GL.Material(MaterialFace.Front, MaterialParameter.Diffuse, colorMat.diffuseColor); GL.Material(MaterialFace.Front, MaterialParameter.Specular, colorMat.specularColor); GL.Material(MaterialFace.Front, MaterialParameter.Emission, colorMat.emissionColor); GL.Material(MaterialFace.Front, MaterialParameter.Shininess, colorMat.shininess); }
private SSMeshOBJSubsetData _loadMaterialSubset(string baseDirectory, WavefrontObjLoader wff, WavefrontObjLoader.MaterialInfoWithFaces objMatSubset) { // generate renderable geometry data... SSVertex_PosNormTex[] vertices; UInt16[] triIndices, wireframeIndices; VertexSoup_VertexFormatBinder.generateDrawIndexBuffer( wff, objMatSubset, out triIndices, out vertices); wireframeIndices = OpenTKHelper.generateLineIndicies(triIndices); SSMeshOBJSubsetData subsetData = new SSMeshOBJSubsetData( vertices, triIndices, wireframeIndices); // setup the material... // load and link every texture present subsetData.textureMaterial = SSTextureMaterial.FromBlenderMtl(baseDirectory, objMatSubset.mtl); subsetData.colorMaterial = SSColorMaterial.fromMtl(objMatSubset.mtl); return(subsetData); }
private void _renderSetupGLSL(SSRenderConfig renderConfig, SSMainShaderProgram shaderPgm, SSMeshOBJSubsetData subset) { // Step 1: setup GL rendering modes... // GL.Enable(EnableCap.Lighting); // GL.Enable(EnableCap.Blend); // GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha); // GL.PixelStore(PixelStoreParameter.UnpackAlignment, 1); // Step 2: setup our material mode and paramaters... if (renderConfig.drawingShadowMap) { // assume SSObject.Render has setup our materials properly for the shadowmap Pass // TODO: find a better way to do this! return; } SSColorMaterial.applyColorMaterial(subset.colorMaterial); if (shaderPgm == null) { SSShaderProgram.DeactivateAll(); // fixed function single-texture if (subset.textureMaterial.diffuseTex != null) { GL.ActiveTexture(TextureUnit.Texture0); GL.Enable(EnableCap.Texture2D); GL.BindTexture(TextureTarget.Texture2D, subset.textureMaterial.diffuseTex.TextureID); } } else { shaderPgm.Activate(); shaderPgm.SetupTextures(subset.textureMaterial); } }