diff options
Diffstat (limited to 'indra/newview')
-rw-r--r-- | indra/newview/CMakeLists.txt | 2 | ||||
-rw-r--r-- | indra/newview/app_settings/shaders/class1/deferred/multiPointLightF.glsl | 1 | ||||
-rw-r--r-- | indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl | 1 | ||||
-rw-r--r-- | indra/newview/app_settings/shaders/class1/deferred/pointLightF.glsl | 1 | ||||
-rw-r--r-- | indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl | 21 | ||||
-rw-r--r-- | indra/newview/llenvironmentmap.cpp | 116 | ||||
-rw-r--r-- | indra/newview/llenvironmentmap.h | 48 | ||||
-rw-r--r-- | indra/newview/llviewermenu.cpp | 8 | ||||
-rw-r--r-- | indra/newview/pipeline.cpp | 48 | ||||
-rw-r--r-- | indra/newview/pipeline.h | 4 | ||||
-rw-r--r-- | indra/newview/skins/default/xui/en/menu_viewer.xml | 7 |
11 files changed, 246 insertions, 11 deletions
diff --git a/indra/newview/CMakeLists.txt b/indra/newview/CMakeLists.txt index 964615320d..5e50f58595 100644 --- a/indra/newview/CMakeLists.txt +++ b/indra/newview/CMakeLists.txt @@ -196,6 +196,7 @@ set(viewer_SOURCE_FILES lldynamictexture.cpp llemote.cpp llenvironment.cpp + llenvironmentmap.cpp llestateinfomodel.cpp lleventnotifier.cpp lleventpoll.cpp @@ -832,6 +833,7 @@ set(viewer_HEADER_FILES lldynamictexture.h llemote.h llenvironment.h + llenvironmentmap.h llestateinfomodel.h lleventnotifier.h lleventpoll.h diff --git a/indra/newview/app_settings/shaders/class1/deferred/multiPointLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/multiPointLightF.glsl index 09c47165dd..0ae4bbfc5d 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/multiPointLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/multiPointLightF.glsl @@ -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; diff --git a/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl index ec3fb9c543..8dcc18080d 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl @@ -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; diff --git a/indra/newview/app_settings/shaders/class1/deferred/pointLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/pointLightF.glsl index 18616a9bb3..c1061f1933 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/pointLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/pointLightF.glsl @@ -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; diff --git a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl index 7700d16007..6958841d05 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl @@ -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; } diff --git a/indra/newview/llenvironmentmap.cpp b/indra/newview/llenvironmentmap.cpp new file mode 100644 index 0000000000..ee185d8ce7 --- /dev/null +++ b/indra/newview/llenvironmentmap.cpp @@ -0,0 +1,116 @@ +/** + * @file llenvironmentmap.cpp + * @brief LLEnvironmentMap class implementation + * + * $LicenseInfo:firstyear=2022&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2022, Linden Research, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License only. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA + * $/LicenseInfo$ + */ + +#include "llviewerprecompiledheaders.h" + +#include "llenvironmentmap.h" +#include "pipeline.h" +#include "llviewerwindow.h" + +LLEnvironmentMap::LLEnvironmentMap() +{ + mOrigin.setVec(0, 0, 0); +} + +void LLEnvironmentMap::update(const LLVector3& origin, U32 resolution) +{ + LL_PROFILE_ZONE_SCOPED_CATEGORY_DISPLAY; + + mOrigin = origin; + + // allocate images + std::vector<LLPointer<LLImageRaw> > rawimages; + rawimages.reserve(6); + + for (int i = 0; i < 6; ++i) + { + rawimages.push_back(new LLImageRaw(resolution, resolution, 3)); + } + + // ============== modified copy/paste of LLFloater360Capture::capture360Images() follows ============== + + // these are the 6 directions we will point the camera, see LLCubeMap::mTargets + LLVector3 look_dirs[6] = { + LLVector3(-1, 0, 0), + LLVector3(1, 0, 0), + LLVector3(0, -1, 0), + LLVector3(0, 1, 0), + LLVector3(0, 0, -1), + LLVector3(0, 0, 1) + }; + + LLVector3 look_upvecs[6] = { + LLVector3(0, -1, 0), + LLVector3(0, -1, 0), + LLVector3(0, 0, -1), + LLVector3(0, 0, 1), + LLVector3(0, -1, 0), + LLVector3(0, -1, 0) + }; + + // save current view/camera settings so we can restore them afterwards + S32 old_occlusion = LLPipeline::sUseOcclusion; + + // set new parameters specific to the 360 requirements + LLPipeline::sUseOcclusion = 0; + LLViewerCamera* camera = LLViewerCamera::getInstance(); + LLVector3 old_origin = camera->getOrigin(); + F32 old_fov = camera->getView(); + F32 old_aspect = camera->getAspect(); + F32 old_yaw = camera->getYaw(); + + // camera constants for the square, cube map capture image + camera->setAspect(1.0); // must set aspect ratio first to avoid undesirable clamping of vertical FoV + camera->setView(F_PI_BY_TWO); + camera->yaw(0.0); + camera->setOrigin(mOrigin); + + // for each of the 6 directions we shoot... + for (int i = 0; i < 6; i++) + { + // set up camera to look in each direction + camera->lookDir(look_dirs[i], look_upvecs[i]); + + // call the (very) simplified snapshot code that simply deals + // with a single image, no sub-images etc. but is very fast + gViewerWindow->simpleSnapshot(rawimages[i], + resolution, resolution, 1); + } + + // restore original view/camera/avatar settings settings + camera->setAspect(old_aspect); + camera->setView(old_fov); + camera->yaw(old_yaw); + camera->setOrigin(old_origin); + + LLPipeline::sUseOcclusion = old_occlusion; + + // ==================================================== + + mCubeMap = new LLCubeMap(false); + mCubeMap->initEnvironmentMap(rawimages); +} + diff --git a/indra/newview/llenvironmentmap.h b/indra/newview/llenvironmentmap.h new file mode 100644 index 0000000000..7d951eb678 --- /dev/null +++ b/indra/newview/llenvironmentmap.h @@ -0,0 +1,48 @@ +/** + * @file llenvironmentmap.h + * @brief LLEnvironmentMap class declaration + * + * $LicenseInfo:firstyear=2022&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2022, Linden Research, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License only. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA + * $/LicenseInfo$ + */ + +#pragma once + +#include "llcubemap.h" + +class LLEnvironmentMap +{ +public: + // allocate an environment map of the given resolution + LLEnvironmentMap(); + + // update this environment map + // origin - position in agent space to generate environment map from in agent space + // resolution - size of cube map to generate + void update(const LLVector3& origin, U32 resolution); + + // cube map used to sample this environment map + LLPointer<LLCubeMap> mCubeMap; + + // point at which environment map was generated from (in agent space) + LLVector3 mOrigin; +}; + diff --git a/indra/newview/llviewermenu.cpp b/indra/newview/llviewermenu.cpp index e3de4267dc..f5ea060e82 100644 --- a/indra/newview/llviewermenu.cpp +++ b/indra/newview/llviewermenu.cpp @@ -8304,6 +8304,12 @@ void handle_cache_clear_immediately() LLNotificationsUtil::add("ConfirmClearCache", LLSD(), LLSD(), callback_clear_cache_immediately); } +void handle_override_environment_map() +{ + gPipeline.overrideEnvironmentMap(); +} + + void handle_web_content_test(const LLSD& param) { std::string url = param.asString(); @@ -9402,6 +9408,8 @@ void initialize_menus() view_listener_t::addMenu(new LLDevelopTextureFetchDebugger(), "Develop.SetTexFetchDebugger"); //Develop (clear cache immediately) commit.add("Develop.ClearCache", boost::bind(&handle_cache_clear_immediately) ); + //Develop (override environment map) + commit.add("Develop.OverrideEnvironmentMap", boost::bind(&handle_override_environment_map)); // Admin >Object view_listener_t::addMenu(new LLAdminForceTakeCopy(), "Admin.ForceTakeCopy"); diff --git a/indra/newview/pipeline.cpp b/indra/newview/pipeline.cpp index 20d6fe39e3..ac7276e1e0 100644 --- a/indra/newview/pipeline.cpp +++ b/indra/newview/pipeline.cpp @@ -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 = 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(); @@ -11467,3 +11496,8 @@ void LLPipeline::restoreHiddenObject( const LLUUID& id ) } } +void LLPipeline::overrideEnvironmentMap() +{ + mEnvironmentMap.update(LLViewerCamera::instance().getOrigin(), 1024); +} + diff --git a/indra/newview/pipeline.h b/indra/newview/pipeline.h index 62d3ae7a39..150d3c7d58 100644 --- a/indra/newview/pipeline.h +++ b/indra/newview/pipeline.h @@ -38,6 +38,7 @@ #include "llgl.h" #include "lldrawable.h" #include "llrendertarget.h" +#include "llenvironmentmap.h" #include <stack> @@ -426,6 +427,9 @@ public: void hideObject( const LLUUID& id ); void restoreHiddenObject( const LLUUID& id ); + LLEnvironmentMap mEnvironmentMap; + void overrideEnvironmentMap(); + private: void unloadShaders(); void addToQuickLookup( LLDrawPool* new_poolp ); diff --git a/indra/newview/skins/default/xui/en/menu_viewer.xml b/indra/newview/skins/default/xui/en/menu_viewer.xml index 8d7cfe1116..db4e794ed4 100644 --- a/indra/newview/skins/default/xui/en/menu_viewer.xml +++ b/indra/newview/skins/default/xui/en/menu_viewer.xml @@ -3250,6 +3250,13 @@ function="World.EnvPreset" function="ToggleControl" parameter="RenderHoverGlowEnable" /> </menu_item_check> + <menu_item_call + enabled="true" + label="Override Environment Map" + name="Override Environment Map"> + <menu_item_call.on_click + function="Develop.OverrideEnvironmentMap" /> + </menu_item_call> <menu_item_separator /> <menu_item_call |