public PerPixelLighting() { this.trackVertexColorType = TrackVertexColor.None; this.specularEnable = false; this.blankLight = new Light(); this.blankLight.Diffuse = ColorEx.Black; this.blankLight.Specular = ColorEx.Black; this.blankLight.SetAttenuation( 0, 1, 0, 0 ); }
public FFPLighting() { this.trackVertexColorType = TrackVertexColor.None; this.specularEnable = false; this.blankLight = new Light(); this.blankLight.Diffuse = ColorEx.Black; this.blankLight.Specular = ColorEx.Black; this.blankLight.SetAttenuation(0, 1, 0, 0); }
public override bool PreAddToRenderState(TargetRenderState targetRenderState, Graphics.Pass srcPass, Graphics.Pass dstPass) { TrackVertexColor trackColor = srcPass.VertexColorTracking; if (trackColor != null) { AddResolveStageMask((int)StageFlags.VsInputDiffuse); } return(true); }
private static Light blankLight; //Shared blank light #endregion #region C'Tor public NormalMapLighting() { this.trackVertexColorType = TrackVertexColor.None; this.normalMapSamplerIndex = 0; this.vsTexCoordSetIndex = 0; this.specularEnabled = false; this.normalMapSpace = NormalMapSpace.Tangent; this.normalMapMinFilter = FilterOptions.Linear; this.normalMapMagFilter = FilterOptions.Linear; this.normalMapMipfilter = FilterOptions.Point; this.normalMapAnisotropy = 1; this.normalMapMipBias = -1.0; blankLight.Diffuse = ColorEx.Black; blankLight.Specular = ColorEx.Black; blankLight.SetAttenuation( 0, 1, 0, 0 ); }
public override void SetSurfaceParams(ColorEx ambient, ColorEx diffuse, ColorEx specular, ColorEx emissive, Real shininess, TrackVertexColor tracking = TrackVertexColor.None) { // TODO: Cache color values to prune unneccessary setting // create a new material based on the supplied params var mat = new D3D.Material(); mat.Diffuse = D3DHelper.ToColor( diffuse ); mat.Ambient = D3DHelper.ToColor( ambient ); mat.Specular = D3DHelper.ToColor( specular ); mat.Emissive = D3DHelper.ToColor( emissive ); mat.Power = shininess; // set the current material ActiveD3D9Device.Material = mat; if ( tracking != TrackVertexColor.None ) { SetRenderState( RenderState.ColorVertex, true ); SetRenderState( RenderState.AmbientMaterialSource, (int)( ( ( tracking & TrackVertexColor.Ambient ) != 0 ) ? ColorSource.Color1 : ColorSource.Material ) ); SetRenderState( RenderState.DiffuseMaterialSource, (int)( ( ( tracking & TrackVertexColor.Diffuse ) != 0 ) ? ColorSource.Color1 : ColorSource.Material ) ); SetRenderState( RenderState.SpecularMaterialSource, (int)( ( ( tracking & TrackVertexColor.Specular ) != 0 ) ? ColorSource.Color1 : ColorSource.Material ) ); SetRenderState( RenderState.EmissiveMaterialSource, (int)( ( ( tracking & TrackVertexColor.Emissive ) != 0 ) ? ColorSource.Color1 : ColorSource.Material ) ); } else { SetRenderState( RenderState.ColorVertex, false ); } }
/// <summary> /// /// </summary> /// <param name="ambient"></param> /// <param name="diffuse"></param> /// <param name="specular"></param> /// <param name="emissive"></param> /// <param name="shininess"></param> /// <param name="tracking"></param> public override void SetSurfaceParams( ColorEx ambient, ColorEx diffuse, ColorEx specular, ColorEx emissive, float shininess, TrackVertexColor tracking ) { // Track vertex colour if ( tracking != TrackVertexColor.None ) { All gt = All.Diffuse; // There are actually 15 different combinations for tracking, of which // GL only supports the most used 5. This means that we have to do some // magic to find the best match. NOTE: // GL_AMBIENT_AND_DIFFUSE != GL_AMBIENT | GL__DIFFUSE if ( ( tracking & TrackVertexColor.Ambient ) != 0 ) { if ( ( tracking & TrackVertexColor.Diffuse ) != 0 ) { gt = All.AmbientAndDiffuse; } else { gt = All.Ambient; } } else if ( ( tracking & TrackVertexColor.Diffuse ) != 0 ) { gt = All.Diffuse; } else if ( ( tracking & TrackVertexColor.Specular ) != 0 ) { gt = All.Emission; } OpenGL.Enable( gt ); GLESConfig.GlCheckError( this ); OpenGL.Enable( All.ColorMaterial ); GLESConfig.GlCheckError( this ); } else { OpenGL.Disable( All.ColorMaterial ); } // XXX Cache previous values? // XXX Front or Front and Back? float[] f4Val = new float[] { diffuse.r, diffuse.g, diffuse.b, diffuse.a }; OpenGL.Material( All.FrontAndBack, All.Diffuse, f4Val ); GLESConfig.GlCheckError( this ); f4Val[ 0 ] = ambient.r; f4Val[ 1 ] = ambient.g; f4Val[ 2 ] = ambient.b; f4Val[ 3 ] = ambient.a; OpenGL.Material( All.FrontAndBack, All.Ambient, f4Val ); GLESConfig.GlCheckError( this ); f4Val[ 0 ] = specular.r; f4Val[ 1 ] = specular.g; f4Val[ 2 ] = specular.b; f4Val[ 3 ] = specular.a; OpenGL.Material( All.FrontAndBack, All.Specular, f4Val ); GLESConfig.GlCheckError( this ); f4Val[ 0 ] = emissive.r; f4Val[ 1 ] = emissive.g; f4Val[ 2 ] = emissive.b; f4Val[ 3 ] = emissive.a; OpenGL.Material( All.FrontAndBack, All.Emission, f4Val ); GLESConfig.GlCheckError( this ); OpenGL.Material( All.FrontAndBack, All.Shininess, shininess ); GLESConfig.GlCheckError( this ); }
/// <summary> /// Sets the surface parameters to be used during rendering an object. /// </summary> /// <param name="ambient"></param> /// <param name="diffuse"></param> /// <param name="specular"></param> /// <param name="emissive"></param> /// <param name="shininess"></param> /// <param name="tracking"></param> public abstract void SetSurfaceParams(ColorEx ambient, ColorEx diffuse, ColorEx specular, ColorEx emissive, float shininess, TrackVertexColor tracking);
public override void SetSurfaceParams(ColorEx ambient, ColorEx diffuse, ColorEx specular, ColorEx emissive, Real shininess, TrackVertexColor tracking) { if (tracking == TrackVertexColor.None) { var gt = Gl.GL_DIFFUSE; // There are actually 15 different combinations for tracking, of which // GL only supports the most used 5. This means that we have to do some // magic to find the best match. NOTE: // GL_AMBIENT_AND_DIFFUSE != GL_AMBIENT | GL__DIFFUSE if ((tracking & TrackVertexColor.Ambient) != 0) { if ((tracking & TrackVertexColor.Diffuse) != 0) { gt = Gl.GL_AMBIENT_AND_DIFFUSE; } else { gt = Gl.GL_AMBIENT; } } else if ((tracking & TrackVertexColor.Diffuse) != 0) { gt = Gl.GL_DIFFUSE; } else if ((tracking & TrackVertexColor.Specular) != 0) { gt = Gl.GL_SPECULAR; } else if ((tracking & TrackVertexColor.Emissive) != 0) { gt = Gl.GL_EMISSION; } Gl.glColorMaterial(Gl.GL_FRONT_AND_BACK, gt); Gl.glEnable(Gl.GL_COLOR_MATERIAL); } else { Gl.glDisable(Gl.GL_COLOR_MATERIAL); } var vals = _tempColorVals; diffuse.ToArrayRGBA( vals ); Gl.glMaterialfv(Gl.GL_FRONT_AND_BACK, Gl.GL_DIFFUSE, vals); ambient.ToArrayRGBA( vals ); Gl.glMaterialfv( Gl.GL_FRONT_AND_BACK, Gl.GL_AMBIENT, vals ); specular.ToArrayRGBA( vals ); Gl.glMaterialfv( Gl.GL_FRONT_AND_BACK, Gl.GL_SPECULAR, vals ); emissive.ToArrayRGBA(vals); Gl.glMaterialfv( Gl.GL_FRONT_AND_BACK, Gl.GL_EMISSION, vals ); Gl.glMaterialf( Gl.GL_FRONT_AND_BACK, Gl.GL_SHININESS, shininess ); }
/// <summary> /// /// </summary> /// <param name="ambient"></param> /// <param name="diffuse"></param> /// <param name="specular"></param> /// <param name="emissive"></param> /// <param name="shininess"></param> public override void SetSurfaceParams(ColorEx ambient, ColorEx diffuse, ColorEx specular, ColorEx emissive, float shininess, TrackVertexColor tracking) { // TODO: Cache color values to prune unneccessary setting if (cache.materialAmbient.CompareTo(ambient) == 0 && cache.materialDiffuse.CompareTo(diffuse) == 0 && cache.materialSpecular.CompareTo(specular) == 0 && cache.materialEmissive.CompareTo(emissive) == 0 && cache.materialShininess == shininess && cache.materialTracking == tracking) return; cache.materialAmbient = ambient.Clone(); cache.materialDiffuse = diffuse.Clone(); cache.materialSpecular = specular.Clone(); cache.materialEmissive = emissive.Clone(); cache.materialShininess = shininess; cache.materialTracking = tracking; // create a new material based on the supplied params D3D.Material mat = new D3D.Material(); mat.Diffuse = diffuse.ToColor(); mat.Ambient = ambient.ToColor(); mat.Specular = specular.ToColor(); mat.Emissive = emissive.ToColor(); mat.SpecularSharpness = shininess; // set the current material device.Material = mat; if (tracking != TrackVertexColor.None) { SetRenderState(ref cache.colorVertex, RenderStates.ColorVertex, true); device.SetRenderState(RenderStates.AmbientMaterialSource, (int)(((tracking & TrackVertexColor.Ambient) != 0) ? D3D.ColorSource.Color1 : D3D.ColorSource.Material)); device.SetRenderState(RenderStates.DiffuseMaterialSource, (int)(((tracking & TrackVertexColor.Diffuse) != 0) ? D3D.ColorSource.Color1 : D3D.ColorSource.Material)); device.SetRenderState(RenderStates.SpecularMaterialSource, (int)(((tracking & TrackVertexColor.Specular) != 0) ? D3D.ColorSource.Color1 : D3D.ColorSource.Material)); device.SetRenderState(RenderStates.EmissiveMaterialSource, (int)(((tracking & TrackVertexColor.Emissive) != 0) ? D3D.ColorSource.Color1 : D3D.ColorSource.Material)); } else SetRenderState(ref cache.colorVertex, RenderStates.ColorVertex, false); }