Skip to content

Commit

Permalink
SL-20606: (WIP) (has debug) Use PBR alpha shader for preview renderin…
Browse files Browse the repository at this point in the history
…g. Needs lighting, state sanitization, cleanup.
  • Loading branch information
cosmic-linden committed Jan 8, 2024
1 parent c22e38d commit 25505f3
Show file tree
Hide file tree
Showing 6 changed files with 128 additions and 20 deletions.
9 changes: 9 additions & 0 deletions indra/newview/app_settings/shaders/class1/deferred/fxaaF.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -2117,7 +2117,16 @@ void main()



#if 1 // TODO: Restore
frag_color = diff;
#else
#if 0
diff.rgb *= 0.6;
frag_color = diff;
#else
frag_color = vec4(1,0,1,0.5);
#endif
#endif

gl_FragDepth = texture(depthMap, vary_fragcoord.xy).r;
}
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,19 @@ void main()
vec3 nz = vec3(noise(seed.rg), noise(seed.gb), noise(seed.rb));
diff.rgb += nz*0.003;

#if 1 // TODO: Revert
frag_color = max(diff, vec4(0));
#else
#if 0
frag_color = vec4(1,0,1,1);
#else
#if 0
diff.rgb *= 0.05;
frag_color = max(diff, vec4(0));
#else
frag_color = texture(diffuseRect, vary_fragcoord);
#endif
#endif
#endif
}

Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,11 @@ void main()
{
vec4 diff = texture(diffuseRect, vary_fragcoord.xy);

#if 1
frag_color = diff;
#else
frag_color = vec4(1,0,1,1);
#endif

gl_FragDepth = texture(depthMap, vary_fragcoord.xy).r;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,9 @@ uniform vec4 color;

void main()
{
#if 0 // TODO: Revert
frag_color = max(color, vec4(0));
#else
frag_color = vec4(1,0,1,1);
#endif
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,14 @@ void main()
{
vec3 col = texture(diffuseRect, vary_tc).rgb;

#if 1 // TODO: Revert
frag_color = vec4(col.rgb, dot(col.rgb, vec3(0.299, 0.587, 0.144)));
#else
#if 1
frag_color = vec4(1,0,1,0.5);
#else
col.rgb *= 0.3;
frag_color = vec4(col.rgb, dot(col.rgb, vec3(0.299, 0.587, 0.144)));
#endif
#endif
}
109 changes: 89 additions & 20 deletions indra/newview/llgltfmaterialpreviewmgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -304,8 +304,26 @@ std::vector<GLTFPreviewModel> create_preview_sphere(LLPointer<LLFetchedGLTFMater
return preview_sphere;
}

}; // namespace
// Set a variable to a value temporarily, and restor the variable's old value
// when this object leaves scope.
template<typename T>
struct SetTemporarily
{
T* mRef;
T mOldVal;
SetTemporarily(T* var, T temp_val)
{
mRef = var;
mOldVal = *mRef;
*mRef = temp_val;
}
~SetTemporarily()
{
*mRef = mOldVal;
}
};

}; // namespace

BOOL LLGLTFPreviewTexture::render()
{
Expand All @@ -316,6 +334,9 @@ BOOL LLGLTFPreviewTexture::render()
LLGLDepthTest(GL_FALSE);
LLGLDisable stencil(GL_STENCIL_TEST);
LLGLDisable scissor(GL_SCISSOR_TEST);
SetTemporarily no_glow(&LLPipeline::sRenderGlow, false);
SetTemporarily no_ssr(&LLPipeline::RenderScreenSpaceReflections, false);
SetTemporarily no_fxaa(&LLPipeline::RenderFSAASamples, U32(0));

LLViewerCamera camera;

Expand All @@ -336,41 +357,89 @@ BOOL LLGLTFPreviewTexture::render()
const LLRect texture_rect(0, mFullHeight, mFullWidth, 0);
camera.setPerspective(NOT_FOR_SELECTION, texture_rect.mLeft, texture_rect.mBottom, texture_rect.getWidth(), texture_rect.getHeight(), FALSE, camera.getNear(), MAX_FAR_CLIP*2.f);

glClearColor(1.0, 1.0, 1.0, 0.0);
glClear(GL_COLOR_BUFFER_BIT);
glClearColor(0, 0, 0, 0);

LLRenderTarget& screen = gPipeline.mAuxillaryRT.screen;

// TODO: Minimize calls to bind and/or clear render targets

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// TODO: It's probably not necessary to flush mBoundTarget here, once we confirm our targets are correct. (see subsequent mBoundTarget->bindTarget)
mBoundTarget->flush();

screen.bindTarget();
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
screen.flush();

mBoundTarget->bindTarget();

// Generate sphere object on-the-fly. Discard afterwards. (Vertex buffer is
// discarded, but the sphere should be cached in LLVolumeMgr.)
std::vector<GLTFPreviewModel> preview_sphere = create_preview_sphere(mGLTFMaterial, object_transform);

#if 1
// Simple shader
gDebugProgram.bind();
LLGLState cull(GL_CULL_FACE, TRUE);

LLColor4 debug_color(1.0 / (1.0 + mBestLoad[LLGLTFMaterial::GLTF_TEXTURE_INFO_BASE_COLOR]),
1.0 / (1.0 + mBestLoad[LLGLTFMaterial::GLTF_TEXTURE_INFO_NORMAL]),
1.0 / (1.0 + mBestLoad[LLGLTFMaterial::GLTF_TEXTURE_INFO_METALLIC_ROUGHNESS]),
1.0 / (1.0 + mBestLoad[LLGLTFMaterial::GLTF_TEXTURE_INFO_EMISSIVE]));
gDebugProgram.uniform4f(LLShaderMgr::DIFFUSE_COLOR, debug_color.mV[VX], debug_color.mV[VY], debug_color.mV[VZ], debug_color.mV[VW]);
#else
// *TODO: PBR + Environment/probe lighting
// TODO: It's probably not necessary to flush mBoundTarget here, once we confirm our targets are correct
mBoundTarget->flush();

// TODO: Proper lighting
// TODO: Avoid perturbing the state machine
// TODO: Opaque rendering
#if 0 // TODO: Deferred material rendering
if (mGLTFMaterial->mAlphaMode == LLGLTFMaterial::ALPHA_MODE_OPAQUE)
#else
if (false)
#endif
{
screen.bindTarget();

gDeferredPBROpaqueProgram.bind();

for (GLTFPreviewModel& part : preview_sphere)
{
LLRenderPass::pushGLTFBatch(*part.mDrawInfo);
}

screen.flush();
}
else
{
screen.bindTarget();

gDeferredPBRAlphaProgram.bind();
}
#endif

for (GLTFPreviewModel& part : preview_sphere)
{
LLRenderPass::pushGLTFBatch(*part.mDrawInfo);
for (GLTFPreviewModel& part : preview_sphere)
{
LLRenderPass::pushGLTFBatch(*part.mDrawInfo);
}

screen.flush();
}

mBoundTarget->bindTarget();

gPipeline.copyScreenSpaceReflections(&screen, &gPipeline.mSceneMap);
gPipeline.generateLuminance(&screen, &gPipeline.mLuminanceMap);
gPipeline.generateExposure(&gPipeline.mLuminanceMap, &gPipeline.mExposureMap);
gPipeline.gammaCorrect(&screen, &gPipeline.mPostMap);
LLVertexBuffer::unbind();
gPipeline.generateGlow(&gPipeline.mPostMap);
gPipeline.combineGlow(&gPipeline.mPostMap, &screen);
gPipeline.renderDoF(&screen, &gPipeline.mPostMap);
gPipeline.applyFXAA(&gPipeline.mPostMap, &screen);

gDeferredPostNoDoFProgram.bind();

// From LLPipeline::renderFinalize: Whatever is last in the above post processing chain should _always_ be rendered directly here. If not, expect problems.
gDeferredPostNoDoFProgram.bindTexture(LLShaderMgr::DEFERRED_DIFFUSE, &screen);
gDeferredPostNoDoFProgram.bindTexture(LLShaderMgr::DEFERRED_DEPTH, mBoundTarget, true);

{
LLGLDepthTest depth_test(GL_TRUE, GL_TRUE, GL_ALWAYS);
gPipeline.mScreenTriangleVB->setBuffer();
gPipeline.mScreenTriangleVB->drawArrays(LLRender::TRIANGLES, 0, 3);
}

gDeferredPostNoDoFProgram.unbind();

return TRUE;
}

Expand Down

0 comments on commit 25505f3

Please sign in to comment.