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); }