Re: [osg-users] Lighting shader problem
Hi Aitor In your code lightPosition = (x=0, y=40, z=0, w=0.3), so you use a directional light (w != 1.0). so you need in your shader a directional light computation. (see Orange book or here http://www.lighthouse3d.com/opengl/glsl/index.php?ogldir1 for more explanation) Or you want a point light and you can keep your shader but lightPosition.w must be equal to 1.0. HTH David Callu 2010/10/5 Aitor Ardanza aitoralt...@terra.es: Trajce (Nick) Nikolov wrote: maybe better to put something in while we can compile and test and see if can help - including the model-Nick Ok, here you have... -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=32382#32382 ___ 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] Lighting shader problem
ledocc wrote: Or you want a point light and you can keep your shader but lightPosition.w must be equal to 1.0. HTH David Callu OK, has been a pretty big mistake, sorry. Setting w to 1 everything is ok! Thanks -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=32554#32554 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Lighting shader problem
ledocc wrote: Is you normal of your model well defined and normalized ? Whitout shaders model looks perfect, and you can see the changes moving the light of the site. ledocc wrote: I suppose you used an osg::Light to define your light. Have you put it in a osg::LightSource ? Code: int const LIGHTS = 1; osg::StateSet *lightStateSet = scene-getOrCreateStateSet(); osg::Geode *lightMarker[LIGHTS]; osg::LightSource *lightSource[LIGHTS]; // Create Lights osg::Vec4 lightColors[] = {osg::Vec4(1.0,1.0,1.0,1.0), osg::Vec4(0.0, 1.0, 0.0, 1.0), osg::Vec4(0.0, 0.0, 1.0, 1.0)}; for (int i = 0; i LIGHTS; i++) { lightMarker[i] = new osg::Geode(); lightMarker[i]-addDrawable(new osg::ShapeDrawable(new osg::Sphere(osg::Vec3(0.0, 40.0, 0.0), 5.0))); osg::Material *light_material = new osg::Material(); light_material-setDiffuse(osg::Material::FRONT, osg::Vec4(1.0, 1.0, 1.0, 1.0)); light_material-setSpecular(osg::Material::FRONT, osg::Vec4(0.1, 0.1, 0.1, 1.0)); light_material-setEmission(osg::Material::FRONT, lightColors[i]); lightMarker[i]-getOrCreateStateSet()-setAttribute(light_material); lightSource[i] = new osg::LightSource(); osg::Light *light = new osg::Light(); // each light must have a unique number light-setLightNum(0); // we set the light's position via a PositionAttitudeTransform object light-setPosition(osg::Vec4(0.0, 40.0, 0.0, 0.3)); light-setSpecular(osg::Vec4(0.1,0.1,0.1,1.0)); light-setAmbient( osg::Vec4(0.2,0.2,0.2,1.0)); light-setDiffuse(lightColors[i]); lightSource[i]-setLight(light); lightSource[i]-setLocalStateSetModes(osg::StateAttribute::ON); lightSource[i]-setStateSetModes(*lightStateSet, osg::StateAttribute::ON); lightTransform[i] = new osg::PositionAttitudeTransform(); lightTransform[i]-addChild(lightSource[i]); lightTransform[i]-addChild(lightMarker[i]); lightTransform[i]-setPosition(osg::Vec3(0, 0,200)); //lightTransform[i]-setScale(osg::Vec3(0.1,0.1,0.1)); scene-addChild(lightTransform[i]); } -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=32364#32364 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Lighting shader problem
the viewer by default is attaching a light. Setup your viewer with NO_LIGHT (or something like that, look in the code), and then create and control your own light -Nick On Mon, Oct 4, 2010 at 11:19 AM, Aitor Ardanza aitoralt...@terra.es wrote: ledocc wrote: bug fix: - ViewDirection = normalize(eyePosition - fvObjectPosition.xyz); + ViewDirection = normalize( - fvObjectPosition.xyz); I already had tried before, but does not solve the problem. If you disable the shader, with the standard osg lighting, gives me no problems, the model normals are well. If approached the camera at a distance close enough to the model, everything is fine, but if you walk away a bit, whole model is lit regardless of the position of the light ... Thanks for the answer! -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=32342#32342 ___ 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] Lighting shader problem
ledocc wrote: bug fix: - ViewDirection = normalize(eyePosition - fvObjectPosition.xyz); + ViewDirection = normalize( - fvObjectPosition.xyz); I already had tried before, but does not solve the problem. If you disable the shader, with the standard osg lighting, gives me no problems, the model normals are well. If approached the camera at a distance close enough to the model, everything is fine, but if you walk away a bit, whole model is lit regardless of the position of the light ... Thanks for the answer! -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=32342#32342 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Lighting shader problem
Hi Aitor, Is you normal of your model well defined and normalized ? I suppose you used an osg::Light to define your light. Have you put it in a osg::LightSource ? Could you provide an example to reproduce your issue This will become hard to solved it without more information. David Callu 2010/10/4 Aitor Ardanza aitoralt...@terra.es: Trajce (Nick) Nikolov wrote: the viewer by default is attaching a light. Setup your viewer with NO_LIGHT (or something like that, look in the code), and then create and control your own light-Nick Neither solves ... Could I use the standard osg lighting if I use a vertex program to change the position of the vertices? yes, you can. If I coment Code: //gl_FrontColor = diffuse + globalAmbient + ambient + specular; the result is this... [Image: http://img210.imageshack.us/img210/4333/30581070.jpg ] -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=32359#32359 ___ 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] Lighting shader problem
Trajce (Nick) Nikolov wrote: the viewer by default is attaching a light. Setup your viewer with NO_LIGHT (or something like that, look in the code), and then create and control your own light-Nick Neither solves ... Could I use the standard osg lighting if I use a vertex program to change the position of the vertices? If I coment Code: //gl_FrontColor = diffuse + globalAmbient + ambient + specular; the result is this... [Image: http://img210.imageshack.us/img210/4333/30581070.jpg ] -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=32359#32359 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Lighting shader problem
maybe better to put something in while we can compile and test and see if can help - including the model -Nick On Mon, Oct 4, 2010 at 5:37 PM, Aitor Ardanza aitoralt...@terra.es wrote: ledocc wrote: Is you normal of your model well defined and normalized ? Whitout shaders model looks perfect, and you can see the changes moving the light of the site. ledocc wrote: I suppose you used an osg::Light to define your light. Have you put it in a osg::LightSource ? Code: int const LIGHTS = 1; osg::StateSet *lightStateSet = scene-getOrCreateStateSet(); osg::Geode *lightMarker[LIGHTS]; osg::LightSource *lightSource[LIGHTS]; // Create Lights osg::Vec4 lightColors[] = {osg::Vec4(1.0,1.0,1.0,1.0), osg::Vec4(0.0, 1.0, 0.0, 1.0), osg::Vec4(0.0, 0.0, 1.0, 1.0)}; for (int i = 0; i LIGHTS; i++) { lightMarker[i] = new osg::Geode(); lightMarker[i]-addDrawable(new osg::ShapeDrawable(new osg::Sphere(osg::Vec3(0.0, 40.0, 0.0), 5.0))); osg::Material *light_material = new osg::Material(); light_material-setDiffuse(osg::Material::FRONT, osg::Vec4(1.0, 1.0, 1.0, 1.0)); light_material-setSpecular(osg::Material::FRONT, osg::Vec4(0.1, 0.1, 0.1, 1.0)); light_material-setEmission(osg::Material::FRONT, lightColors[i]); lightMarker[i]-getOrCreateStateSet()-setAttribute(light_material); lightSource[i] = new osg::LightSource(); osg::Light *light = new osg::Light(); // each light must have a unique number light-setLightNum(0); // we set the light's position via a PositionAttitudeTransform object light-setPosition(osg::Vec4(0.0, 40.0, 0.0, 0.3)); light-setSpecular(osg::Vec4(0.1,0.1,0.1,1.0)); light-setAmbient( osg::Vec4(0.2,0.2,0.2,1.0)); light-setDiffuse(lightColors[i]); lightSource[i]-setLight(light); lightSource[i]-setLocalStateSetModes(osg::StateAttribute::ON); lightSource[i]-setStateSetModes(*lightStateSet, osg::StateAttribute::ON); lightTransform[i] = new osg::PositionAttitudeTransform(); lightTransform[i]-addChild(lightSource[i]); lightTransform[i]-addChild(lightMarker[i]); lightTransform[i]-setPosition(osg::Vec3(0, 0,200)); //lightTransform[i]-setScale(osg::Vec3(0.1,0.1,0.1)); scene-addChild(lightTransform[i]); } -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=32364#32364 ___ 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] Lighting shader problem
Thanks for the correction, but the result is the same ... Aitor -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=32254#32254 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Lighting shader problem
Hi Aitor try this: Your code do the job in eye coordinate so eyePosition = vec3(0,0,0) and you don't need eyePosition uniform; bug fix: - ViewDirection = normalize(eyePosition - fvObjectPosition.xyz); + ViewDirection = normalize( - fvObjectPosition.xyz); HTH David Callu 2010/10/1 Aitor Ardanza aitoralt...@terra.es: Thanks for the correction, but the result is the same ... Aitor -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=32254#32254 ___ 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] Lighting shader problem
Hi, I'm doing tests with shader for the lighting and the following problem happens to me ... With the camera close enough, all goes well, but if they turn away, do not seem to take into account the position of the light. Two images: the first up close, and the other from a distance and back lighting. [Image: http://img227.imageshack.us/img227/3906/lighting1.jpg ][Image: http://img266.imageshack.us/img266/7084/lighting2.jpg ] vertex shader: Code: uniform vec3 eyePosition; varying vec2 Texcoord; varying vec3 ViewDirection; varying vec3 LightDirection; varying vec3 Normal; varying vec4 color; varying vec3 position; void main( void ) { gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex; Texcoord= gl_MultiTexCoord0.xy; position = gl_Vertex.xyz; vec4 fvObjectPosition = gl_ModelViewMatrix * gl_Vertex; ViewDirection = normalize(eyePosition - fvObjectPosition.xyz); LightDirection = normalize(gl_LightSource[0].position.xyz - fvObjectPosition.xyz); Normal = gl_NormalMatrix * gl_Normal; float NdotL = max(dot(Normal, LightDirection), 0.0); vec4 diffuse = NdotL * gl_FrontMaterial.diffuse * gl_LightSource[0].diffuse; vec4 ambient = gl_FrontMaterial.ambient * gl_LightSource[0].ambient; vec4 globalAmbient = gl_LightModel.ambient * gl_FrontMaterial.ambient; vec3 fvReflection = normalize( ( ( 2.0 * Normal ) * NdotL ) - LightDirection ); float fRDotV = max( 0.0, dot( fvReflection, ViewDirection ) ); vec4 specular = gl_FrontMaterial.specular * gl_LightSource[0].specular * pow(fRDotV,200.0); gl_FrontColor = diffuse + globalAmbient + ambient + specular; } Any idea what can be the problem? Thank you! Cheers, Aitor -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=32224#32224 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Lighting shader problem
Hi Aitor, I'm definitely not a shader guy but how does your eyePosition variable ever get set?? Cheers, Greg -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=32228#32228 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Lighting shader problem
Hi, I get it by : Code: osg::Vec3f eye; osg::Vec3f center; osg::Vec3f up; getCamera()-getViewMatrixAsLookAt(eye, center, up); if(!aniModel-getAvatar()-getOrCreateStateSet()-getUniform(eyePosition)-setElement(0,osg::Vec3(eye._v[0],eye._v[1],eye._v[2]))) osg::notify(osg::WARN) Update eyePosition: can't set uniform at 0 elements std::endl; Thanks your answer! Cheers, Aitor[/quote] -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=32231#32231 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Lighting shader problem
if(!aniModel-getAvatar()-getOrCreateStateSet()-getUniform(eyePosition)-setElement(0,osg::Vec3(eye._v[0],eye._v[1],eye._v[2]))) why not : if(!aniModel-getAvatar()-getOrCreateStateSet()-getUniform(eyePosition)-set(eye)) ? -Fred ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org