//----------------------------------------------------------------------- bool FFPTexturing::addPSFunctionInvocations(TextureUnitParams* textureUnitParams, Function* psMain, int& internalCounter) { const LayerBlendModeEx& colourBlend = textureUnitParams->mTextureUnitState->getColourBlendMode(); const LayerBlendModeEx& alphaBlend = textureUnitParams->mTextureUnitState->getAlphaBlendMode(); ParameterPtr source1; ParameterPtr source2; int groupOrder = FFP_PS_TEXTURING; // Add texture sampling code. ParameterPtr texel = psMain->resolveLocalParameter(Parameter::SPS_UNKNOWN, 0, "texel", GCT_FLOAT4); FunctionInvocation* curFuncInvocation = NULL; if (textureUnitParams->mTexCoordCalcMethod == TEXCALC_PROJECTIVE_TEXTURE) curFuncInvocation = OGRE_NEW FunctionInvocation(FFP_FUNC_SAMPLE_TEXTURE_PROJ, groupOrder, internalCounter++); else curFuncInvocation = OGRE_NEW FunctionInvocation(FFP_FUNC_SAMPLE_TEXTURE, groupOrder, internalCounter++); curFuncInvocation->pushOperand(textureUnitParams->mTextureSampler, Operand::OPS_IN); curFuncInvocation->pushOperand(textureUnitParams->mPSInputTexCoord, Operand::OPS_IN); curFuncInvocation->pushOperand(texel, Operand::OPS_OUT); psMain->addAtomInstace(curFuncInvocation); // Build colour argument for source1. source1 = psMain->resolveLocalParameter(Parameter::SPS_UNKNOWN, 0, "source1", GCT_FLOAT4); addPSArgumentInvocations(psMain, source1, texel, textureUnitParams->mTextureSamplerIndex, colourBlend.source1, colourBlend.colourArg1, colourBlend.alphaArg1, false, groupOrder, internalCounter); // Build colour argument for source2. source2 = psMain->resolveLocalParameter(Parameter::SPS_UNKNOWN, 0, "source2", GCT_FLOAT4); addPSArgumentInvocations(psMain, source2, texel, textureUnitParams->mTextureSamplerIndex, colourBlend.source2, colourBlend.colourArg2, colourBlend.alphaArg2, false, groupOrder, internalCounter); bool needDifferentAlphaBlend = false; if (alphaBlend.operation != colourBlend.operation || alphaBlend.source1 != colourBlend.source1 || alphaBlend.source2 != colourBlend.source2 || colourBlend.source1 == LBS_MANUAL || colourBlend.source2 == LBS_MANUAL || alphaBlend.source1 == LBS_MANUAL || alphaBlend.source2 == LBS_MANUAL) needDifferentAlphaBlend = true; // Build colours blend addPSBlendInvocations(psMain, source1, source2, texel, textureUnitParams->mTextureSamplerIndex, colourBlend, groupOrder, internalCounter, needDifferentAlphaBlend ? (Operand::OPM_X | Operand::OPM_Y | Operand::OPM_Z ) : Operand::OPM_ALL); // Case we need different alpha channel code. if (needDifferentAlphaBlend) { // Build alpha argument for source1. addPSArgumentInvocations(psMain, source1, texel, textureUnitParams->mTextureSamplerIndex, alphaBlend.source1, alphaBlend.colourArg1, alphaBlend.alphaArg1, true, groupOrder, internalCounter); // Build alpha argument for source2. addPSArgumentInvocations(psMain, source2, texel, textureUnitParams->mTextureSamplerIndex, alphaBlend.source2, alphaBlend.colourArg2, alphaBlend.alphaArg2, true, groupOrder, internalCounter); // Build alpha blend addPSBlendInvocations(psMain, source1, source2, texel, textureUnitParams->mTextureSamplerIndex, alphaBlend, groupOrder, internalCounter, Operand::OPM_W); } return true; }
//----------------------------------------------------------------------- bool FFPTexturing::addPSFunctionInvocations(TextureUnitParams* textureUnitParams, Function* psMain, int& internalCounter) { const LayerBlendModeEx& colourBlend = textureUnitParams->mTextureUnitState->getColourBlendMode(); const LayerBlendModeEx& alphaBlend = textureUnitParams->mTextureUnitState->getAlphaBlendMode(); ParameterPtr source1; ParameterPtr source2; int groupOrder = FFP_PS_TEXTURING; // Add texture sampling code. ParameterPtr texel = psMain->resolveLocalParameter(Parameter::SPS_UNKNOWN, 0, c_ParamTexelEx + StringConverter::toString(textureUnitParams->mTextureSamplerIndex), GCT_FLOAT4); addPSSampleTexelInvocation(textureUnitParams, psMain, texel, FFP_PS_SAMPLING, internalCounter); // Build colour argument for source1. source1 = psMain->resolveLocalParameter(Parameter::SPS_UNKNOWN, 0, "source1", GCT_FLOAT4); addPSArgumentInvocations(psMain, source1, texel, textureUnitParams->mTextureSamplerIndex, colourBlend.source1, colourBlend.colourArg1, colourBlend.alphaArg1, false, groupOrder, internalCounter); // Build colour argument for source2. source2 = psMain->resolveLocalParameter(Parameter::SPS_UNKNOWN, 0, "source2", GCT_FLOAT4); addPSArgumentInvocations(psMain, source2, texel, textureUnitParams->mTextureSamplerIndex, colourBlend.source2, colourBlend.colourArg2, colourBlend.alphaArg2, false, groupOrder, internalCounter); bool needDifferentAlphaBlend = false; if (alphaBlend.operation != colourBlend.operation || alphaBlend.source1 != colourBlend.source1 || alphaBlend.source2 != colourBlend.source2 || colourBlend.source1 == LBS_MANUAL || colourBlend.source2 == LBS_MANUAL || alphaBlend.source1 == LBS_MANUAL || alphaBlend.source2 == LBS_MANUAL) needDifferentAlphaBlend = true; // Build colours blend addPSBlendInvocations(psMain, source1, source2, texel, textureUnitParams->mTextureSamplerIndex, colourBlend, groupOrder, internalCounter, needDifferentAlphaBlend ? (Operand::OPM_X | Operand::OPM_Y | Operand::OPM_Z ) : Operand::OPM_ALL); // Case we need different alpha channel code. if (needDifferentAlphaBlend) { // Build alpha argument for source1. addPSArgumentInvocations(psMain, source1, texel, textureUnitParams->mTextureSamplerIndex, alphaBlend.source1, alphaBlend.colourArg1, alphaBlend.alphaArg1, true, groupOrder, internalCounter); // Build alpha argument for source2. addPSArgumentInvocations(psMain, source2, texel, textureUnitParams->mTextureSamplerIndex, alphaBlend.source2, alphaBlend.colourArg2, alphaBlend.alphaArg2, true, groupOrder, internalCounter); // Build alpha blend addPSBlendInvocations(psMain, source1, source2, texel, textureUnitParams->mTextureSamplerIndex, alphaBlend, groupOrder, internalCounter, Operand::OPM_W); } return true; }