Re: [osg-users] ViewDependentShadow and Lod

2009-05-05 Thread Wojciech Lewandowski

Hi Antonin,

I am glad you had this sorted it out. You may try to replace shaders with 
yours. Its possible to set only fragment shaders and use fixed pipeline for 
vertices by setting MainVertexShader and ShadowVertexShader to NULL.


Cheers,
Wojtek

- Original Message - 
From: Antonin Linares antonin.lina...@onera.fr

To: OpenSceneGraph Users osg-users@lists.openscenegraph.org
Sent: Monday, May 04, 2009 4:11 PM
Subject: Re: [osg-users] ViewDependentShadow and Lod



Again,

Please don't care of my previous message, i'm wrong.

Some part of my terrain database use pure glColor(), so the shader  miss 
compute this part of  database.


Sorry all.

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


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


Re: [osg-users] ViewDependentShadow and Lod

2009-05-05 Thread Antonin Linares

Hi Wojtek,
Thanks for the vertex shader trick, but in this way i gate pure black 
shadow and terrible artifact on my shadow caster model.

Actually i can see two way to solve my lighting problem.

-Make a vertex shader who can compute lighting with glMaterial and 
glColor both.
   but it's seem to me that it's impossible without using an uniform 
switch.


-Use a nodeVisitor to replace vertex color attribute by a similar material.
   But here i dont now how to check actual color mode:

void setMatNodeVisitor::apply(osg::Node node)
{
   osg::Geode* geode = node.asGeode();
   if(geode)
   {
   for(int i =0; i  geode-getNumDrawable(); i++)
   {
   osg::Material* mat = (osg::Matrial*) 
geode-getDrawable(i)-getStateSet();

if(mat){
  if(mat.getColorMode() == osg::Material::OFF)
  //no material off in my scene ...
  
   }

   }
   }  
}



Wojciech Lewandowski a écrit :

Hi Antonin,

I am glad you had this sorted it out. You may try to replace shaders 
with yours. Its possible to set only fragment shaders and use fixed 
pipeline for vertices by setting MainVertexShader and 
ShadowVertexShader to NULL.


Cheers,
Wojtek

- Original Message - From: Antonin Linares 
antonin.lina...@onera.fr

To: OpenSceneGraph Users osg-users@lists.openscenegraph.org
Sent: Monday, May 04, 2009 4:11 PM
Subject: Re: [osg-users] ViewDependentShadow and Lod



Again,

Please don't care of my previous message, i'm wrong.

Some part of my terrain database use pure glColor(), so the shader  
miss compute this part of  database.


Sorry all.

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



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




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


Re: [osg-users] ViewDependentShadow and Lod

2009-05-05 Thread Wojciech Lewandowski

Hi Antonin,

Sounds like your issue might be related to GL_LIGHTING or GL_MATERIAL_COLOR 
mode usage. GL_COLOR_MATERIAL selects source of 
diffuse/ambient/emissive/specular term. Its either taken from material or 
from  color set in geometries. This fixed pipeline attribute is not passed 
to Vertex Shaders as an uniform so shader coders may need to make 
workarounds for it.


We had such problem with bunch of models using GL_COLOR_MATERIAL set to 
AMBIENT_AND_DIFFUSE  in which case actual ambient and diffuse material 
values where not set in material but assumed tio be taken from glColor. If 
they were not set in material they often were quite random so they were 
causing the issues. We overcame this by approach similar to your option 
number 2.  We ran a visitor which found if material set per drawable used 
GL_COLOR_MATERIAL with colors from drawable and we cloned such material 
replacing its colors with these from drawable color array. There should be a 
problem with drawables with more than one color (colors set per vertex or 
per primitive) but fortunately we did not have such cases. Below is source 
of the function used by this visitor. Its inputs are drawable StateSet and 
Color taken from drawable color array.


bool SubstituteColorMaterial( osg::StateSet * ss, osg::Vec4 color )
{
   if( !ss ) return false;

   osg::Material * material =
   dynamic_castosg::Material*
   ( ss-getAttribute( osg::StateAttribute::MATERIAL ) );

   if ( !material || material-getColorMode() == osg::Material::OFF ) 
return false;


   osg::ref_ptr osg::Material 
   newOsgMaterial = dynamic_castosg::Material*
   ( material-clone(osg::CopyOp::SHALLOW_COPY) );

   switch( newOsgMaterial-getColorMode() )
   {
   case osg::Material::AMBIENT_AND_DIFFUSE:
   newOsgMaterial-setAmbient( osg::Material::FRONT_AND_BACK, 
color );
   newOsgMaterial-setDiffuse( osg::Material::FRONT_AND_BACK, 
color );

   break;
   case osg::Material::AMBIENT:
   newOsgMaterial-setAmbient( osg::Material::FRONT_AND_BACK, 
color );

   break;
   case osg::Material::DIFFUSE:
   newOsgMaterial-setDiffuse( osg::Material::FRONT_AND_BACK, 
color );

   break;
   case osg::Material::SPECULAR:
   newOsgMaterial-setSpecular( osg::Material::FRONT_AND_BACK, 
color );

   break;
   case osg::Material::EMISSION:
   newOsgMaterial-setEmission( osg::Material::FRONT_AND_BACK, 
color );

   break;
   }

   newOsgMaterial-setColorMode( osg::Material::OFF );

   ss-setAttribute(  newOsgMaterial.get()  );

   return true;
}

Maybe this helps a little,
Wojtek

- Original Message - 
From: Antonin Linares antonin.lina...@onera.fr

To: OpenSceneGraph Users osg-users@lists.openscenegraph.org
Sent: Tuesday, May 05, 2009 4:23 PM
Subject: Re: [osg-users] ViewDependentShadow and Lod


Hi Wojtek,
Thanks for the vertex shader trick, but in this way i gate pure black
shadow and terrible artifact on my shadow caster model.
Actually i can see two way to solve my lighting problem.

-Make a vertex shader who can compute lighting with glMaterial and
glColor both.
   but it's seem to me that it's impossible without using an uniform
switch.

-Use a nodeVisitor to replace vertex color attribute by a similar material.
   But here i dont now how to check actual color mode:

void setMatNodeVisitor::apply(osg::Node node)
{
   osg::Geode* geode = node.asGeode();
   if(geode)
   {
   for(int i =0; i  geode-getNumDrawable(); i++)
   {
   osg::Material* mat = (osg::Matrial*)
geode-getDrawable(i)-getStateSet();
if(mat){
  if(mat.getColorMode() == osg::Material::OFF)
  //no material off in my scene ...

   }
   }
   }
}


Wojciech Lewandowski a écrit :

Hi Antonin,

I am glad you had this sorted it out. You may try to replace shaders with 
yours. Its possible to set only fragment shaders and use fixed pipeline 
for vertices by setting MainVertexShader and ShadowVertexShader to NULL.


Cheers,
Wojtek

- Original Message - From: Antonin Linares 
antonin.lina...@onera.fr

To: OpenSceneGraph Users osg-users@lists.openscenegraph.org
Sent: Monday, May 04, 2009 4:11 PM
Subject: Re: [osg-users] ViewDependentShadow and Lod



Again,

Please don't care of my previous message, i'm wrong.

Some part of my terrain database use pure glColor(), so the shader  miss 
compute this part of  database.


Sorry all.

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



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




___
osg-users mailing list
osg-users@lists.openscenegraph.org
http

Re: [osg-users] ViewDependentShadow and Lod

2009-05-04 Thread Antonin Linares

Hi all,

Finally i find where is the lighting problem, it's the specular 
computation. Here's the change i made in the main vertex shader:


   void DirectionalLight(in int 
i,\n
in vec3 
normal,\n
 inout vec4 
ambient,\n
inout vec4 
diffuse,\n
 inout vec4 
specular)\n
   
{  
 \n
float nDotVP; // normal . light 
direction\n
float nDotHV; // normal . light half 
vector\n
float pf; // power 
factor\n
   
  
 \n
nDotVP = max(0.0, 
dot(normal,\n
   
normalize(vec3(gl_LightSource[i].position;\n
nDotHV = max(0.0, 
dot(normal,\n
 
vec3(gl_LightSource[i].halfVector)));\n
   
  
 \n
   //CHANGE HERE 
\n
  //  if (nDotVP == 
0.0)\n
 //   pf = 
0.0;
   \n
  // 
else   
   \n
  //  pf = pow(nDotHV, 
gl_FrontMaterial.shininess); \n
   //CHANGE TO 
   \n
if (nDotVP  
0.0)  \n
   pf = pow(nDotHV, 
gl_FrontMaterial.shininess);  \n
   
else 
  \n
pf = 0.0;
   \n
   //END CHANGE 
   \n
ambient  += gl_LightSource[i].ambient; 
  \n
diffuse  += gl_LightSource[i].diffuse * nDotVP;   
\n
specular += gl_LightSource[i].specular * 
pf;\n
   
   \n
   } 
  \n



There are similarly problem in spot and point light.
I'm not understand exactly why, maybe equality check on float ?

best regard





Hi Wojtek,

Yes reference frame is set in StandardShadowMap, i didn't notice it 
yesterday.

I made test and i found something new:
It's not a lod problem but a Lighting problem (geometry is good). 
Actually i take a look in StandardShadowMap shader, if you have any idea.


[...]

Find where is the problem, gl_Color is miss compute (for my terrain 
db) by the main vertex shader,  by using a constant one in fragment i 
solve
my lighing problem. I' m going to make my own vertex shader to keep 
the lighting computation.




Thanks


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


Re: [osg-users] ViewDependentShadow and Lod

2009-05-04 Thread Antonin Linares

Again,

Please don't care of my previous message, i'm wrong.

Some part of my terrain database use pure glColor(), so the shader  miss 
compute this part of  database.


Sorry all.

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


Re: [osg-users] ViewDependentShadow and Lod

2009-04-30 Thread Antonin Linares

Hi Wojtek,

Yes reference frame is set in StandardShadowMap, i didn't notice it 
yesterday.

I made test and i found something new:
It's not a lod problem but a Lighting problem (geometry is good). 
Actually i take a look in StandardShadowMap shader, if you have any idea.


[...]

Find where is the problem, gl_Color is miss compute (for my terrain db) 
by the main vertex shader,  by using a constant one in fragment i solve
my lighing problem. I' m going to make my own vertex shader to keep the 
lighting computation.




Thanks





Hi Antonin,
 
As far as I remember, ABSOLUTE_RF_INHERIT_VIEWPOINT reference frame 
for Shadow map camera is  set in osgShadow::StandardShadowMap and 
should be inherited and used by all derived classes 
including DebugShadowMap, MinimalCull/DrawBounds and all three LispSM 
flavours. So it looks like your problems may be caused by something 
else...
 
We have been using LispSM with LODs and we have not seen major 
artifacts since this addition of ABSOLUTE_RF_INHERIT_VIEWPOINT which 
happened after discussion you referenced.
 
Maybe you are using LODs switched by pixel sizes (not viewpoint 
distance ) ? I have not tested this scenario but I would guess that it 
would depend on shadow map resolution. Its also possible that LispSM 
skewed projection matrix may somehow cause wrong results in pixel size 
LOD computations. 
 
Sorry to say that but you caught me at bad moment. I am going on a 5 
day trip tomorrow and will be offline till next Tuesday.  If you are 
unable  to solve the issue by then, send some more info and maybe we 
would come up with some fresh idea...
 
Cheers,

Wojtek Lewandowski
 


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


Re: [osg-users] ViewDependentShadow and Lod

2009-04-29 Thread Wojciech Lewandowski
Hi Antonin,

As far as I remember, ABSOLUTE_RF_INHERIT_VIEWPOINT reference frame for Shadow 
map camera is  set in osgShadow::StandardShadowMap and should be inherited and 
used by all derived classes including DebugShadowMap, MinimalCull/DrawBounds 
and all three LispSM flavours. So it looks like your problems may be caused by 
something else...

We have been using LispSM with LODs and we have not seen major artifacts since 
this addition of ABSOLUTE_RF_INHERIT_VIEWPOINT which happened after discussion 
you referenced. 

Maybe you are using LODs switched by pixel sizes (not viewpoint distance ) ? I 
have not tested this scenario but I would guess that it would depend on shadow 
map resolution. Its also possible that LispSM skewed projection matrix may 
somehow cause wrong results in pixel size LOD computations. 

Sorry to say that but you caught me at bad moment. I am going on a 5 day trip 
tomorrow and will be offline till next Tuesday.  If you are unable  to solve 
the issue by then, send some more info and maybe we would come up with some 
fresh idea...

Cheers,
Wojtek Lewandowski



From: Antonin Linares 
Sent: Wednesday, April 29, 2009 5:57 PM
To: osg osg 
Subject: [osg-users] ViewDependentShadow and Lod


Hi all,

I actualy use LightSpacePerspectiveShadowMap and it's work very well.
but :(
My terrain database lod levels became crazy, he seem to me it's the same 
problem in this thread here. (lod is compute from the shadow camera view point
 instead of eyes points)
So i test to change the shadow camera RefernceFrame to 
ABSOLUTE_RF_INHERIT_VIEWPOINT
in DebugShadowMap but it's made no change.

Wojtek save me !! 
thanks all.

Antonin Linares.








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