Cocos2d-lua 初識shader之五:定時器

在GLProgram::setUniformsForBuiltins函數中有下面代碼:


 
if(_flags.usesTime) {
    // This doesn't give the most accurate global time value.
    // Cocos2D doesn't store a high precision time value, so this will have to do.
    // Getting Mach time per frame per shader using time could be extremely expensive.
    float time = _director->getTotalFrames() * _director->getAnimationInterval();
        
    setUniformLocationWith4f(_builtInUniforms[GLProgram::UNIFORM_TIME], time/10.0, time, time*2, time*4);
    setUniformLocationWith4f(_builtInUniforms[GLProgram::UNIFORM_SIN_TIME], time/8.0, time/4.0, time/2.0, sinf(time));
    setUniformLocationWith4f(_builtInUniforms[GLProgram::UNIFORM_COS_TIME], time/8.0, time/4.0, time/2.0, cosf(time));
}


即Cocos在刷新時,已經將時間傳入進來了,可以在shader 中調用CC_Time,CC_SinTime和CC_CosTime這三個量來進行操作

屬性爲(x, y, z, w)

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章