Re: [osg-users] Tonemapping, RTT, PixelDataBufferObject, GPU-CPU copy pixel value

2011-01-29 Thread josselin . petit

Hi Dan,

I already made tone mapping algorithms in OSG, but using OSG PPU  
(http://projects.tevs.eu/osgppu/), very useful for post-processing  
like tone mapping.


Have a look here:
http://www.mail-archive.com/osg-users@lists.openscenegraph.org/msg18523.html

In this discussion, I speak about a bug in PPU which is solved today,  
so you could make your own algorithm easily.


Hope this helps,
Josselin.


This message was sent using IMP, the Internet Messaging Program.

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


Re: [osg-users] [osgPPU] HDR example: wrong average luminance?

2010-04-28 Thread josselin . petit

Dear Art, Luca, Allen,

This is really great news for me to hear that the problem is gone :)
Now my tone mapping should be faster and more accurate.

Thank you Art!

Josselin.


This message was sent using IMP, the Internet Messaging Program.

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


Re: [osg-users] [osgPPU] HDR example: wrong average luminance?

2010-04-23 Thread josselin . petit

Hi Luca,

I'm working with the average value, I've found some problems, just  
like you. For me the two problems are :
- for each new mipmap level, where you have to perform the mean of the  
four pixels of the previous level, the mipmap_shader use values of the  
first mipmap level of the texture, and not the log10 values of the  
previous mipmap level

- the value of the last mipmap level is wrong.

The way I found is :
1. compute the log10 values of the entire texture in a first shader
2. then perform the mipmap with:
osgPPU::UnitInMipmapOut* sceneLuminance = new osgPPU::UnitInMipmapOut();
sceneLuminance-setName(ComputeSceneLuminance);
{
sceneLuminance-generateMipmapForInputTexture(0);
}
3. get the 5th or 6th level of the mipmapped texture, and perform the  
mean of this texture in a shader. You'll got your average luminance.


Hope this helps,
Josselin.


This message was sent using IMP, the Internet Messaging Program.

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


Re: [osg-users] Using HDRI to light models...

2010-03-02 Thread josselin . petit

Hi Alessandro,

For image-based lighting, you can have a look in the Orange Book  
(OpenGL Shading Language), chapter 12 (Lighting). There are some  
shaders for image-based lighting with a cube map, and you can use them  
with a HDR cube map (have a look in the osgvertexprogram for cube map  
example, and use the hdr or exr plugin to load your hdr images).


Best regards,
Josselin.




This message was sent using IMP, the Internet Messaging Program.

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


Re: [osg-users] [osgPPU] FFT users?

2010-02-25 Thread josselin . petit

Hi Art, Hi Jason,

Ok thanks for your answer, I will try with CUDA so.

Cheers,
Josselin.




This message was sent using IMP, the Internet Messaging Program.

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


[osg-users] [osgPPU] FFT users?

2010-02-23 Thread josselin . petit

Hi,

I just would like to know if someone already used a fft algorithm with  
osgPPU (for image processing), with pixel shaders or CUDA?


Or maybe could you tell me if it's difficult to use CUDA in osgPPU?  
I'm quite experimented with PPU but not with CUDA, and I would like to  
know how it could be difficult to use the FFT librairy of CUDA  
(http://developer.download.nvidia.com/compute/cuda/2_0/docs/CUFFT_Library_2.0.pdf).


Thanks in avance,
Josselin.


This message was sent using IMP, the Internet Messaging Program.

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


Re: [osg-users] light lobes and shadow maps

2010-01-14 Thread josselin . petit

Hi Nick,

This is not really an answer to your question, but for my application  
I used an attenuation factor (proportional to the squared distance) to  
avoid light behind obstacles (obstacles are generally far from my  
lights in my application). Maybe you can use one too.


By the way, could you tell me how many lights you have?

Josselin.


This message was sent using IMP, the Internet Messaging Program.

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


[osg-users] [osgPPU] Precision in osgPPU

2009-09-16 Thread josselin . petit


Hi everyone,

I would like to use osg PPU to compute very accurate data, about ten  
number behind the comma, to avoid numerical errors.


So I used 32 bits textures for the render to texture :
texture2D-setInternalFormat(GL_RGBA32F_ARB);
texture2D-setSourceFormat(GL_RGBA);
texture2D-setSourceType(GL_FLOAT);

texture2D-setWrap(osg::Texture2D::WRAP_S,osg::Texture2D::CLAMP_TO_BORDER);
texture2D-setWrap(osg::Texture2D::WRAP_T,osg::Texture2D::CLAMP_TO_BORDER);
texture2D-setWrap(osg::Texture2D::WRAP_R,osg::Texture2D::CLAMP_TO_BORDER);
texture2D-setFilter(osg::Texture2D::MIN_FILTER, osg::Texture2D::NEAREST);
texture2D-setFilter(osg::Texture2D::MAG_FILTER,osg::Texture2D::NEAREST);


But I noticed, by exemple, when I put the value 0.012024048 in one  
shader (gl_FragColor = vec(0.012024048, 0.012024048, 0.012024048,  
1.0);),

the value read in the next shader becomes 0.012023926.
I checked the values twice, once with the glsl Devil debugger, once  
with an UnitOutCapture.


Is there a way to have more precision for my data ?

Thanks in advance,
Josselin.


This message was sent using IMP, the Internet Messaging Program.

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


Re: [osg-users] [osgPPU] Precision in osgPPU

2009-09-16 Thread josselin . petit


Hi jp,

Thanks for your quick answer :)

I'm working with a nVidia GeForce 280, so I think it's ok for 32 bits  
textures and Cuda.


Thanks too for your two propositions. I'll tell you if one works...

Josselin.


This message was sent using IMP, the Internet Messaging Program.

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


Re: [osg-users] Transparency and hdr texture

2009-06-02 Thread josselin . petit

Hi Jason and Ragnar,

Thanks for answering.
I did'nt know that the OpenEXR format supports 16 bits per pixels and  
an alpha channel. Thanks for the link.


Josselin.


This message was sent using IMP, the Internet Messaging Program.

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


[osg-users] Transparency and hdr texture

2009-05-29 Thread josselin . petit

Hi,

Does anyone know an image format storing high dynamic range values (32  
bits per pixel) and transparency ?


Thanks,
Josselin


This message was sent using IMP, the Internet Messaging Program.

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


Re: [osg-users] Projective texture mapping with occluders/visibility computation

2009-05-05 Thread josselin . petit

Hi Max,

Well, one year ago I was ignorant too in OpenGL and shaders, now I'm  
still ignorant in OpenGL but I begin to understand how to use shaders  
;-)



For shaders, the first reference is the orange book (Addison Wesley -  
2006 - OpenGL Shading Language).


But here are some cool tutorials:
For toon shader, lighting, texturing:
http://www.lighthouse3d.com/opengl/glsl/

And the best tutorials I've found are here: (in French... I like it  
but maybe you not)

http://www.ozone3d.net/tutorials/index_glsl.php

In particularly, there is a tutorial which explains how to do  
projective texture mapping:

http://www.ozone3d.net/tutorials/glsl_texturing_p08.php#part_8


And to use shaders in OSG, you can find tutorials in the OSG website:
http://www.openscenegraph.org/projects/osg/wiki/Support/Tutorials


Hope this help :)
Josselin.





This message was sent using IMP, the Internet Messaging Program.

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


Re: [osg-users] Projective texture mapping with occluders/visibility computation

2009-04-27 Thread josselin . petit

Hi Max,

I'm not sure, but when you run your program, can't you see a line like :
Scaling image '../Data_Calibrage/Image/IMG_5316_small.jpg' from  
640,480 to 512,512 ?


Otherwise, to do projective texture mapping, personaly I'm using  
shaders since I have back projection problems with OpenGl texture  
mapping.


For OpenGl texture mapping, you can look in the osgspotlight exemple.

Hope that helps,
Josselin.


This message was sent using IMP, the Internet Messaging Program.

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


Re: [osg-users] HDR Skybox

2009-04-15 Thread josselin . petit

Hi Rob,

I think you forgot to set the data in the textureCubeMap in float,  
that's why you see strange colors for values above 1.0.


You can try this :

osg::TextureCubeMap* cubemap = new osg::TextureCubeMap;
cubemap-setInternalFormat(GL_RGBA16F_ARB);
cubemap-setSourceType(GL_FLOAT);
cubemap-setSourceFormat(GL_RGBA);
#define CUBEMAP_FILENAME(face)  
../../../OpenSceneGraph-Data/Cubemap_debevec/ #face .hdr


osg::Image* imagePosX = osgDB::readImageFile(CUBEMAP_FILENAME(posx));
osg::Image* imageNegX = osgDB::readImageFile(CUBEMAP_FILENAME(negx));
osg::Image* imagePosY = osgDB::readImageFile(CUBEMAP_FILENAME(posy));
osg::Image* imageNegY = osgDB::readImageFile(CUBEMAP_FILENAME(negy));
osg::Image* imagePosZ = osgDB::readImageFile(CUBEMAP_FILENAME(posz));
osg::Image* imageNegZ = osgDB::readImageFile(CUBEMAP_FILENAME(negz));

if (imagePosX  imageNegX  imagePosY  imageNegY  imagePosZ  
 imageNegZ)

{
cubemap-setImage(osg::TextureCubeMap::POSITIVE_X, imagePosX);
cubemap-setImage(osg::TextureCubeMap::NEGATIVE_X, imageNegX);
cubemap-setImage(osg::TextureCubeMap::POSITIVE_Y, imagePosY);
cubemap-setImage(osg::TextureCubeMap::NEGATIVE_Y, imageNegY);
cubemap-setImage(osg::TextureCubeMap::POSITIVE_Z, imagePosZ);
cubemap-setImage(osg::TextureCubeMap::NEGATIVE_Z, imageNegZ);

cubemap-setWrap(osg::Texture::WRAP_S, osg::Texture::CLAMP_TO_EDGE);
cubemap-setWrap(osg::Texture::WRAP_T, osg::Texture::CLAMP_TO_EDGE);
cubemap-setWrap(osg::Texture::WRAP_R, osg::Texture::CLAMP_TO_EDGE);

//cubemap-setFilter(osg::Texture::MIN_FILTER,  
osg::Texture::LINEAR_MIPMAP_LINEAR);

cubemap-setFilter(osg::Texture::MIN_FILTER, 
osg::Texture::LINEAR);
cubemap-setFilter(osg::Texture::MAG_FILTER, osg::Texture::LINEAR);

//cubemap-setResizeNonPowerOfTwoHint(false);
}

Hope this help :)
Josselin.


This message was sent using IMP, the Internet Messaging Program.

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


[osg-users] Projective texture / TexGen / Back Projection

2009-01-14 Thread josselin . petit

Hi,

I would like to have car headlights in my driving simulator, so I use  
the TexGen class (with EYE_LINEAR) to do that. Like in the spotlight  
example, I have a nice spotlight, but with one artefact, which comes  
from the fact that the matrix math used produces a BACK PROJECTION.


I've read that this artifact has historically been avoided by using a  
special black and white texture 1D to cut away unnecessary projecting  
contributions... but how to do that in OSG ? Have someone experimented  
this way ?


Thanks in advance,
Josselin.


This message was sent using IMP, the Internet Messaging Program.

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


Re: [osg-users] Tone mapping algorithms

2008-11-19 Thread josselin . petit

Hi all,

Really no one for tone mapping ?

Ok, maybe I have to give more informations. So here is how I'm doing  
until today  (sorry the length of the mail, but there is a lot of  
informations ;-). Please, if you're interested by the subject and if  
you have any suggestion, give answer !


- I want to set up the Reinhard's tone mapping algorithm (in  
Photographic Tone Reproduction for Digital Images, 2002). This is  
the simplest tone mapping algorithm, it gives very nice results, and  
is real-time computable.


0. To do that, I think (tell me if I'm wrong) that the best way is to  
use OSG PPU.


1. The first thing that we have to do is to load an hdr image, we can  
find some of them in the website of Debevec  
(http://www.debevec.org/Research/HDR/ , take picture(s) in .hdr format).

To use this kind of image in OSG PPU, just change these lines in osgppu.cpp:
osg::Node* loadedModel = osgDB::readNodeFiles(arguments);
if (!loadedModel) loadedModel = createTeapot();
with these lines (be carreful with the path of the image):
osg::Image* image = osgDB::readImageFile(Data/Images/memorial.hdr);
osg::Geode* loadedModel = osg::createGeodeForImage(image);

With these new lines, we are now working with a HDR image in the HDR  
pipeline defined by Art Tevs in hdrppu.h :-)


2. Using a glslDebugger like glslDevil, we can see that values in the  
HDR image are not in candela/m² (bug in the hdr loader ?). Anyway,  
it's not really important, we can just put a factor 1000 in the first  
shader used in the hdr pipeline (Data/glsl/luminance_fp.glsl). So  
replace this line :
gl_FragColor.xyz = vec3( texColor0.r * 0.2125 + texColor0.g * 0.7154 +  
texColor0.b * 0.0721 );

with this line :
gl_FragColor.xyz = 1000.0 * vec3( texColor0.r * 0.2125 + texColor0.g *  
0.7154 + texColor0.b * 0.0721 );


3. So now we are working with an hdr image in candela/m². With the  
first shader, we have computed a black and white image (or intensity  
image), because we have next to compute the mean of this intensity  
image. Here difficulties are beginning for me...
The HDR Pipeline uses the InitInMipmapOut Unit, the goal is to create  
a Mipmapped Texture with the shader  
(Data/glsl/luminance_mipmap_fp.glsl).

On the level 0, we have the input texture.
On the level 1, we have the log of the input texture, with half  
resolution of the input texture.
On the level 2, we have the mean of the level 1, with half resolution  
of the level 1.

On the level 3, ...
On the level 8, we have the mean of the input image.

Problems I've seen are :
- data computed in the level 1 (log-values) are lost when we want use  
them for the level 2 (we're using non log-values, we can see that with  
glslDebugger)
- we can't pass the value of the level 8 to the next unit, so  
fLuminance value is lost.


I've no answer to these problems, so if someone have... send me a mail ;-)

4. To ending, we just have to compute the tone mapping algorithm in  
the shader of the hdr Unit: here is my code (sorry, comments are in  
french ;-) to put in (Data/glsl/Reinhard sale/tonemap_hdr_2_fp.glsl):

--
// hdr texture containing the scene
uniform sampler2D hdrInput;

// Luminance input
uniform sampler2D lumInput;

/**
 **/
void main(void)
{
vec3 RGB, XYZ;
vec4 texel;
float at, x, y;
// pour avoir des candela/m²
float factor = 1000.0;

mat3 xyz2rgb = mat3(3.240479, -1.537150, -0.498535,
 -0.969256,  1.875992,  0.041556,
0.055648, -0.204043,  1.057311);
mat3 rgb2xyz = mat3(0.4125, 0.3576, 0.1804,
  0.2127, 0.7152, 0.0722,
  0.0193, 0.1192, 0.9502);

// coordonnées du pixel
vec2 inTex = gl_TexCoord[0].st;

// get adapted, normal and scaled luminance
// ie luminance d'adaptation
//float fLuminance = texture2D(lumInput, inTex, 100.0).w;
float fLuminance = 50.0;

// texture
texel = factor * texture2D(hdrInput,inTex);
//texel = texture2D(hdrInput,inTex);

// conversion en XYZ - début du tone mapping
XYZ = rgb2xyz * texel.rgb;

// calcul de x et y pour sauvegarder la couleur
if ((XYZ[0] + XYZ[1] + XYZ[2])  0.0)
{
x = XYZ[0] / (XYZ[0] + XYZ[1] + XYZ[2]);
y = XYZ[1] / (XYZ[0] + XYZ[1] + XYZ[2]);
}
else
{
x = 0.0;
y = 0.0;
}

// prise en compte de la luminance d'adaptation
// ds le tone mapping
XYZ[1] = 0.18 * XYZ[1] / fLuminance;

// tone mapping sur la luminance
XYZ[1] = XYZ[1] / (1.0 + XYZ[1]);

// calcul de l'image XYZ tone mappée
if (y  0.0)
{
XYZ[0] = x / y * XYZ[1];
XYZ[2] = XYZ[1] / y * (1.0 - x - y);
}

// calcul de l'image RGB 

[osg-users] Tone mapping algorithms

2008-11-05 Thread josselin . petit

Hi,

I just would like to know if some persons have implemented some tone  
mapping algorithms in OSG (others that the one in OSG PPU, like  
Reinhard in Photographic Tone Reproduction for Digital Images in  
2002 or others algorithms), using OSG PPU or not.


I would like to know if you have some problems with these algorithms  
(like me...), particulary with the computation of the log-average  
luminance of the high dynamic range image.


Else, what results have you ? Nice rendering ? Good frame rate ?

Thanks in advance,
Josselin Petit.


This message was sent using IMP, the Internet Messaging Program.

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


Re: [osg-users] Bug with hdr data rescaling in a texture 2D

2008-08-29 Thread josselin . petit

Hi Robert,

Thanks for your answer.

My hdr image is 2272 * 1704 pixels, and is automatically rescaled by  
gluScaleImage called form Texture2D::aplly(). But I use the  
setResizeNonPowerOfTwoHint(false) function on the hdrTexture, and my  
image is fine :-)


Thanks !

Josselin.



This message was sent using IMP, the Internet Messaging Program.

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


[osg-users] Bug with hdr data rescaling in a texture 2D

2008-08-28 Thread josselin . petit

Hi all,

I think there is a bug when we rescale an hdr image in a 16 bits  
texture : I can see strange colors where values are greater than 1.0,  
but when we rescale the hdr image with an other software, the image is  
fine.


Is it a known bug ?

Thanks in advance,
Josselin.


This message was sent using IMP, the Internet Messaging Program.

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


Re: [osg-users] 2 spotlights with the spotlight example ?

2008-08-27 Thread josselin . petit

Hi Paul,

First thanks for your answer.

I think that if we comment out the texture2-setImage() call, we don't  
use the second spotlight. So we see just one spotlight with the red  
light, and sometimes the green too (but the two lights and the  
spotlight are independant).


For my application, I'm trying to have 2 separated spotlights. Lights  
are ok, but there is clearly a problem with spotlight, maybe the  
lookAt() function in :


texgen2-setPlanesFromMatrix(osg::Matrixd::lookAt(position2,  
position2+direction, up)*osg::Matrixd::perspective(angle,1.0,0.1,100));


but I've not found any solution yet...

Josselin.


This message was sent using IMP, the Internet Messaging Program.

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


[osg-users] 2 spotlights with the spotlight example ?

2008-07-31 Thread josselin . petit

Hello,

I'm new in OSG.

I would like to have 2 spotlights in the spotlight example. I created  
a second spotlight, a second texgen and a texgennode associated, I  
enabled my second light, assigned texturesAttibutesAndModes, but that  
don't work (with just one light that works fine).


Any Idea about this problem? (you can find the code below)

Thanks in advance,

Josselin.



#include osg/Notify
#include osg/MatrixTransform
#include osg/ShapeDrawable
#include osg/PositionAttitudeTransform
#include osg/Geometry
#include osg/Texture2D
#include osg/Geode
#include osg/LightSource
#include osg/TexGenNode

#include osgUtil/Optimizer

#include osgDB/Registry
#include osgDB/ReadFile

#include osgViewer/Viewer
#include iostream

// for the grid data..
#include terrain_coords.h

osg::Image* createSpotLightImage(const osg::Vec4 centerColour, const  
osg::Vec4 backgroudColour, unsigned int size, float power)

{
osg::Image* image = new osg::Image;
image-allocateImage(size,size,1,GL_RGBA,GL_UNSIGNED_BYTE);


float mid = (float(size)-1)*0.5f;
float div = 2.0f/float(size);
for(unsigned int r=0;rsize;++r)
{
unsigned char* ptr = image-data(0,r,0);
for(unsigned int c=0;csize;++c)
{
float dx = (float(c) - mid)*div;
float dy = (float(r) - mid)*div;
float r = powf(1.0f-sqrtf(dx*dx+dy*dy),power);
if (r0.0f) r=0.0f;
osg::Vec4 color = centerColour*r+backgroudColour*(1.0f-r);
*ptr++ = (unsigned char)((color[0])*255.0f);
*ptr++ = (unsigned char)((color[1])*255.0f);
*ptr++ = (unsigned char)((color[2])*255.0f);
*ptr++ = (unsigned char)((color[3])*255.0f);
			//std::cout  ((color[0])*255.0f)  ,   ((color[1])*255.0f)  
 ,   ((color[2])*255.0f)  .  std::endl;

}
}
return image;
}

osg::StateSet* create2SpotLightDecoratorState(unsigned int lightNum1,  
unsigned int textureUnit1, unsigned int lightNum2, unsigned int  
textureUnit2)

{
osg::StateSet* stateset = new osg::StateSet;

stateset-setMode(GL_LIGHT0+lightNum1, osg::StateAttribute::ON);
stateset-setMode(GL_LIGHT0+lightNum2, osg::StateAttribute::ON);

osg::Vec4 centerColour(1.0f,1.0f,1.0f,1.0f);
osg::Vec4 ambientColour(0.05f,0.05f,0.05f,1.0f);

// set up spot light texture
	osg::Image* spotLightImage = createSpotLightImage(centerColour,  
ambientColour, 64, 1.0);


osg::Texture2D* texture1 = new osg::Texture2D();

texture1-setImage(spotLightImage);  // blanc au milieu, plus  
sombre sur les cotés

texture1-setBorderColor(osg::Vec4(ambientColour));
texture1-setWrap(osg::Texture::WRAP_S,osg::Texture::CLAMP_TO_BORDER);
texture1-setWrap(osg::Texture::WRAP_T,osg::Texture::CLAMP_TO_BORDER);
texture1-setWrap(osg::Texture::WRAP_R,osg::Texture::CLAMP_TO_BORDER);

stateset-setTextureAttributeAndModes(textureUnit1, texture1,  
osg::StateAttribute::ON);
//stateset-setTextureAttributeAndModes(textureUnit1, texture1,  
osg::StateAttribute::PROTECTED);



osg::Texture2D* texture2 = new osg::Texture2D();
texture2-setImage(spotLightImage);
texture2-setBorderColor(osg::Vec4(ambientColour));
texture2-setWrap(osg::Texture::WRAP_S,osg::Texture::CLAMP_TO_BORDER);
texture2-setWrap(osg::Texture::WRAP_T,osg::Texture::CLAMP_TO_BORDER);
texture2-setWrap(osg::Texture::WRAP_R,osg::Texture::CLAMP_TO_BORDER);

	stateset-setTextureAttributeAndModes(textureUnit2, texture2,  
osg::StateAttribute::ON);
	//stateset-setTextureAttributeAndModes(textureUnit2, texture2,  
osg::StateAttribute::PROTECTED);


// set up tex gens
stateset-setTextureMode(textureUnit1, GL_TEXTURE_GEN_S,  
osg::StateAttribute::ON);
stateset-setTextureMode(textureUnit1, GL_TEXTURE_GEN_T,  
osg::StateAttribute::ON);
stateset-setTextureMode(textureUnit1, GL_TEXTURE_GEN_R,  
osg::StateAttribute::ON);
stateset-setTextureMode(textureUnit1, GL_TEXTURE_GEN_Q,  
osg::StateAttribute::ON);
stateset-setTextureMode(textureUnit2, GL_TEXTURE_GEN_S,  
osg::StateAttribute::ON);
stateset-setTextureMode(textureUnit2, GL_TEXTURE_GEN_T,  
osg::StateAttribute::ON);
stateset-setTextureMode(textureUnit2, GL_TEXTURE_GEN_R,  
osg::StateAttribute::ON);
stateset-setTextureMode(textureUnit2, GL_TEXTURE_GEN_Q,  
osg::StateAttribute::ON);


return stateset;
}


osg::Node* create2SpotLightNode(const osg::Vec3 direction, float  
angle, unsigned int lightNum1, unsigned int textureUnit1, unsigned int  
lightNum2, unsigned int textureUnit2)

{
osg::Group* group = new osg::Group;

osg::Vec3 position1 = osg::Vec3(0.f, 0.f, 0.f);
osg::Vec3 position2 = osg::Vec3(40.f, 40.f, 10.f);

// create first light source.
osg::LightSource* lightsource1 = new osg::LightSource;
//lightsource1-setLocalStateSetModes(osg::StateAttribute::ON);
	//lightsource1-setStateSetModes(*lightsource1-getStateSet(),  
osg::StateAttribute::ON);

osg::Light* light1 =