Hello Christian,
On 03/15/2013 11:11 AM, Christian Bar wrote:
Thank you for your answer :)
No, I have to render the other viewport first...
The solution shoul be exactly what you are proposing:
teaching the ShadowStage to not touch pixels not
written to by the scene it renders.
Hope it is not too complicated...
I'm attaching a quick hack that makes the test case I have work. Before
I clean it up and implement it properly would you mind giving it a try
to see if it works for you as well? Thanks!
There is one remaining issue I'm aware of:
The viewport with shadows needs a SolidBackground with alpha == 0.f when
shadows are enabled and a DepthClearBackground when shadows are
disabled. I'm not sure how to get around that right now.
Cheers,
Carsten
diff --git a/Source/System/NodeCores/Groups/Effects/ShadowStage/OSGShadowTreeHandler.cpp b/Source/System/NodeCores/Groups/Effects/ShadowStage/OSGShadowTreeHandler.cpp
index 497ca83..63a2650 100644
--- a/Source/System/NodeCores/Groups/Effects/ShadowStage/OSGShadowTreeHandler.cpp
+++ b/Source/System/NodeCores/Groups/Effects/ShadowStage/OSGShadowTreeHandler.cpp
@@ -69,9 +69,9 @@ std::string ShadowTreeHandler::_shadow_combine_fp =
"void main(void)\n"
"{\n"
" vec2 tc = texCoord * vec2(xFactor, yFactor);\n"
- " vec3 color = texture2D(colorMap, tc).rgb;\n"
- " color *= hasFactorMap ? (1.0 - texture2D(shadowFactorMap, tc).r) : 1.0;\n"
- " gl_FragColor = vec4(color, 1.0);\n"
+ " vec4 color = texture2D(colorMap, tc).rgba;\n"
+ " color.rgb *= hasFactorMap ? (1.0 - texture2D(shadowFactorMap, tc).r) : 1.0;\n"
+ " gl_FragColor = vec4(color);\n"
"}\n";
@@ -168,8 +168,8 @@ ShadowTreeHandler::ShadowTreeHandler(ShadowStage *pSource,
_colorMapImage = Image ::createLocal();
_colorMapO->setImage (_colorMapImage);
- _colorMapO->setInternalFormat(GL_RGB);
- _colorMapO->setExternalFormat(GL_RGB);
+ _colorMapO->setInternalFormat(GL_RGBA);
+ _colorMapO->setExternalFormat(GL_RGBA);
_colorMapO->setMinFilter (GL_NEAREST);
_colorMapO->setMagFilter (GL_NEAREST);
_colorMapO->setWrapS (GL_REPEAT);
@@ -650,9 +650,9 @@ void ShadowTreeHandler::doDrawCombineMap2(DrawEnv *pEnv)
commitChanges();
- glClearColor(0.2f, 0.2, 0.2f, 1.0f);
+// glClearColor(0.2f, 0.2, 0.2f, 1.0f);
// glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
- glClear(GL_COLOR_BUFFER_BIT);
+// glClear(GL_COLOR_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
@@ -666,6 +666,9 @@ void ShadowTreeHandler::doDrawCombineMap2(DrawEnv *pEnv)
glDepthMask(GL_FALSE);
glDisable(GL_DEPTH_TEST);
+ glEnable(GL_BLEND);
+ glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+
glBegin(GL_QUADS);
{
glTexCoord2f(0.00, 0.00);
@@ -682,6 +685,8 @@ void ShadowTreeHandler::doDrawCombineMap2(DrawEnv *pEnv)
}
glEnd();
+ glDisable(GL_BLEND);
+
glEnable(GL_DEPTH_TEST);
glDepthMask(GL_TRUE);
@@ -744,10 +749,10 @@ void ShadowTreeHandler::doDrawCombineMap1(DrawEnv *pEnv)
commitChanges();
- glClearColor(0.2f, 0.2, 0.2f, 1.0f);
-// glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
-
- glClear(GL_COLOR_BUFFER_BIT);
+// glClearColor(0.2f, 0.2, 0.2f, 1.0f);
+// // glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+//
+// glClear(GL_COLOR_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
@@ -761,6 +766,9 @@ void ShadowTreeHandler::doDrawCombineMap1(DrawEnv *pEnv)
glDepthMask(GL_FALSE);
glDisable(GL_DEPTH_TEST);
+ glEnable(GL_BLEND);
+ glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+
glBegin(GL_QUADS);
{
glTexCoord2f(0.00, 0.00);
@@ -777,6 +785,8 @@ void ShadowTreeHandler::doDrawCombineMap1(DrawEnv *pEnv)
}
glEnd();
+ glDisable(GL_BLEND);
+
glEnable(GL_DEPTH_TEST);
glDepthMask(GL_TRUE);
------------------------------------------------------------------------------
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
http://p.sf.net/sfu/appdyn_d2d_mar
_______________________________________________
Opensg-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/opensg-users