Added fullbright shiny underwater shader.

This commit is contained in:
Shyotl
2011-05-18 17:00:44 -05:00
parent a4b7bbd031
commit 4663b605ef
5 changed files with 128 additions and 48 deletions

View File

@@ -226,7 +226,14 @@ BOOL LLShaderMgr::attachShaderFeatures(LLGLSLShader * shader)
else if (features->isFullbright)
{
if (features->hasWaterFog)
if (features->isShiny && features->hasWaterFog)
{
if (!shader->attachObject("lighting/lightFullbrightShinyWaterF.glsl"))
{
return FALSE;
}
}
else if (features->hasWaterFog)
{
if (!shader->attachObject("lighting/lightFullbrightWaterF.glsl"))
{

View File

@@ -152,12 +152,7 @@ void LLStandardBumpmap::addstandard()
// llinfos << "Loading bumpmap: " << bump_file << " from viewerart" << llendl;
gStandardBumpmapList[LLStandardBumpmap::sStandardBumpmapCount].mLabel = label;
gStandardBumpmapList[LLStandardBumpmap::sStandardBumpmapCount].mImage =
LLViewerTextureManager::getFetchedTexture(LLUUID(bump_image_id),
TRUE,
LLViewerTexture::BOOST_NONE,
LLViewerTexture::LOD_TEXTURE,
0,
0);
LLViewerTextureManager::getFetchedTexture(LLUUID(bump_image_id));
gStandardBumpmapList[LLStandardBumpmap::sStandardBumpmapCount].mImage->setBoostLevel(LLViewerTexture::BOOST_BUMP) ;
gStandardBumpmapList[LLStandardBumpmap::sStandardBumpmapCount].mImage->setLoadedCallback(LLBumpImageList::onSourceStandardLoaded, 0, TRUE, FALSE, NULL, NULL );
LLStandardBumpmap::sStandardBumpmapCount++;
@@ -342,30 +337,43 @@ void LLDrawPoolBump::beginShiny(bool invisible)
sVertexMask = VERTEX_MASK_SHINY | LLVertexBuffer::MAP_TEXCOORD0;
}
if (LLPipeline::sUnderWaterRender)
if (getVertexShaderLevel() > 0)
{
shader = &gObjectShinyWaterProgram;
if (LLPipeline::sUnderWaterRender)
{
shader = &gObjectShinyWaterProgram;
}
else
{
shader = &gObjectShinyProgram;
}
shader->bind();
}
else
{
shader = &gObjectShinyProgram;
shader = NULL;
}
bindCubeMap(shader, mVertexShaderLevel, diffuse_channel, cube_channel, invisible);
}
//static
void LLDrawPoolBump::bindCubeMap(LLGLSLShader* shader, S32 shader_level, S32& diffuse_channel, S32& cube_channel, bool invisible)
{
LLCubeMap* cube_map = gSky.mVOSkyp ? gSky.mVOSkyp->getCubeMap() : NULL;
if( cube_map )
{
if (!invisible && LLViewerShaderMgr::instance()->getVertexShaderLevel(LLViewerShaderMgr::SHADER_OBJECT) > 0 )
if (!invisible && shader )
{
LLMatrix4 mat;
mat.initRows(LLVector4(gGLModelView+0),
LLVector4(gGLModelView+4),
LLVector4(gGLModelView+8),
LLVector4(gGLModelView+12));
shader->bind();
LLVector3 vec = LLVector3(gShinyOrigin) * mat;
LLVector4 vec4(vec, gShinyOrigin.mV[3]);
shader->uniform4fv(LLViewerShaderMgr::SHINY_ORIGIN, 1, vec4.mV);
if (mVertexShaderLevel > 1)
if (shader_level > 1)
{
cube_map->setMatrix(1);
// Make sure that texture coord generation happens for tex unit 1, as that's the one we use for
@@ -427,22 +435,16 @@ void LLDrawPoolBump::renderShiny(bool invisible)
}
}
void LLDrawPoolBump::endShiny(bool invisible)
//static
void LLDrawPoolBump::unbindCubeMap(LLGLSLShader* shader, S32 shader_level, S32& diffuse_channel, S32& cube_channel, bool invisible)
{
LLFastTimer t(LLFastTimer::FTM_RENDER_SHINY);
if ((!invisible && !gPipeline.hasRenderBatches(LLRenderPass::PASS_SHINY))||
(invisible && !gPipeline.hasRenderBatches(LLRenderPass::PASS_INVISI_SHINY)))
{
return;
}
LLCubeMap* cube_map = gSky.mVOSkyp ? gSky.mVOSkyp->getCubeMap() : NULL;
if( cube_map )
{
cube_map->disable();
cube_map->restoreMatrix();
if (!invisible && mVertexShaderLevel > 1)
if (!invisible && shader_level > 1)
{
shader->disableTexture(LLViewerShaderMgr::ENVIRONMENT_MAP, LLTexUnit::TT_CUBE_MAP);
@@ -453,7 +455,6 @@ void LLDrawPoolBump::endShiny(bool invisible)
shader->disableTexture(LLViewerShaderMgr::DIFFUSE_MAP);
}
}
shader->unbind();
}
}
gGL.getTexUnit(diffuse_channel)->disable();
@@ -461,6 +462,22 @@ void LLDrawPoolBump::endShiny(bool invisible)
gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE);
gGL.getTexUnit(0)->setTextureBlendType(LLTexUnit::TB_MULT);
}
void LLDrawPoolBump::endShiny(bool invisible)
{
LLFastTimer t(LLFastTimer::FTM_RENDER_SHINY);
if ((!invisible && !gPipeline.hasRenderBatches(LLRenderPass::PASS_SHINY))||
(invisible && !gPipeline.hasRenderBatches(LLRenderPass::PASS_INVISI_SHINY)))
{
return;
}
unbindCubeMap(shader, mVertexShaderLevel, diffuse_channel, cube_channel, invisible);
if (shader)
{
shader->unbind();
}
diffuse_channel = -1;
cube_channel = 0;
@@ -481,7 +498,7 @@ void LLDrawPoolBump::beginFullbrightShiny()
if (LLPipeline::sUnderWaterRender)
{
shader = &gObjectShinyWaterProgram;
shader = &gObjectFullbrightShinyWaterProgram;
}
else
{
@@ -588,18 +605,37 @@ void LLDrawPoolBump::renderGroup(LLSpatialGroup* group, U32 type, U32 mask, BOOL
// static
BOOL LLDrawPoolBump::bindBumpMap(LLDrawInfo& params, S32 channel)
{
LLViewerTexture* bump = NULL;
U8 bump_code = params.mBump;
return bindBumpMap(bump_code, params.mTexture, params.mVSize, channel);
}
//static
BOOL LLDrawPoolBump::bindBumpMap(LLFace* face, S32 channel)
{
const LLTextureEntry* te = face->getTextureEntry();
if (te)
{
U8 bump_code = te->getBumpmap();
return bindBumpMap(bump_code, face->getTexture(), face->getVirtualSize(), channel);
}
return FALSE;
}
//static
BOOL LLDrawPoolBump::bindBumpMap(U8 bump_code, LLViewerTexture* texture, F32 vsize, S32 channel)
{
//Note: texture atlas does not support bump texture now.
LLViewerFetchedTexture* tex = LLViewerTextureManager::staticCastToFetchedTexture(params.mTexture) ;
LLViewerFetchedTexture* tex = LLViewerTextureManager::staticCastToFetchedTexture(texture) ;
if(!tex)
{
//if the texture is not a fetched texture
return FALSE;
}
LLViewerTexture* bump = NULL;
switch( bump_code )
{
case BE_NO_BUMP:
@@ -613,7 +649,7 @@ BOOL LLDrawPoolBump::bindBumpMap(LLDrawInfo& params, S32 channel)
if( bump_code < LLStandardBumpmap::sStandardBumpmapCount )
{
bump = gStandardBumpmapList[bump_code].mImage;
gBumpImageList.addTextureStats(bump_code, tex->getID(), params.mVSize);
gBumpImageList.addTextureStats(bump_code, tex->getID(), vsize);
}
break;
}
@@ -968,25 +1004,28 @@ LLViewerTexture* LLBumpImageList::getBrightnessDarknessImage(LLViewerFetchedText
}
bump_image_map_t::iterator iter = entries_list->find(src_image->getID());
if (iter != entries_list->end())
if (iter != entries_list->end() && iter->second.notNull())
{
bump = iter->second;
}
else
{
LLPointer<LLImageRaw> raw = new LLImageRaw(1,1,1);
raw->clear(0x77, 0x77, 0x77, 0xFF);
raw->clear(0x77, 0x77, 0xFF, 0xFF);
(*entries_list)[src_image->getID()] = LLViewerTextureManager::getLocalTexture( raw.get(), TRUE);
(*entries_list)[src_image->getID()]->setExplicitFormat(GL_ALPHA8, GL_ALPHA);
// Note: this may create an LLImageGL immediately
src_image->setBoostLevel(LLViewerTexture::BOOST_BUMP) ;
src_image->setLoadedCallback( callback_func, 0, TRUE, FALSE, new LLUUID(src_image->getID()), NULL );
bump = (*entries_list)[src_image->getID()]; // In case callback was called immediately and replaced the image
}
// bump_total++;
// llinfos << "*** Creating " << (void*)bump << " " << bump_total << llendl;
if (!src_image->hasCallbacks())
{ //if image has no callbacks but resolutions don't match, trigger raw image loaded callback again
if (src_image->getWidth() != bump->getWidth() ||
src_image->getHeight() != bump->getHeight() ||
(LLPipeline::sRenderDeferred && bump->getComponents() != 4))
{
src_image->setBoostLevel(LLViewerTexture::BOOST_BUMP) ;
src_image->setLoadedCallback( callback_func, 0, TRUE, FALSE, new LLUUID(src_image->getID()), NULL );
}
}
}
@@ -1089,7 +1128,21 @@ void LLBumpImageList::onSourceLoaded( BOOL success, LLViewerTexture *src_vi, LLI
{
bump_image_map_t& entries_list(bump_code == BE_BRIGHTNESS ? gBumpImageList.mBrightnessEntries : gBumpImageList.mDarknessEntries );
bump_image_map_t::iterator iter = entries_list.find(source_asset_id);
if (iter != entries_list.end())
if (iter == entries_list.end() ||
iter->second.isNull() ||
iter->second->getWidth() != src->getWidth() ||
iter->second->getHeight() != src->getHeight()) // bump not cached yet or has changed resolution
{ //make sure an entry exists for this image
LLPointer<LLImageRaw> raw = new LLImageRaw(1,1,1);
raw->clear(0x77, 0x77, 0xFF, 0xFF);
entries_list[src_vi->getID()] = LLViewerTextureManager::getLocalTexture( raw.get(), TRUE);
iter = entries_list.find(src_vi->getID());
}
//if (iter->second->getWidth() != src->getWidth() ||
// iter->second->getHeight() != src->getHeight()) // bump not cached yet or has changed resolution
{
LLPointer<LLImageRaw> dst_image = new LLImageRaw(src->getWidth(), src->getHeight(), 1);
U8* dst_data = dst_image->getData();
@@ -1216,18 +1269,10 @@ void LLBumpImageList::onSourceLoaded( BOOL success, LLViewerTexture *src_vi, LLI
bump->setExplicitFormat(GL_RGBA, GL_RGBA);
bump->createGLTexture(0, nrm_image);
}
iter->second = bump; // derefs (and deletes) old image
//---------------------------------------------------
}
else
{
// entry should have been added in LLBumpImageList::getImage().
// Not a legit assertion - the bump texture could have been flushed by the bump image manager
//llassert(0);
}
}
}

View File

@@ -41,6 +41,7 @@
class LLImageRaw;
class LLSpatialGroup;
class LLDrawInfo;
class LLGLSLShader;
class LLViewerFetchedTexture;
class LLDrawPoolBump : public LLRenderPass
@@ -79,6 +80,9 @@ public:
void renderBump(U32 pass = LLRenderPass::PASS_BUMP);
void endBump(U32 pass = LLRenderPass::PASS_BUMP);
static void bindCubeMap(LLGLSLShader* shader, S32 shader_level, S32& diffuse_channel, S32& cube_channel, bool invisible);
static void unbindCubeMap(LLGLSLShader* shader, S32 shader_level, S32& diffuse_channel, S32& cube_channel, bool invisible);
virtual S32 getNumDeferredPasses();
/*virtual*/ void beginDeferredPass(S32 pass);
/*virtual*/ void endDeferredPass(S32 pass);
@@ -89,7 +93,12 @@ public:
/*virtual*/ void endPostDeferredPass(S32 pass);
/*virtual*/ void renderPostDeferred(S32 pass);
BOOL bindBumpMap(LLDrawInfo& params, S32 channel = -2);
static BOOL bindBumpMap(LLDrawInfo& params, S32 channel = -2);
static BOOL bindBumpMap(LLFace* face, S32 channel = -2);
private:
static BOOL bindBumpMap(U8 bump_code, LLViewerTexture* tex, F32 vsize, S32 channel);
};
enum EBumpEffect

View File

@@ -79,6 +79,7 @@ LLGLSLShader gObjectFullbrightProgram(LLViewerShaderMgr::SHADER_OBJECT);
LLGLSLShader gObjectFullbrightWaterProgram(LLViewerShaderMgr::SHADER_OBJECT);
LLGLSLShader gObjectFullbrightShinyProgram(LLViewerShaderMgr::SHADER_OBJECT);
LLGLSLShader gObjectFullbrightShinyWaterProgram(LLViewerShaderMgr::SHADER_OBJECT);
LLGLSLShader gObjectShinyProgram(LLViewerShaderMgr::SHADER_OBJECT);
LLGLSLShader gObjectShinyWaterProgram(LLViewerShaderMgr::SHADER_OBJECT);
@@ -580,6 +581,7 @@ BOOL LLViewerShaderMgr::loadBasicShaders()
shaders.push_back( make_pair( "lighting/lightShinyF.glsl", mVertexShaderLevel[SHADER_LIGHTING] ) );
shaders.push_back( make_pair( "lighting/lightFullbrightShinyF.glsl", mVertexShaderLevel[SHADER_LIGHTING] ) );
shaders.push_back( make_pair( "lighting/lightShinyWaterF.glsl", mVertexShaderLevel[SHADER_LIGHTING] ) );
shaders.push_back( make_pair( "lighting/lightFullbrightShinyWaterF.glsl", mVertexShaderLevel[SHADER_LIGHTING] ) );
for (U32 i = 0; i < shaders.size(); i++)
{
@@ -1229,6 +1231,22 @@ BOOL LLViewerShaderMgr::loadShadersObject()
success = gObjectFullbrightShinyProgram.createShader(NULL, &mShinyUniforms);
}
if (success)
{
gObjectFullbrightShinyWaterProgram.mName = "Fullbright Shiny Water Shader";
gObjectFullbrightShinyWaterProgram.mFeatures.calculatesAtmospherics = true;
gObjectFullbrightShinyWaterProgram.mFeatures.isFullbright = true;
gObjectFullbrightShinyWaterProgram.mFeatures.isShiny = true;
gObjectFullbrightShinyWaterProgram.mFeatures.hasGamma = true;
gObjectFullbrightShinyWaterProgram.mFeatures.hasTransport = true;
gObjectFullbrightShinyWaterProgram.mFeatures.hasWaterFog = true;
gObjectFullbrightShinyWaterProgram.mShaderFiles.clear();
gObjectFullbrightShinyWaterProgram.mShaderFiles.push_back(make_pair("objects/fullbrightShinyV.glsl", GL_VERTEX_SHADER_ARB));
gObjectFullbrightShinyWaterProgram.mShaderFiles.push_back(make_pair("objects/fullbrightShinyWaterF.glsl", GL_FRAGMENT_SHADER_ARB));
gObjectFullbrightShinyWaterProgram.mShaderLevel = mVertexShaderLevel[SHADER_OBJECT];
gObjectFullbrightShinyWaterProgram.mShaderGroup = LLGLSLShader::SG_WATER;
success = gObjectFullbrightShinyWaterProgram.createShader(NULL, &mShinyUniforms);
}
if( !success )
{

View File

@@ -315,6 +315,7 @@ extern LLGLSLShader gObjectSimpleLODProgram;
extern LLGLSLShader gObjectFullbrightLODProgram;
extern LLGLSLShader gObjectFullbrightShinyProgram;
extern LLGLSLShader gObjectFullbrightShinyWaterProgram;
extern LLGLSLShader gObjectShinyProgram;
extern LLGLSLShader gObjectShinyWaterProgram;