SL-17282 prototype mixing of reflection map into legacy materials
parent
deffbca3ee
commit
93a0259666
|
|
@ -183,8 +183,7 @@ void LLCubeMap::initEnvironmentMap(const std::vector<LLPointer<LLImageRaw> >& ra
|
|||
llassert(rawimages[i]->getHeight() == resolution);
|
||||
llassert(rawimages[i]->getComponents() == components);
|
||||
|
||||
|
||||
mImages[i] = new LLImageGL(resolution, resolution, components, FALSE);
|
||||
mImages[i] = new LLImageGL(resolution, resolution, components, TRUE);
|
||||
mImages[i]->setTarget(mTargets[i], LLTexUnit::TT_CUBE_MAP);
|
||||
mRawImages[i] = rawimages[i];
|
||||
mImages[i]->createGLTexture(0, mRawImages[i], texname);
|
||||
|
|
@ -195,6 +194,11 @@ void LLCubeMap::initEnvironmentMap(const std::vector<LLPointer<LLImageRaw> >& ra
|
|||
|
||||
mImages[i]->setSubImage(mRawImages[i], 0, 0, resolution, resolution);
|
||||
}
|
||||
enableTexture(0);
|
||||
bind();
|
||||
mImages[0]->setFilteringOption(LLTexUnit::TFO_ANISOTROPIC);
|
||||
glEnable(GL_TEXTURE_CUBE_MAP_SEAMLESS);
|
||||
glGenerateMipmap(GL_TEXTURE_CUBE_MAP);
|
||||
gGL.getTexUnit(0)->disable();
|
||||
disable();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -832,6 +832,9 @@ BOOL LLGLSLShader::mapUniforms(const vector<LLStaticHashedString> * uniforms)
|
|||
|
||||
As example where this situation appear see: "Deferred Material Shader 28/29/30/31"
|
||||
And tickets: MAINT-4165, MAINT-4839, MAINT-3568, MAINT-6437
|
||||
|
||||
--- davep TODO -- pretty sure the entire block here is superstitious and that the uniform index has nothing to do with the texture channel
|
||||
texture channel should follow the uniform VALUE
|
||||
*/
|
||||
|
||||
|
||||
|
|
@ -840,6 +843,7 @@ BOOL LLGLSLShader::mapUniforms(const vector<LLStaticHashedString> * uniforms)
|
|||
S32 bumpMap = glGetUniformLocationARB(mProgramObject, "bumpMap");
|
||||
S32 altDiffuseMap = glGetUniformLocationARB(mProgramObject, "altDiffuseMap");
|
||||
S32 environmentMap = glGetUniformLocationARB(mProgramObject, "environmentMap");
|
||||
S32 reflectionMap = glGetUniformLocationARB(mProgramObject, "reflectionMap");
|
||||
|
||||
std::set<S32> skip_index;
|
||||
|
||||
|
|
@ -882,6 +886,12 @@ BOOL LLGLSLShader::mapUniforms(const vector<LLStaticHashedString> * uniforms)
|
|||
continue;
|
||||
}
|
||||
|
||||
if (-1 == reflectionMap && std::string(name) == "reflectionMap")
|
||||
{
|
||||
reflectionMap = i;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (-1 == altDiffuseMap && std::string(name) == "altDiffuseMap")
|
||||
{
|
||||
altDiffuseMap = i;
|
||||
|
|
@ -892,8 +902,9 @@ BOOL LLGLSLShader::mapUniforms(const vector<LLStaticHashedString> * uniforms)
|
|||
bool specularDiff = specularMap < diffuseMap && -1 != specularMap;
|
||||
bool bumpLessDiff = bumpMap < diffuseMap && -1 != bumpMap;
|
||||
bool envLessDiff = environmentMap < diffuseMap && -1 != environmentMap;
|
||||
bool refLessDiff = reflectionMap < diffuseMap && -1 != reflectionMap;
|
||||
|
||||
if (specularDiff || bumpLessDiff || envLessDiff)
|
||||
if (specularDiff || bumpLessDiff || envLessDiff || refLessDiff)
|
||||
{
|
||||
mapUniform(diffuseMap, uniforms);
|
||||
skip_index.insert(diffuseMap);
|
||||
|
|
@ -912,6 +923,11 @@ BOOL LLGLSLShader::mapUniforms(const vector<LLStaticHashedString> * uniforms)
|
|||
mapUniform(environmentMap, uniforms);
|
||||
skip_index.insert(environmentMap);
|
||||
}
|
||||
|
||||
if (-1 != reflectionMap) {
|
||||
mapUniform(reflectionMap, uniforms);
|
||||
skip_index.insert(reflectionMap);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1155,6 +1155,7 @@ void LLShaderMgr::initAttribsAndUniforms()
|
|||
mReservedUniforms.push_back("bumpMap");
|
||||
mReservedUniforms.push_back("bumpMap2");
|
||||
mReservedUniforms.push_back("environmentMap");
|
||||
mReservedUniforms.push_back("reflectionMap");
|
||||
mReservedUniforms.push_back("cloud_noise_texture");
|
||||
mReservedUniforms.push_back("cloud_noise_texture_next");
|
||||
mReservedUniforms.push_back("fullbright");
|
||||
|
|
|
|||
|
|
@ -80,6 +80,7 @@ public:
|
|||
BUMP_MAP, // "bumpMap"
|
||||
BUMP_MAP2, // "bumpMap2"
|
||||
ENVIRONMENT_MAP, // "environmentMap"
|
||||
REFLECTION_MAP, // "reflectionMap"
|
||||
CLOUD_NOISE_MAP, // "cloud_noise_texture"
|
||||
CLOUD_NOISE_MAP_NEXT, // "cloud_noise_texture_next"
|
||||
FULLBRIGHT, // "fullbright"
|
||||
|
|
|
|||
|
|
@ -36,7 +36,6 @@ out vec4 frag_color;
|
|||
uniform sampler2DRect depthMap;
|
||||
uniform sampler2DRect diffuseRect;
|
||||
uniform sampler2DRect specularRect;
|
||||
uniform samplerCube environmentMap;
|
||||
uniform sampler2D noiseMap;
|
||||
uniform sampler2D lightFunc;
|
||||
|
||||
|
|
|
|||
|
|
@ -42,7 +42,6 @@ uniform sampler2DRect diffuseRect;
|
|||
uniform sampler2DRect specularRect;
|
||||
uniform sampler2DRect depthMap;
|
||||
uniform sampler2DRect normalMap;
|
||||
uniform samplerCube environmentMap;
|
||||
uniform sampler2D noiseMap;
|
||||
uniform sampler2D projectionMap;
|
||||
uniform sampler2D lightFunc;
|
||||
|
|
|
|||
|
|
@ -36,7 +36,6 @@ out vec4 frag_color;
|
|||
uniform sampler2DRect diffuseRect;
|
||||
uniform sampler2DRect specularRect;
|
||||
uniform sampler2DRect normalMap;
|
||||
uniform samplerCube environmentMap;
|
||||
uniform sampler2D noiseMap;
|
||||
uniform sampler2D lightFunc;
|
||||
uniform sampler2DRect depthMap;
|
||||
|
|
|
|||
|
|
@ -40,6 +40,7 @@ uniform sampler2DRect normalMap;
|
|||
uniform sampler2DRect lightMap;
|
||||
uniform sampler2DRect depthMap;
|
||||
uniform samplerCube environmentMap;
|
||||
uniform samplerCube reflectionMap;
|
||||
uniform sampler2D lightFunc;
|
||||
|
||||
uniform float blur_size;
|
||||
|
|
@ -119,6 +120,8 @@ void main()
|
|||
|
||||
vec3 refnormpersp = normalize(reflect(pos.xyz, norm.xyz));
|
||||
|
||||
vec3 env_vec = env_mat * refnormpersp;
|
||||
|
||||
if (spec.a > 0.0) // specular reflection
|
||||
{
|
||||
float sa = dot(refnormpersp, light_dir.xyz);
|
||||
|
|
@ -128,13 +131,28 @@ void main()
|
|||
vec3 spec_contrib = dumbshiny * spec.rgb;
|
||||
bloom = dot(spec_contrib, spec_contrib) / 6;
|
||||
color.rgb += spec_contrib;
|
||||
|
||||
// add reflection map - EXPERIMENTAL WORK IN PROGRESS
|
||||
float reflection_lods = 11; // TODO -- base this on resolution of reflection map instead of hard coding
|
||||
float min_lod = textureQueryLod(reflectionMap,env_vec).y; // lower is higher res
|
||||
|
||||
//vec3 reflected_color = texture(reflectionMap, env_vec, (1.0-spec.a)*reflection_lod).rgb;
|
||||
vec3 reflected_color = textureLod(reflectionMap, env_vec, max(min_lod, (1.0-spec.a)*reflection_lods)).rgb;
|
||||
//vec3 reflected_color = texture(reflectionMap, env_vec).rgb;
|
||||
//vec3 reflected_color = normalize(env_vec)*0.5+0.5;
|
||||
reflected_color *= spec.rgb;
|
||||
vec3 mixer = clamp(color.rgb + vec3(1,1,1) - spec.rgb, vec3(0,0,0), vec3(1,1,1));
|
||||
|
||||
color.rgb = mix(reflected_color*sqrt(spec.a*0.8), color, mixer);
|
||||
|
||||
//color.rgb = mix(reflected_color * spec.rgb * sqrt(spec.a*0.8), color.rgb, color.rgb);
|
||||
//color.rgb += reflected_color * spec.rgb; // * sqrt(spec.a*0.8), color.rgb, color.rgb);
|
||||
}
|
||||
|
||||
color.rgb = mix(color.rgb, diffuse.rgb, diffuse.a);
|
||||
|
||||
if (envIntensity > 0.0)
|
||||
{ // add environmentmap
|
||||
vec3 env_vec = env_mat * refnormpersp;
|
||||
vec3 reflected_color = textureCube(environmentMap, env_vec).rgb;
|
||||
color = mix(color.rgb, reflected_color, envIntensity);
|
||||
}
|
||||
|
|
@ -154,5 +172,6 @@ void main()
|
|||
// convert to linear as fullscreen lights need to sum in linear colorspace
|
||||
// and will be gamma (re)corrected downstream...
|
||||
frag_color.rgb = srgb_to_linear(color.rgb);
|
||||
//frag_color.r = 1.0;
|
||||
frag_color.a = bloom;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -67,7 +67,7 @@ void LLEnvironmentMap::update(const LLVector3& origin, U32 resolution)
|
|||
LLVector3(0, -1, 0),
|
||||
LLVector3(0, 0, -1),
|
||||
LLVector3(0, 0, 1),
|
||||
LLVector3(0, 1, 0),
|
||||
LLVector3(0, -1, 0),
|
||||
LLVector3(0, -1, 0)
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -8188,24 +8188,42 @@ void LLPipeline::bindDeferredShader(LLGLSLShader& shader, LLRenderTarget* light_
|
|||
|
||||
stop_glerror();
|
||||
|
||||
bool setup_env_mat = false;
|
||||
channel = shader.enableTexture(LLShaderMgr::ENVIRONMENT_MAP, LLTexUnit::TT_CUBE_MAP);
|
||||
if (channel > -1)
|
||||
{
|
||||
LLCubeMap* cube_map = mEnvironmentMap.mCubeMap.notNull() ? mEnvironmentMap.mCubeMap : gSky.mVOSkyp ? gSky.mVOSkyp->getCubeMap() : NULL;
|
||||
LLCubeMap* cube_map = gSky.mVOSkyp ? gSky.mVOSkyp->getCubeMap() : NULL;
|
||||
if (cube_map)
|
||||
{
|
||||
setup_env_mat = true;
|
||||
cube_map->enable(channel);
|
||||
cube_map->bind();
|
||||
F32* m = gGLModelView;
|
||||
|
||||
F32 mat[] = { m[0], m[1], m[2],
|
||||
m[4], m[5], m[6],
|
||||
m[8], m[9], m[10] };
|
||||
|
||||
shader.uniformMatrix3fv(LLShaderMgr::DEFERRED_ENV_MAT, 1, TRUE, mat);
|
||||
}
|
||||
}
|
||||
|
||||
channel = shader.enableTexture(LLShaderMgr::REFLECTION_MAP, LLTexUnit::TT_CUBE_MAP);
|
||||
if (channel > -1)
|
||||
{
|
||||
LLCubeMap* cube_map = mEnvironmentMap.mCubeMap;
|
||||
if (cube_map)
|
||||
{
|
||||
setup_env_mat = true;
|
||||
cube_map->enable(channel);
|
||||
cube_map->bind();
|
||||
}
|
||||
}
|
||||
|
||||
if (setup_env_mat)
|
||||
{
|
||||
F32* m = gGLModelView;
|
||||
|
||||
F32 mat[] = { m[0], m[1], m[2],
|
||||
m[4], m[5], m[6],
|
||||
m[8], m[9], m[10] };
|
||||
|
||||
shader.uniformMatrix3fv(LLShaderMgr::DEFERRED_ENV_MAT, 1, TRUE, mat);
|
||||
}
|
||||
|
||||
if (gAtmosphere)
|
||||
{
|
||||
// bind precomputed textures necessary for calculating sun and sky luminance
|
||||
|
|
@ -9103,6 +9121,17 @@ void LLPipeline::unbindDeferredShader(LLGLSLShader &shader)
|
|||
cube_map->disable();
|
||||
}
|
||||
}
|
||||
|
||||
channel = shader.disableTexture(LLShaderMgr::REFLECTION_MAP, LLTexUnit::TT_CUBE_MAP);
|
||||
if (channel > -1)
|
||||
{
|
||||
LLCubeMap* cube_map = mEnvironmentMap.mCubeMap;
|
||||
if (cube_map)
|
||||
{
|
||||
cube_map->disable();
|
||||
}
|
||||
}
|
||||
|
||||
gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE);
|
||||
gGL.getTexUnit(0)->activate();
|
||||
shader.unbind();
|
||||
|
|
|
|||
Loading…
Reference in New Issue