Re: [osg-users] shadows and custom shaders

2010-09-24 Thread Michael Irby II
Hi guys,

So I have been reworking to support the shadows. Does the tex gen coords get 
stored in the texture matrix? Am I wrong to assume I can still use the 
fixed-function tex gen coords with a shader?

Werner,

I noticed you said you replaced the OSG shader with your own. Do you happen to 
know what happens when you stop using an uber-shader to render everything in 
your scene. My scene has many shaders in the graph. To me it seems like some 
data might be getting overridden down the traversal of the scene.

Thanks.

--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=32056#32056





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] shadows and custom shaders

2010-09-24 Thread Jean-Sébastien Guay

Hi Michael,


So I have been reworking to support the shadows. Does the tex gen coords get 
stored in the texture matrix? Am I wrong to assume I can still use the 
fixed-function tex gen coords with a shader?


Texture coordinate generation is done by the Vertex stage, so as soon as 
you start using a vertex shader you need to do tex coord generation for 
your shadow texture unit too. Check the vertex shaders in 
src/osgShadow/StandardShadowMap.cpp for guidance.



I noticed you said you replaced the OSG shader with your own. Do you happen to 
know what happens when you stop using an uber-shader to render everything in 
your scene. My scene has many shaders in the graph. To me it seems like some 
data might be getting overridden down the traversal of the scene.


If you use different shaders on different nodes, you need to do shadow 
texgen computation (vertex shader) and shadow application (fragment 
shader) in all of them. You can easily factor out those functions into 
small shader files that you will include everywhere you use your own 
shaders. That's what the shaders in StandardShadowMap.cpp do - the main 
shader declares a DynamicShadow() function and calls it, and the shadow 
shader defines that function. You can do the same, just write your own 
main shader, declaring the DynamicShadow() function and calling it, and 
include the same shadow shader (with the code of DynamicShadow()) in all 
of them.


Hope this helps,

J-S
--
__
Jean-Sebastien Guayjean-sebastien.g...@cm-labs.com
   http://www.cm-labs.com/
http://whitestar02.webhop.org/
___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] shadows and custom shaders

2010-09-24 Thread Michael Irby II
Thanks J-S. Yea I finally got it working. I did it by taking over the cull step 
of the shadow maps and getting rid of the fixed function tex gen and then 
pushing the matrices for the shadow projection into my vertex shaders and doing 
the math there.

Thanks for your help.

--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=32058#32058





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] shadows and custom shaders

2010-09-24 Thread Jean-Sébastien Guay

Hi Michael,


Thanks J-S. Yea I finally got it working. I did it by taking over the cull step 
of the shadow maps and getting rid of the fixed function tex gen and then 
pushing the matrices for the shadow projection into my vertex shaders and doing 
the math there.


I think you may have overcomplicated things for yourself a bit... You 
dind't have to remove any fixed function state at all, since when you 
use shaders it's implicitly replaced by your shader. Also, in the shader 
you have everything you need to be able to calculate the texgen already 
(care of the TexGen and some other calculations). This is all spelled 
out in the shaders at the top of src/osgShadow/StandardShadowMap.cpp, as 
I mentioned before.


You have a function called DynamicShadow:

void DynamicShadow( in vec4 ecPosition )
{
// generate coords for shadow mapping
gl_TexCoord[1].s = dot( ecPosition, gl_EyePlaneS[1] );
gl_TexCoord[1].t = dot( ecPosition, gl_EyePlaneT[1] );
gl_TexCoord[1].p = dot( ecPosition, gl_EyePlaneR[1] );
gl_TexCoord[1].q = dot( ecPosition, gl_EyePlaneQ[1] );
}

(the gl_EyePlane* are set up by the TexGen) and you call it like this:

vec4  ecPos  = gl_ModelViewMatrix * gl_Vertex;
DynamicShadow( ecPos );

And as I said, you can put the first part in a file that you will add to 
every osg::Program you have, in addition to your own shader that will 
have the second set of lines in it. Same for the fragment shader,, where 
you would do the shadowmap lookup using the texcoords that were 
calculated above in the vertex shader. That way you're not duplicating 
much code, you're reusing the same file in many places. And you're 
working within the system instead of replacing big parts of it, which I 
find preferable since it's less prone to break later on if OSG changes.


Anyways, good to know you have something that works, but I just wanted 
to point out that there may be a better way.


J-S
--
__
Jean-Sebastien Guayjean-sebastien.g...@cm-labs.com
   http://www.cm-labs.com/
http://whitestar02.webhop.org/
___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


[osg-users] shadows and custom shaders

2010-09-21 Thread Michael Irby II
Hi,

So I have been experimenting with shadows in OSG using the ShadowMap shadow 
technique. With the default OSG implementation and every custom shader in my 
scene graph disabled the shadows work correctly. Once I turn my shaders on they 
stop working. This is understandable as he OSG shadow shader will be 
overridden. I then reimplemented the shadow projection code in my pixel 
shaders, but then still no shadows. I am not too familiar with the OpenGL 
fixed-function shadow pipeline. If you do not provide a vertex shader does 
OpenGL generate the proper texture coordinates by default. I saw that OSG was 
creating a TexGen attribute and applying that after shadow map creation. If I 
am implementing custom vertex shaders should I be overriding the ShadowMap and 
not allowing that TexGen to be created and then generate the proper texture 
coordinates in my vertex shader? At this point I think all that is missing is 
the proper texture coordinates for shadows to be working for me. Any help woul
 d be appreciated. Thanks in advance!

Cheers,
Michael

--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=31896#31896





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] shadows and custom shaders

2010-09-21 Thread Jean-Sébastien Guay

Hello Michael,


If I am implementing custom vertex shaders should I be overriding the ShadowMap 
and not allowing that TexGen to be created and then generate the proper texture 
coordinates in my vertex shader? At this point I think all that is missing is 
the proper texture coordinates for shadows to be working for me.


Your intuition is correct, but you just need to calculate the shadow 
texture coordinates for the shadow texture unit. No need to disable the 
osg::TexGen because since it's fixed-function state, it will just be 
ignored when using a vertex shader.


As has been said before, once you start using shaders for a given stage 
you need to do everything the fixed pipeline would have done for you in 
your shader for that stage yourself (at least, what you need). That 
includes fog, texgen, etc.


J-S
--
__
Jean-Sebastien Guayjean-sebastien.g...@cm-labs.com
   http://www.cm-labs.com/
http://whitestar02.webhop.org/
___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] shadows and custom shaders

2010-09-21 Thread Michael Irby II
Hi J-S,

Thanks for the swift reply, good to know I was on the correct path.

--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=31904#31904





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] shadows and custom shaders

2010-09-21 Thread Werner Modenbach
Hi Michael,

You are right. There can only be one shader program loaded which has to do all 
the work.
If you overload the default shader from osgShadow, it has to do that work 
together with your new stuff.

In my case I just created my own class Cl_SoftShadowMap, derived from 
osgSoftShadowmap. I reimplemented two methods:

// If our shader needs additional uniforms, they may be set here
void Cl_SoftShadowMap::createUniforms() {
_uniformList.clear();
SoftShadowMap::createUniforms();

// This Variable will be set by any node using textures
_uniformList.push_back(new osg::Uniform(USE_TEXTURE_UNIFORM, false));

// Shadow creation can be switched on an off (we still need our shaders)
useShadowUniform = new osg::Uniform(USE_SHADOW_MAP_UNIFORM, useShadow);
_uniformList.push_back(useShadowUniform.get());

// Toggle between soft and hard shadows
useSoftShadowUniform = new osg::Uniform(USE_SOFT_SHADOW_UNIFORM, 
useSoftShadow);
_uniformList.push_back(useSoftShadowUniform.get());

// Uniforms used for bump mapping
_uniformList.push_back(new osg::Uniform(USE_BUMP_MAP_UNIFORM, false));
_uniformList.push_back(new osg::Uniform(bumpMap, BUMP_TEXTURE_UNIT));
}

// We create our own shaders
void Cl_SoftShadowMap::createShaders(bool _enableShadow, 
 bool _enableBumpMapping, 
 bool _enableDisplacementMapping) {
if( _shaderList.empty() ) {
osg::ref_ptrosg::Shader vertexShader;
vertexShader = Cl_ShaderGen::getShader(osg::Shader::VERTEX,
   _enableShadow,
   _enableBumpMapping, 
   _enableDisplacementMapping);
_shaderList.push_back(vertexShader);
osg::ref_ptrosg::Shader fragmentShader;
fragmentShader = Cl_ShaderGen::getShader(osg::Shader::FRAGMENT, 
   _enableShadow,
   _enableBumpMapping,
   _enableDisplacementMapping);
_shaderList.push_back(fragmentShader);
}
}

By this way your own shaders get loaded an you can create any uniform youneed.
You can use it by calling shadowScene-setShadowTechnique(...);

I hope this helps.

- Werner -


On Tuesday 21 September 2010 15:25:23 Michael Irby II wrote:
 Hi,
 
 So I have been experimenting with shadows in OSG using the ShadowMap shadow
 technique. With the default OSG implementation and every custom shader in
 my scene graph disabled the shadows work correctly. Once I turn my shaders
 on they stop working. This is understandable as he OSG shadow shader will
 be overridden. I then reimplemented the shadow projection code in my pixel
 shaders, but then still no shadows. I am not too familiar with the OpenGL
 fixed-function shadow pipeline. If you do not provide a vertex shader does
 OpenGL generate the proper texture coordinates by default. I saw that OSG
 was creating a TexGen attribute and applying that after shadow map
 creation. If I am implementing custom vertex shaders should I be
 overriding the ShadowMap and not allowing that TexGen to be created and
 then generate the proper texture coordinates in my vertex shader? At this
 point I think all that is missing is the proper texture coordinates for
 shadows to be working for me. Any help woul d be appreciated. Thanks in
 advance!
 
 Cheers,
 Michael
 
 --
 Read this topic online here:
 http://forum.openscenegraph.org/viewtopic.php?p=31896#31896
 
 
 
 
 
 ___
 osg-users mailing list
 osg-users@lists.openscenegraph.org
 http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

-- 
TEXION Software Solutions

TEXION GmbH -  Rotter Bruch 26a  -  D 52068 Aachen - HRB 14999 Aachen
Fon: +49 241 475757-0, Fax: +49 241 475757-29, web: http://www.texion.eu

Geschäftsführer/Managing Director: Werner Modenbach
___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org