public static D3D.TextureArgument ConvertEnum(LayerBlendSource blendSource) { D3D.TextureArgument d3dTexArg = 0; switch (blendSource) { case LayerBlendSource.Current: d3dTexArg = D3D.TextureArgument.Current; break; case LayerBlendSource.Texture: d3dTexArg = D3D.TextureArgument.TextureColor; break; case LayerBlendSource.Diffuse: d3dTexArg = D3D.TextureArgument.Diffuse; break; case LayerBlendSource.Specular: d3dTexArg = D3D.TextureArgument.Specular; break; case LayerBlendSource.Manual: d3dTexArg = D3D.TextureArgument.TFactor; break; } // end switch return(d3dTexArg); }
public static D3D9.TextureArgument ConvertEnum(LayerBlendSource lbs, bool perStageConstants) { switch (lbs) { case LayerBlendSource.Current: return(D3D9.TextureArgument.Current); case LayerBlendSource.Texture: return(D3D9.TextureArgument.Texture); case LayerBlendSource.Diffuse: return(D3D9.TextureArgument.Diffuse); case LayerBlendSource.Specular: return(D3D9.TextureArgument.Specular); case LayerBlendSource.Manual: return(perStageConstants ? D3D9.TextureArgument.Constant : D3D9.TextureArgument.TFactor); } return(0); }
public static D3D.TextureArgument ConvertEnum( LayerBlendSource blendSource ) { D3D.TextureArgument d3dTexArg = 0; switch ( blendSource ) { case LayerBlendSource.Current: d3dTexArg = D3D.TextureArgument.Current; break; case LayerBlendSource.Texture: d3dTexArg = D3D.TextureArgument.Texture; break; case LayerBlendSource.Diffuse: d3dTexArg = D3D.TextureArgument.Diffuse; break; case LayerBlendSource.Specular: d3dTexArg = D3D.TextureArgument.Specular; break; case LayerBlendSource.Manual: d3dTexArg = D3D.TextureArgument.TFactor; break; } // end switch return d3dTexArg; }
public static TextureArgument ConvertEnum(LayerBlendSource lbs, bool perStageConstants) { switch (lbs) { case LayerBlendSource.Current: return TextureArgument.Current; case LayerBlendSource.Texture: return TextureArgument.Texture; case LayerBlendSource.Diffuse: return TextureArgument.Diffuse; case LayerBlendSource.Specular: return TextureArgument.Specular; case LayerBlendSource.Manual: return perStageConstants ? TextureArgument.Constant : TextureArgument.TFactor; } return 0; }
/// <summary> /// Sets the alpha operation to be applied to this texture. /// </summary> /// <remarks> /// This works in exactly the same way as SetColorOperation, except /// that the effect is applied to the level of alpha (i.e. transparency) /// of the texture rather than its color. When the alpha of a texel (a pixel /// on a texture) is 1.0, it is opaque, wheras it is fully transparent if the /// alpha is 0.0. Please refer to the SetColorOperation method for more info. /// </remarks> /// <param name="operation">The operation to be used, e.g. modulate (multiply), add, subtract.</param> /// <param name="source1">The source of the first alpha value to the operation e.g. texture alpha.</param> /// <param name="source2">The source of the second alpha value to the operation e.g. current surface alpha.</param> /// <param name="arg1">Manually supplied alpha value (only required if source1 = LayerBlendSource.Manual).</param> /// <param name="arg2">Manually supplied alpha value (only required if source2 = LayerBlendSource.Manual).</param> /// <param name="blendFactor">Manually supplied 'blend' value - only required for operations /// which require manual blend e.g. LayerBlendOperationEx.BlendManual. /// </param> public void SetAlphaOperation( LayerBlendOperationEx operation, LayerBlendSource source1, LayerBlendSource source2, Real arg1, Real arg2, Real blendFactor ) { this.alphaBlendMode.operation = operation; this.alphaBlendMode.source1 = source1; this.alphaBlendMode.source2 = source2; this.alphaBlendMode.alphaArg1 = arg1; this.alphaBlendMode.alphaArg2 = arg2; this.alphaBlendMode.blendFactor = blendFactor; }
/// <summary> /// Overloaded method. /// </summary> /// <param name="operation">The operation to be used, e.g. modulate (multiply), add, subtract.</param> /// <param name="source1">The source of the first color to the operation e.g. texture color.</param> /// <param name="source2">The source of the second color to the operation e.g. current surface color.</param> /// <param name="arg1">Manually supplied color value (only required if source1 = Manual).</param> public void SetColorOperationEx( LayerBlendOperationEx operation, LayerBlendSource source1, LayerBlendSource source2, ColorEx arg1 ) { SetColorOperationEx( operation, source1, source2, arg1, ColorEx.White, 0.0f ); }
/// <summary> /// For setting advanced blending options. /// </summary> /// <remarks> /// This is an extended version of the <see cref="TextureUnitState.SetColorOperation"/> method which allows /// extremely detailed control over the blending applied between this and earlier layers. /// See the IMPORTANT note below about the issues between mulitpass and multitexturing that /// using this method can create. /// <p/> /// Texture color operations determine how the final color of the surface appears when /// rendered. Texture units are used to combine color values from various sources (ie. the /// diffuse color of the surface from lighting calculations, combined with the color of /// the texture). This method allows you to specify the 'operation' to be used, ie. the /// calculation such as adds or multiplies, and which values to use as arguments, such as /// a fixed value or a value from a previous calculation. /// <p/> /// The defaults for each layer are: /// <ul> /// <li>op = Modulate</li> /// <li>source1 = Texture</li> /// <li>source2 = Current</li> /// </ul> /// ie. each layer takes the color results of the previous layer, and multiplies them /// with the new texture being applied. Bear in mind that colors are RGB values from /// 0.0 - 1.0 so multiplying them together will result in values in the same range, /// 'tinted' by the multiply. Note however that a straight multiply normally has the /// effect of darkening the textures - for this reason there are brightening operations /// like ModulateX2. See the LayerBlendOperation and LayerBlendSource enumerated /// types for full details. /// <p/> /// Because of the limitations on some underlying APIs (Direct3D included) /// the Texture argument can only be used as the first argument, not the second. /// <p/> /// The final 3 parameters are only required if you decide to pass values manually /// into the operation, i.e. you want one or more of the inputs to the color calculation /// to come from a fixed value that you supply. Hence you only need to fill these in if /// you supply <code>Manual</code> to the corresponding source, or use the /// <code>BlendManual</code> operation. /// <p/> /// The engine tries to use multitexturing hardware to blend texture layers /// together. However, if it runs out of texturing units (e.g. 2 of a GeForce2, 4 on a /// GeForce3) it has to fall back on multipass rendering, i.e. rendering the same object /// multiple times with different textures. This is both less efficient and there is a smaller /// range of blending operations which can be performed. For this reason, if you use this method /// you MUST also call <see cref="TextureUnitState.SetColorOpMultipassFallback"/> to specify which effect you /// want to fall back on if sufficient hardware is not available. /// <p/> /// If you wish to avoid having to do this, use the simpler <see cref="TextureUnitState.SetColorOperation"/> method /// which allows less flexible blending options but sets up the multipass fallback automatically, /// since it only allows operations which have direct multipass equivalents. /// <p/> /// This has no effect in the programmable pipeline. /// </remarks> /// <param name="operation">The operation to be used, e.g. modulate (multiply), add, subtract.</param> /// <param name="source1">The source of the first color to the operation e.g. texture color.</param> /// <param name="source2">The source of the second color to the operation e.g. current surface color.</param> /// <param name="arg1">Manually supplied color value (only required if source1 = Manual).</param> /// <param name="arg2">Manually supplied color value (only required if source2 = Manual)</param> /// <param name="blendFactor"> /// Manually supplied 'blend' value - only required for operations /// which require manual blend e.g. LayerBlendOperationEx.BlendManual /// </param> public void SetColorOperationEx( LayerBlendOperationEx operation, LayerBlendSource source1, LayerBlendSource source2, ColorEx arg1, ColorEx arg2, float blendFactor ) { this.colorBlendMode.operation = operation; this.colorBlendMode.source1 = source1; this.colorBlendMode.source2 = source2; this.colorBlendMode.colorArg1 = arg1; this.colorBlendMode.colorArg2 = arg2; this.colorBlendMode.blendFactor = blendFactor; }
/// <summary> /// Overloaded method. /// </summary> public void SetAlphaOperation(LayerBlendOperationEx operation, LayerBlendSource source1, LayerBlendSource source2) { SetAlphaOperation(operation, source1, source2, 1.0f, 1.0f, 0.0f); }
/// <summary> /// Sets the alpha operation to be applied to this texture. /// </summary> /// <remarks> /// This works in exactly the same way as SetColorOperation, except /// that the effect is applied to the level of alpha (i.e. transparency) /// of the texture rather than its color. When the alpha of a texel (a pixel /// on a texture) is 1.0, it is opaque, wheras it is fully transparent if the /// alpha is 0.0. Please refer to the SetColorOperation method for more info. /// </remarks> /// <param name="operation">The operation to be used, e.g. modulate (multiply), add, subtract.</param> /// <param name="source1">The source of the first alpha value to the operation e.g. texture alpha.</param> /// <param name="source2">The source of the second alpha value to the operation e.g. current surface alpha.</param> /// <param name="arg1">Manually supplied alpha value (only required if source1 = LayerBlendSource.Manual).</param> /// <param name="arg2">Manually supplied alpha value (only required if source2 = LayerBlendSource.Manual).</param> /// <param name="blendFactor">Manually supplied 'blend' value - only required for operations /// which require manual blend e.g. LayerBlendOperationEx.BlendManual. /// </param> public void SetAlphaOperation(LayerBlendOperationEx operation, LayerBlendSource source1, LayerBlendSource source2, float arg1, float arg2, float blendFactor) { alphaBlendMode.operation = operation; alphaBlendMode.source1 = source1; alphaBlendMode.source2 = source2; alphaBlendMode.alphaArg1 = arg1; alphaBlendMode.alphaArg2 = arg2; alphaBlendMode.blendFactor = blendFactor; }
protected virtual void AddPSArgumentInvocations( Function psMain, Parameter arg, Parameter texel, int samplerIndex, LayerBlendSource blendSrc, ColorEx colorValue, Real alphaValue, bool isAlphaArgument, int groupOrder, ref int internalCounter ) { FunctionInvocation curFuncInvocation = null; switch ( blendSrc ) { case LayerBlendSource.Current: curFuncInvocation = new FunctionInvocation( FFPRenderState.FFPFuncAssign, groupOrder, internalCounter++ ); if ( samplerIndex == 0 ) { curFuncInvocation.PushOperand( this.psDiffuse, Operand.OpSemantic.In ); } else { curFuncInvocation.PushOperand( this.psOutDiffuse, Operand.OpSemantic.In ); } curFuncInvocation.PushOperand( arg, Operand.OpSemantic.Out ); psMain.AddAtomInstance( curFuncInvocation ); break; case LayerBlendSource.Texture: curFuncInvocation = new FunctionInvocation( FFPRenderState.FFPFuncAssign, groupOrder, internalCounter++ ); curFuncInvocation.PushOperand( texel, Operand.OpSemantic.In ); curFuncInvocation.PushOperand( arg, Operand.OpSemantic.Out ); psMain.AddAtomInstance( curFuncInvocation ); break; case LayerBlendSource.Specular: curFuncInvocation = new FunctionInvocation( FFPRenderState.FFPFuncAssign, groupOrder, internalCounter++ ); curFuncInvocation.PushOperand( this.psSpecular, Operand.OpSemantic.In ); curFuncInvocation.PushOperand( arg, Operand.OpSemantic.Out ); psMain.AddAtomInstance( curFuncInvocation ); break; case LayerBlendSource.Diffuse: curFuncInvocation = new FunctionInvocation( FFPRenderState.FFPFuncAssign, groupOrder, internalCounter++ ); curFuncInvocation.PushOperand( this.psDiffuse, Operand.OpSemantic.In ); curFuncInvocation.PushOperand( arg, Operand.OpSemantic.Out ); psMain.AddAtomInstance( curFuncInvocation ); break; case LayerBlendSource.Manual: curFuncInvocation = new FunctionInvocation( FFPRenderState.FFPFuncConstruct, groupOrder, internalCounter++ ); if ( isAlphaArgument ) { curFuncInvocation.PushOperand( ParameterFactory.CreateConstParamFloat( alphaValue ), Operand.OpSemantic.In ); } else { curFuncInvocation.PushOperand( ParameterFactory.CreateConstParamFloat( colorValue.r ), Operand.OpSemantic.In ); curFuncInvocation.PushOperand( ParameterFactory.CreateConstParamFloat( colorValue.g ), Operand.OpSemantic.In ); curFuncInvocation.PushOperand( ParameterFactory.CreateConstParamFloat( colorValue.b ), Operand.OpSemantic.In ); curFuncInvocation.PushOperand( ParameterFactory.CreateConstParamFloat( colorValue.a ), Operand.OpSemantic.In ); } curFuncInvocation.PushOperand( arg, Operand.OpSemantic.In ); psMain.AddAtomInstance( curFuncInvocation ); break; } }