protected internal override bool OnApply() { this.dirtyFlags = EffectHelpers.SetWorldViewProjAndFog(this.dirtyFlags, ref this.world, ref this.view, ref this.projection, ref this.worldView, this.fogEnabled, this.fogStart, this.fogEnd, this.worldViewProjParam, this.fogVectorParam); if ((this.dirtyFlags & EffectDirtyFlags.MaterialColor) != ~EffectDirtyFlags.All) { EffectHelpers.SetMaterialColor(this.lightingEnabled, this.alpha, ref this.diffuseColor, ref this.emissiveColor, ref this.ambientLightColor, this.diffuseColorParam, this.emissiveColorParam); this.dirtyFlags &= ~EffectDirtyFlags.MaterialColor; } if (this.lightingEnabled) { this.dirtyFlags = EffectHelpers.SetLightingMatrices(this.dirtyFlags, ref this.world, ref this.view, this.worldParam, this.worldInverseTransposeParam, this.eyePositionParam); bool flag = !this.light1.Enabled && !this.light2.Enabled; if (this.oneLight != flag) { this.oneLight = flag; this.dirtyFlags |= EffectDirtyFlags.ShaderIndex; } } if ((this.dirtyFlags & EffectDirtyFlags.ShaderIndex) != ~EffectDirtyFlags.All) { int num = 0; if (!this.fogEnabled) { ++num; } if (this.vertexColorEnabled) { num += 2; } if (this.textureEnabled) { num += 4; } if (this.lightingEnabled) { if (this.preferPerPixelLighting) { num += 24; } else if (this.oneLight) { num += 16; } else { num += 8; } } this.dirtyFlags &= ~EffectDirtyFlags.ShaderIndex; if (this._shaderIndex != num) { this._shaderIndex = num; this.CurrentTechnique = this.Techniques[this._shaderIndex]; return(true); } } return(false); }
/// <summary> /// Lazily computes derived parameter values immediately before applying the effect. /// </summary> protected internal override void OnApply() { // Recompute the world+view+projection matrix or fog vector? dirtyFlags = EffectHelpers.SetWorldViewProjAndFog(dirtyFlags, ref world, ref view, ref projection, ref worldView, fogEnabled, fogStart, fogEnd, worldViewProjParam, fogVectorParam); // Recompute the world inverse transpose and eye position? dirtyFlags = EffectHelpers.SetLightingMatrices(dirtyFlags, ref world, ref view, worldParam, worldInverseTransposeParam, eyePositionParam); // Recompute the diffuse/emissive/alpha material color parameters? if ((dirtyFlags & EffectDirtyFlags.MaterialColor) != 0) { EffectHelpers.SetMaterialColor(true, alpha, ref diffuseColor, ref emissiveColor, ref ambientLightColor, diffuseColorParam, emissiveColorParam); dirtyFlags &= ~EffectDirtyFlags.MaterialColor; } // Check if we can use the only-bother-with-the-first-light shader optimization. bool newOneLight = !light1.Enabled && !light2.Enabled; if (oneLight != newOneLight) { oneLight = newOneLight; dirtyFlags |= EffectDirtyFlags.ShaderIndex; } // Recompute the shader index? if ((dirtyFlags & EffectDirtyFlags.ShaderIndex) != 0) { int shaderIndex = 0; if (!fogEnabled) { shaderIndex += 1; } if (weightsPerVertex == 2) { shaderIndex += 2; } else if (weightsPerVertex == 4) { shaderIndex += 4; } if (preferPerPixelLighting) { shaderIndex += 12; } else if (oneLight) { shaderIndex += 6; } shaderIndexParam.SetValue(shaderIndex); dirtyFlags &= ~EffectDirtyFlags.ShaderIndex; } }
/// <summary> /// Lazily computes derived parameter values immediately before applying the effect. /// </summary> protected internal override bool OnApply() { // Recompute the world+view+projection matrix or fog vector? dirtyFlags = EffectHelpers.SetWorldViewProjAndFog(dirtyFlags, ref world, ref view, ref projection, ref worldView, fogEnabled, fogStart, fogEnd, worldViewProjParam, fogVectorParam); // Recompute the world inverse transpose and eye position? dirtyFlags = EffectHelpers.SetLightingMatrices(dirtyFlags, ref world, ref view, worldParam, worldInverseTransposeParam, eyePositionParam); // Recompute the diffuse/emissive/alpha material color parameters? if ((dirtyFlags & EffectDirtyFlags.MaterialColor) != 0) { EffectHelpers.SetMaterialColor(true, alpha, ref diffuseColor, ref emissiveColor, ref ambientLightColor, diffuseColorParam, emissiveColorParam); dirtyFlags &= ~EffectDirtyFlags.MaterialColor; } // Check if we can use the only-bother-with-the-first-light shader optimization. bool newOneLight = !light1.Enabled && !light2.Enabled; if (oneLight != newOneLight) { oneLight = newOneLight; dirtyFlags |= EffectDirtyFlags.ShaderIndex; } // Recompute the shader index? if ((dirtyFlags & EffectDirtyFlags.ShaderIndex) != 0) { int shaderIndex = 0; if (!fogEnabled) { shaderIndex += 1; } if (fresnelEnabled) { shaderIndex += 2; } if (specularEnabled) { shaderIndex += 4; } if (oneLight) { shaderIndex += 8; } dirtyFlags &= ~EffectDirtyFlags.ShaderIndex; if (_shaderIndex != shaderIndex) { _shaderIndex = shaderIndex; CurrentTechnique = Techniques[_shaderIndex]; return(true); } } return(false); }
/// <summary> /// Lazily computes derived parameter values immediately before applying the effect. /// </summary> protected internal override void OnApply() { // Recompute the shader index? // if ((dirtyFlags & EffectDirtyFlags.ShaderIndex) != 0) { int shaderIndex = 0; if (!fogEnabled) { shaderIndex += 1; } if (vertexColorEnabled) { shaderIndex += 2; } if (textureEnabled) { shaderIndex += 4; } if (lightingEnabled) { if (preferPerPixelLighting) { shaderIndex += 24; } else if (oneLight) { shaderIndex += 16; } else { shaderIndex += 8; } } // // //shaderIndexParam.SetValue (shaderIndex); // // dirtyFlags &= ~EffectDirtyFlags.ShaderIndex; if (oldIndex != shaderIndex) { int vertexShader = VSArray[VSIndices[shaderIndex]]; int fragmentShader = PSArray[PSIndices[shaderIndex]]; UpdateTechnique("BasicEffect", "", vertexShader, fragmentShader); oldIndex = shaderIndex; // Update here } // } // These are the states that work GLStateManager.Projection(Projection); GLStateManager.WorldView(world, view); // Override this for now for testing purposes dirtyFlags |= EffectDirtyFlags.World | EffectDirtyFlags.WorldViewProj; dirtyFlags |= EffectDirtyFlags.WorldViewProj | EffectDirtyFlags.EyePosition; dirtyFlags &= ~EffectDirtyFlags.FogEnable; // turn off fog for now dirtyFlags |= EffectDirtyFlags.MaterialColor; GLStateManager.Textures2D(TextureEnabled); GLStateManager.ColorArray(VertexColorEnabled); // Recompute the world+view+projection matrix or fog vector? dirtyFlags = EffectHelpers.SetWorldViewProjAndFog(dirtyFlags, ref world, ref view, ref projection, ref worldView, fogEnabled, fogStart, fogEnd, worldViewProjParam, fogVectorParam); // Recompute the diffuse/emissive/alpha material color parameters? if ((dirtyFlags & EffectDirtyFlags.MaterialColor) != 0) { EffectHelpers.SetMaterialColor(lightingEnabled, alpha, ref diffuseColor, ref emissiveColor, ref ambientLightColor, diffuseColorParam, emissiveColorParam); dirtyFlags &= ~EffectDirtyFlags.MaterialColor; } if (TextureEnabled) { _texture.Apply(); textureParam.SetValue(_texture); //System.Console.WriteLine("Texture set"); } // // if (lightingEnabled) { // // Recompute the world inverse transpose and eye position? // dirtyFlags = EffectHelpers.SetLightingMatrices (dirtyFlags, ref world, ref view, worldParam, worldInverseTransposeParam, eyePositionParam); // // // Check if we can use the only-bother-with-the-first-light shader optimization. // bool newOneLight = !light1.Enabled && !light2.Enabled; // // if (oneLight != newOneLight) { // oneLight = newOneLight; // dirtyFlags |= EffectDirtyFlags.ShaderIndex; // } // } }