diff options
Diffstat (limited to 'indra/newview/pipeline.cpp')
-rw-r--r-- | indra/newview/pipeline.cpp | 195 |
1 files changed, 69 insertions, 126 deletions
diff --git a/indra/newview/pipeline.cpp b/indra/newview/pipeline.cpp index a3c15442ad..e80b5cc9ef 100644 --- a/indra/newview/pipeline.cpp +++ b/indra/newview/pipeline.cpp @@ -116,6 +116,8 @@ #include "llenvironment.h" +#pragma optimize("", off) + #ifdef _DEBUG // Debug indices is disabled for now for debug performance - djs 4/24/02 //#define DEBUG_INDICES @@ -298,62 +300,6 @@ void drawBoxOutline(const LLVector3& pos, const LLVector3& size); U32 nhpo2(U32 v); LLVertexBuffer* ll_create_cube_vb(U32 type_mask, U32 usage); -glh::matrix4f glh_copy_matrix(F32* src) -{ - glh::matrix4f ret; - ret.set_value(src); - return ret; -} - -glh::matrix4f glh_get_current_modelview() -{ - return glh_copy_matrix(gGLModelView); -} - -glh::matrix4f glh_get_current_projection() -{ - return glh_copy_matrix(gGLProjection); -} - -glh::matrix4f glh_get_last_modelview() -{ - return glh_copy_matrix(gGLLastModelView); -} - -glh::matrix4f glh_get_last_projection() -{ - return glh_copy_matrix(gGLLastProjection); -} - -void glh_copy_matrix(const glh::matrix4f& src, F32* dst) -{ - for (U32 i = 0; i < 16; i++) - { - dst[i] = src.m[i]; - } -} - -void glh_set_current_modelview(const glh::matrix4f& mat) -{ - glh_copy_matrix(mat, gGLModelView); -} - -void glh_set_current_projection(glh::matrix4f& mat) -{ - glh_copy_matrix(mat, gGLProjection); -} - -glh::matrix4f gl_ortho(GLfloat left, GLfloat right, GLfloat bottom, GLfloat top, GLfloat znear, GLfloat zfar) -{ - glh::matrix4f ret( - 2.f/(right-left), 0.f, 0.f, -(right+left)/(right-left), - 0.f, 2.f/(top-bottom), 0.f, -(top+bottom)/(top-bottom), - 0.f, 0.f, -2.f/(zfar-znear), -(zfar+znear)/(zfar-znear), - 0.f, 0.f, 0.f, 1.f); - - return ret; -} - void display_update_camera(); //---------------------------------------- @@ -983,7 +929,7 @@ bool LLPipeline::allocateScreenBuffer(U32 resX, U32 resY, U32 samples) for (U32 i = 0; i < 4; i++) { if (!mShadow[i].allocate(sun_shadow_map_width,U32(resY*scale), 0, TRUE, FALSE, LLTexUnit::TT_TEXTURE)) return false; - if (!mShadowOcclusion[i].allocate(mShadow[i].getWidth()/occlusion_divisor, mShadow[i].getHeight()/occlusion_divisor, 0, TRUE, FALSE, LLTexUnit::TT_TEXTURE)) return false; + if (!mShadowOcclusion[i].allocate(mShadow[i].getWidth()/occlusion_divisor, mShadow[i].getHeight()/occlusion_divisor, 0, TRUE, FALSE, LLTexUnit::TT_TEXTURE)) return false; } } else @@ -1445,9 +1391,9 @@ bool LLPipeline::canUseVertexShaders() bool LLPipeline::canUseWindLightShaders() const { - return (!LLPipeline::sDisableShaders && - gWLSkyProgram.mProgramObject != 0 && - LLViewerShaderMgr::instance()->getVertexShaderLevel(LLViewerShaderMgr::SHADER_WINDLIGHT) > 1); + bool usingWindlight = LLViewerShaderMgr::instance()->getVertexShaderLevel(LLViewerShaderMgr::SHADER_WINDLIGHT) > 1; + bool haveShaders = ((gWLSkyProgram.mProgramObject != 0) || (gDeferredWLSkyProgram.mProgramObject != 0)); + return (!LLPipeline::sDisableShaders && haveShaders && usingWindlight); } bool LLPipeline::canUseWindLightShadersOnObjects() const @@ -2201,7 +2147,7 @@ void check_references(LLSpatialGroup* group, LLFace* face) void LLPipeline::checkReferences(LLFace* face) { -#if 0 +#if CHECK_PIPELINE_REFERENCES if (sCull) { for (LLCullResult::sg_iterator iter = sCull->beginVisibleGroups(); iter != sCull->endVisibleGroups(); ++iter) @@ -2233,7 +2179,7 @@ void LLPipeline::checkReferences(LLFace* face) void LLPipeline::checkReferences(LLDrawable* drawable) { -#if 0 +#if CHECK_PIPELINE_REFERENCES if (sCull) { for (LLCullResult::sg_iterator iter = sCull->beginVisibleGroups(); iter != sCull->endVisibleGroups(); ++iter) @@ -2284,7 +2230,7 @@ void check_references(LLSpatialGroup* group, LLDrawInfo* draw_info) void LLPipeline::checkReferences(LLDrawInfo* draw_info) { -#if 0 +#if CHECK_PIPELINE_REFERENCES if (sCull) { for (LLCullResult::sg_iterator iter = sCull->beginVisibleGroups(); iter != sCull->endVisibleGroups(); ++iter) @@ -2310,7 +2256,7 @@ void LLPipeline::checkReferences(LLDrawInfo* draw_info) void LLPipeline::checkReferences(LLSpatialGroup* group) { -#if 0 +#if CHECK_PIPELINE_REFERENCES if (sCull) { for (LLCullResult::sg_iterator iter = sCull->beginVisibleGroups(); iter != sCull->endVisibleGroups(); ++iter) @@ -2483,8 +2429,8 @@ void LLPipeline::updateCull(LLCamera& camera, LLCullResult& result, S32 water_cl } } - glh::matrix4f modelview = glh_get_last_modelview(); - glh::matrix4f proj = glh_get_last_projection(); + glh::matrix4f modelview = get_last_modelview(); + glh::matrix4f proj = get_last_projection(); LLGLUserClipPlane clip(plane, modelview, proj, water_clip != 0 && LLPipeline::sReflectionRender); LLGLDepthTest depth(GL_TRUE, GL_FALSE); @@ -6075,8 +6021,9 @@ void LLPipeline::setupAvatarLights(bool for_edit) } else if (gAvatarBacklight) // Always true (unless overridden in a devs .ini) { - LLVector3 opposite_pos = -1.f * mSunDir; - LLVector3 orthog_light_pos = mSunDir % LLVector3::z_axis; + LLVector3 sun_dir = LLVector3(mSunDir); + LLVector3 opposite_pos = -sun_dir; + LLVector3 orthog_light_pos = sun_dir % LLVector3::z_axis; LLVector4 backlight_pos = LLVector4(lerp(opposite_pos, orthog_light_pos, 0.3f), 0.0f); backlight_pos.normalize(); @@ -6091,7 +6038,7 @@ void LLPipeline::setupAvatarLights(bool for_edit) } } F32 backlight_mag; - if (gSky.getSunDirection().mV[2] >= LLSky::NIGHTTIME_ELEVATION_COS) + if (LLEnvironment::instance().getIsSunUp()) { backlight_mag = BACKLIGHT_DAY_MAGNITUDE_OBJECT; } @@ -6300,25 +6247,29 @@ void LLPipeline::setupHWLights(LLDrawPool* pool) { assertInitialized(); + LLEnvironment& environment = LLEnvironment::instance(); + LLSettingsSky::ptr_t psky = environment.getCurrentSky(); + // Ambient if (!LLGLSLShader::sNoFixedFunction) { gGL.syncMatrices(); - LLColor4 ambient = gSky.getTotalAmbientColor(); + LLColor4 ambient = psky->getTotalAmbient(); gGL.setAmbientLightColor(ambient); } // Light 0 = Sun or Moon (All objects) { - if (gSky.getSunDirection().mV[2] >= LLSky::NIGHTTIME_ELEVATION_COS) - { - mSunDir.setVec(gSky.getSunDirection()); - mSunDiffuse.setVec(gSky.getSunDiffuseColor()); + LLVector4 light_dir = environment.getLightDirectionCFR(); + mSunDir.setVec(light_dir); + + if (environment.getIsSunUp()) + { + mSunDiffuse.setVec(psky->getSunDiffuse()); } else { - mSunDir.setVec(gSky.getMoonDirection()); - mSunDiffuse.setVec(gSky.getMoonDiffuseColor()); + mSunDiffuse.setVec(psky->getMoonDiffuse()); } F32 max_color = llmax(mSunDiffuse.mV[0], mSunDiffuse.mV[1], mSunDiffuse.mV[2]); @@ -6328,20 +6279,12 @@ void LLPipeline::setupHWLights(LLDrawPool* pool) } mSunDiffuse.clamp(); - LLVector4 light_pos(mSunDir, 0.0f); LLColor4 light_diffuse = mSunDiffuse; - if (LLPipeline::sRenderDeferred) - { - /*light_diffuse.mV[0] = powf(light_diffuse.mV[0], 2.2f); - light_diffuse.mV[1] = powf(light_diffuse.mV[1], 2.2f); - light_diffuse.mV[2] = powf(light_diffuse.mV[2], 2.2f);*/ - } - mHWLightColors[0] = light_diffuse; LLLightState* light = gGL.getLight(0); - light->setPosition(light_pos); + light->setPosition(mSunDir); light->setDiffuse(light_diffuse); light->setAmbient(LLColor4::black); light->setSpecular(LLColor4::black); @@ -6560,7 +6503,7 @@ void LLPipeline::enableLights(U32 mask) mLightMask = mask; stop_glerror(); - LLColor4 ambient = gSky.getTotalAmbientColor(); + LLColor4 ambient = LLEnvironment::instance().getCurrentSky()->getTotalAmbient(); gGL.setAmbientLightColor(ambient); } } @@ -8270,7 +8213,7 @@ void LLPipeline::bindDeferredShader(LLGLSLShader& shader, U32 light_index, U32 n stop_glerror(); - glh::matrix4f projection = glh_get_current_projection(); + glh::matrix4f projection = get_current_projection(); glh::matrix4f inv_proj = projection.inverse(); shader.uniformMatrix4fv(LLShaderMgr::INVERSE_PROJECTION_MATRIX, 1, FALSE, inv_proj.m); @@ -8444,7 +8387,7 @@ void LLPipeline::bindDeferredShader(LLGLSLShader& shader, U32 light_index, U32 n if (shader.getUniformLocation(LLShaderMgr::DEFERRED_NORM_MATRIX) >= 0) { - glh::matrix4f norm_mat = glh_get_current_modelview().inverse().transpose(); + glh::matrix4f norm_mat = get_current_modelview().inverse().transpose(); shader.uniformMatrix4fv(LLShaderMgr::DEFERRED_NORM_MATRIX, 1, FALSE, norm_mat.m); } } @@ -8514,7 +8457,7 @@ void LLPipeline::renderDeferredLighting() LLGLEnable cull(GL_CULL_FACE); LLGLEnable blend(GL_BLEND); - glh::matrix4f mat = glh_copy_matrix(gGLModelView); + glh::matrix4f mat = copy_matrix(gGLModelView); LLStrider<LLVector3> vert; mDeferredVB->getVertexStrider(vert); @@ -8525,8 +8468,7 @@ void LLPipeline::renderDeferredLighting() { setupHWLights(NULL); //to set mSunDir; - LLVector4 dir(mSunDir, 0.f); - glh::vec4f tc(dir.mV); + glh::vec4f tc(mSunDir.mV); mat.mult_matrix_vec(tc); mTransformedSunDir.set(tc.v); } @@ -8548,7 +8490,7 @@ void LLPipeline::renderDeferredLighting() mDeferredLight.clear(GL_COLOR_BUFFER_BIT); glClearColor(0,0,0,0); - glh::matrix4f inv_trans = glh_get_current_modelview().inverse().transpose(); + glh::matrix4f inv_trans = get_current_modelview().inverse().transpose(); const U32 slice = 32; F32 offset[slice*3]; @@ -9128,7 +9070,7 @@ void LLPipeline::renderDeferredLightingToRT(LLRenderTarget* target) LLGLEnable cull(GL_CULL_FACE); LLGLEnable blend(GL_BLEND); - glh::matrix4f mat = glh_copy_matrix(gGLModelView); + glh::matrix4f mat = copy_matrix(gGLModelView); LLStrider<LLVector3> vert; mDeferredVB->getVertexStrider(vert); @@ -9139,8 +9081,7 @@ void LLPipeline::renderDeferredLightingToRT(LLRenderTarget* target) { setupHWLights(NULL); //to set mSunDir; - LLVector4 dir(mSunDir, 0.f); - glh::vec4f tc(dir.mV); + glh::vec4f tc(mSunDir.mV); mat.mult_matrix_vec(tc); mTransformedSunDir.set(tc.v); } @@ -9162,7 +9103,7 @@ void LLPipeline::renderDeferredLightingToRT(LLRenderTarget* target) mDeferredLight.clear(GL_COLOR_BUFFER_BIT); glClearColor(0,0,0,0); - glh::matrix4f inv_trans = glh_get_current_modelview().inverse().transpose(); + glh::matrix4f inv_trans = get_current_modelview().inverse().transpose(); const U32 slice = 32; F32 offset[slice*3]; @@ -9181,7 +9122,7 @@ void LLPipeline::renderDeferredLightingToRT(LLRenderTarget* target) } } -// pretty sure this doesn't work as expected since the shaders using 'shadow_ofset' all declare it as a single uniform float, no array or vec +// pretty sure this doesn't work as expected since the shaders using 'shadow_offset' all declare it as a single uniform float, no array or vec gDeferredSunProgram.uniform3fv(LLShaderMgr::DEFERRED_SHADOW_OFFSET, slice, offset); gDeferredSunProgram.uniform2f(LLShaderMgr::DEFERRED_SCREEN_RES, mDeferredLight.getWidth(), mDeferredLight.getHeight()); @@ -9651,7 +9592,7 @@ void LLPipeline::setupSpotLight(LLGLSLShader& shader, LLDrawable* drawablep) LLMatrix4 light_mat(quat, LLVector4(origin,1.f)); glh::matrix4f light_to_agent((F32*) light_mat.mMatrix); - glh::matrix4f light_to_screen = glh_get_current_modelview() * light_to_agent; + glh::matrix4f light_to_screen = get_current_modelview() * light_to_agent; glh::matrix4f screen_to_light = light_to_screen.inverse(); @@ -9838,7 +9779,7 @@ void LLPipeline::generateWaterReflection(LLCamera& camera_in) gPipeline.pushRenderTypeMask(); - glh::matrix4f projection = glh_get_current_projection(); + glh::matrix4f projection = get_current_projection(); glh::matrix4f mat; stop_glerror(); @@ -9899,11 +9840,11 @@ void LLPipeline::generateWaterReflection(LLCamera& camera_in) mat.set_scale(glh::vec3f(1,1,-1)); mat.set_translate(glh::vec3f(0,0,height*2.f)); - glh::matrix4f current = glh_get_current_modelview(); + glh::matrix4f current = get_current_modelview(); mat = current * mat; - glh_set_current_modelview(mat); + set_current_modelview(mat); gGL.loadMatrix(mat.m); LLViewerCamera::updateFrustumPlanes(camera, FALSE, TRUE); @@ -10014,7 +9955,7 @@ void LLPipeline::generateWaterReflection(LLCamera& camera_in) glCullFace(GL_BACK); gGL.popMatrix(); mWaterRef.flush(); - glh_set_current_modelview(current); + set_current_modelview(current); LLPipeline::sUseOcclusion = occlusion; } @@ -10044,7 +9985,7 @@ void LLPipeline::generateWaterReflection(LLCamera& camera_in) gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE); - LLColor3 col = LLEnvironment::instance().getCurrentWater()->getFogColor(); + LLColor3 col = LLEnvironment::instance().getCurrentWater()->getWaterFogColor(); glClearColor(col.mV[0], col.mV[1], col.mV[2], 0.f); mWaterDis.bindTarget(); LLViewerCamera::sCurCameraID = LLViewerCamera::CAMERA_WATER1; @@ -10054,7 +9995,7 @@ void LLPipeline::generateWaterReflection(LLCamera& camera_in) if (!LLPipeline::sUnderWaterRender || LLDrawPoolWater::sNeedsReflectionUpdate) { //clip out geometry on the same side of water as the camera - mat = glh_get_current_modelview(); + mat = get_current_modelview(); LLPlane plane(-pnorm, -(pd+pad)); LLGLUserClipPlane clip_plane(plane, mat, projection); @@ -10687,8 +10628,8 @@ void LLPipeline::generateSunShadow(LLCamera& camera) //get sun view matrix //store current projection/modelview matrix - glh::matrix4f saved_proj = glh_get_current_projection(); - glh::matrix4f saved_view = glh_get_current_modelview(); + glh::matrix4f saved_proj = get_current_projection(); + glh::matrix4f saved_view = get_current_modelview(); glh::matrix4f inv_view = saved_view.inverse(); glh::matrix4f view[6]; @@ -10709,15 +10650,17 @@ void LLPipeline::generateSunShadow(LLCamera& camera) //LLVector3 n = RenderShadowNearDist; //F32 nearDist[] = { n.mV[0], n.mV[1], n.mV[2], n.mV[2] }; + LLVector3 sun_dir(mSunDir); + //put together a universal "near clip" plane for shadow frusta LLPlane shadow_near_clip; - { + { LLVector3 p = gAgent.getPositionAgent(); - p += mSunDir * RenderFarClip*2.f; - shadow_near_clip.setVec(p, mSunDir); + p += sun_dir * RenderFarClip*2.f; + shadow_near_clip.setVec(p, sun_dir); } - LLVector3 lightDir = -mSunDir; + LLVector3 lightDir = -sun_dir; lightDir.normVec(); glh::vec3f light_dir(lightDir.mV); @@ -10845,8 +10788,8 @@ void LLPipeline::generateSunShadow(LLCamera& camera) LLViewerCamera::sCurCameraID = (LLViewerCamera::eCameraID)(LLViewerCamera::CAMERA_SHADOW0+j); //restore render matrices - glh_set_current_modelview(saved_view); - glh_set_current_projection(saved_proj); + set_current_modelview(saved_view); + set_current_projection(saved_proj); LLVector3 eye = camera.getOrigin(); @@ -11159,8 +11102,8 @@ void LLPipeline::generateSunShadow(LLCamera& camera) shadow_cam.setOrigin(0,0,0); - glh_set_current_modelview(view[j]); - glh_set_current_projection(proj[j]); + set_current_modelview(view[j]); + set_current_projection(proj[j]); LLViewerCamera::updateFrustumPlanes(shadow_cam, FALSE, FALSE, TRUE); @@ -11173,8 +11116,8 @@ void LLPipeline::generateSunShadow(LLCamera& camera) 0.f, 0.f, 0.5f, 0.5f, 0.f, 0.f, 0.f, 1.f); - glh_set_current_modelview(view[j]); - glh_set_current_projection(proj[j]); + set_current_modelview(view[j]); + set_current_projection(proj[j]); for (U32 i = 0; i < 16; i++) { @@ -11253,8 +11196,8 @@ void LLPipeline::generateSunShadow(LLCamera& camera) for (S32 i = 0; i < 2; i++) { - glh_set_current_modelview(saved_view); - glh_set_current_projection(saved_proj); + set_current_modelview(saved_view); + set_current_projection(saved_proj); if (mShadowSpotLight[i].isNull()) { @@ -11314,8 +11257,8 @@ void LLPipeline::generateSunShadow(LLCamera& camera) 0.f, 0.f, 0.5f, 0.5f, 0.f, 0.f, 0.f, 1.f); - glh_set_current_modelview(view[i+4]); - glh_set_current_projection(proj[i+4]); + set_current_modelview(view[i+4]); + set_current_projection(proj[i+4]); mSunShadowMatrix[i+4] = trans*proj[i+4]*view[i+4]*inv_view; @@ -11359,13 +11302,13 @@ void LLPipeline::generateSunShadow(LLCamera& camera) if (!CameraOffset) { - glh_set_current_modelview(saved_view); - glh_set_current_projection(saved_proj); + set_current_modelview(saved_view); + set_current_projection(saved_proj); } else { - glh_set_current_modelview(view[1]); - glh_set_current_projection(proj[1]); + set_current_modelview(view[1]); + set_current_projection(proj[1]); gGL.loadMatrix(view[1].m); gGL.matrixMode(LLRender::MM_PROJECTION); gGL.loadMatrix(proj[1].m); @@ -11543,7 +11486,7 @@ void LLPipeline::generateImpostor(LLVOAvatar* avatar) F32 fov = atanf(tdim.mV[1]/distance)*2.f*RAD_TO_DEG; F32 aspect = tdim.mV[0]/tdim.mV[1]; glh::matrix4f persp = gl_perspective(fov, aspect, 1.f, 256.f); - glh_set_current_projection(persp); + set_current_projection(persp); gGL.loadMatrix(persp.m); gGL.matrixMode(LLRender::MM_MODELVIEW); @@ -11554,7 +11497,7 @@ void LLPipeline::generateImpostor(LLVOAvatar* avatar) mat = glh::matrix4f((GLfloat*) OGL_TO_CFR_ROTATION) * mat; gGL.loadMatrix(mat.m); - glh_set_current_modelview(mat); + set_current_modelview(mat); glClearColor(0.0f,0.0f,0.0f,0.0f); gGL.setColorMask(true, true); |