Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Leyder Dylan

Per Pixel Lighting -> GL_TEXTURE_3D

This topic is 5364 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, Instead of using a 2D texture and a 1D texture for the light, I'd like to use a 3D texture. So, I've writtent the code for initialising it but the initialisation failed. Is there a problem ?
/*

	Slug Production	(c)	2003 - http://www.slug-production.be.tf/

	File : "GL_EXT_texture_3D.cpp"
	  
	Programmed by : Leyder Dylan (slug-production@be.tf)

*/


# include <windows.h>
# include <gl\gl.h>

# include "GLExt.h"
# include "Texture-3D.h"


// EXT Texture 3D Initialisation

PFNGLTEXIMAGE3DEXTPROC glTexImage3DEXT = NULL;

// The Texture_3D is supported or not ? By default, not supported

bool EXT_Texture_3D = false;


// **********************************************

bool Init_Texture_3D()
{
    
	// The name of the extension

	char *Extension;

    Extension = (char *) glGetString(GL_EXTENSIONS);
   
    if (!(strstr(Extension, "GL_EXT_texture3D")) == 1)
		{ 
			// The "GL_EXT_texture3D" extension is not supported

			MessageBox(NULL,"'GL_EXT_texture3D'","ERROR : Extension not supported :",MB_ICONERROR);
		} 
	
	else 
		{
			// The "GL_EXT_texture3D" is supported

			
			// EXT Texture 3D Initialisation

			glTexImage3DEXT     =  (PFNGLTEXIMAGE3DEXTPROC)     wglGetProcAddress("GL_EXT_texture3D");
      
			// EXT Texture 3D Initialisation failed !

			if (!glTexImage3DEXT)
				{
					MessageBox(NULL,"GL_EXT_texture3D","ERROR : Initialisation failed !",MB_ICONERROR);
					
					return false;
				}
		}

	return true;

}
I've a GeForce 4 4200 Ti and it supports the extension. Thanks all. ======================== Leyder Dylan (dylan.leyder@slug-production.be.tf http://www.slug-production.be.tf/ [edited by - Leyder Dylan on October 9, 2003 5:57:49 PM]

Share this post


Link to post
Share on other sites
Advertisement
replace
glTexImage3DEXT = (PFNGLTEXIMAGE3DEXTPROC) wglGetProcAddress("GL_EXT_texture3D");
with
glTexImage3DEXT = (PFNGLTEXIMAGE3DEXTPROC) wglGetProcAddress("glTexImage3DEXT");

typo?

Share this post


Link to post
Share on other sites
Oups, got it.

Tryed to initialise an extension as a function.

Now, the extension is loaded correctly but when I want to generate a 3D texture, I've an error "the memory can not be read..."

According the "OpenGL 1.2", there's no errors in this code :


glBindTexture(GL_TEXTURE_3D, Texture_TGA[Loop_02].Texture_ID);

glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);

glTexParameteri(GL_TEXTURE_3D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_3D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);

glTexImage3DEXT(GL_TEXTURE_3D, 0, GL_RGB, Texture_TGA[Loop_02].width, Texture_TGA[Loop_02].height, Texture_TGA[Loop_02].height, 0, GL_RGB, GL_UNSIGNED_BYTE, Texture_TGA[Loop_02].imageData);


For the "depth" parameter of the 3D texture, I use the height or the width of the texture. The problem comes from that ?

Thanks sir.

========================
Leyder Dylan (dylan.leyder@slug-production.be.tf
http://www.slug-production.be.tf/

[edited by - Leyder Dylan on October 9, 2003 12:40:37 AM]

Share this post


Link to post
Share on other sites
You are probably accessing memory out of bounds.

Since you are trying to do light falloff function you can use GL_INTENSITY(or GL_ALPHA) instead of GL_RGB. You also have to apply glTexParameteri to all 3 axis (S,T,R).

Try something like this:


int textureID = 0;
int width = 64;
int height = 64;
int depth = 64; // might be called "slices" or something less confusing
unsigned char* data = new unsigned char[ width * height * depth ];
// fill this data here with some nice fall-off function
//...
glGenTextures( 1, &textureID );
glBindTexture( GL_TEXTURE_3D, textureID );
glTexParameteri( GL_TEXTURE_3D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE );
glTexParameteri( GL_TEXTURE_3D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE );
glTexParameteri( GL_TEXTURE_3D, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE );

glTexParameteri( GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
glTexParameteri( GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );

glTexImage3DEXT( GL_TEXTURE_3D, 0, GL_INTENSITY, width, height, depth, 0, GL_INTENSITY, GL_UNSIGNED_BYTE, data );


You should never let your fears become the boundaries of your dreams.

Share this post


Link to post
Share on other sites
Ok thanks but the problem is that I need to add a depth to my texture.

My texture has a height and width BUT NO DEPTH.

It''s possible to add the depth to a texture ?

I searched on the web and every demo generates a 3D texture himself not from a external texture (tga or jpg or ...)

So the problem is the depth ...

========================
Leyder Dylan (dylan.leyder@slug-production.be.tf
http://www.slug-production.be.tf/

Share this post


Link to post
Share on other sites
That''s because tga or jpg are picture format for 2D images, as most formats on the web.
Your best bet is to take a stack of images having the same prefix and the suffix as id for instance :
[ image00.jpg image01.jpg image02.jpg ... image63.jpg ]

Otherwise you would have to go into other exotic picture formats but I don''t know any good one that supports 3D pictures.

As for the purpose of testing, you can simply consider depth==1 and load any jpeg or tga image : it will do the trick, and will allow you at least to test if 3D texture is mounted to the graphics card correctly and if rendering is supported in hardware.

Share this post


Link to post
Share on other sites
I realy don''t understand what are you trying to do. You can''t simply add another dimension to texture. Why do you need 3D texture for?

You should never let your fears become the boundaries of your dreams.

Share this post


Link to post
Share on other sites
_DarkWIng_,

With a 2D Texture, I need to use 2 texture units for lighting a scene with Per Pixel Lighting.

---------------------
Why 2 texture units ?
---------------------

The first texture unit is used for the coordinates (x,y) :

glMultiTexCoord2f(GL_TEXTURE_2D,X,Y);


The second texture unit is used for the coordinates (z) :

glMultiTexCoord1f(GL_TEXTURE_2D,Z);




For the moment I used only 2 2D textures. I'll update the code for using a 1D texture and a 2D texture.





With a 3D texture, I need only one texture unit for lighting a scene with Per Pixel Lighting.

The texture unit is used for the coordinates (x,y,z) :


glMultiTexCoord3f(GL_TEXTURE_2D,X,Y,Z);


Each solution has some problems :

GL_TEXTURE_2D
Advantages : - Relatively low hardware requirements
Disadvantages : - 2 texture units used


GL_TEXTURE_3D
Advantages : - 1 texture unit used
Disadvantages : - Required the "GL_EXT_texture3D" extension

Hope this light your mind a little bit




Vincoof,

You're right for the trick, it works but not well.

Here're 2 screenshots (I'm lighting a box (6 faces) ) with a 2D Texture :

- When I start the program, I've this :




- When I light a corner of the box, I've this :



Not bad don't you ? But I need to fix the 1D texture as you can see on the back face. The ground texture is OK but the wall texture is "rectangular".




Now, with the 3D Texture :

- When I start the program, I've this :



==> First, the problem comes from the "Y" texture coordinate. The program doesn't care of it.


- When I light a corner of the box, I've this :



On "Y" again, the texture is rectangular.



So for me :
- Does the problem come from the fake 2D texture (your trick) ?
- Are some parameters not correctly set up ?

I followed your idea, the texture is a 2D one generated in a 3D one with depth = 1.

Next take a look on the following code :

   
// We set the Texture Coord.

glMultiTexCoord3fARB(GL_TEXTURE0_ARB, s, t, r);
//glMultiTexCoord4fARB(GL_TEXTURE0_ARB, s, t, r, 0.5f);



I've tryed the 3f with X, Y, Z as parameters. Next, I tryed with the 4f with X, Y, Z, 1.0f as parameters but the result is the same.

For me, again, the problem comes from the trick ...

Any idea ?

Thanks.

========================
Leyder Dylan (dylan.leyder@slug-production.be.tf
http://www.slug-production.be.tf/


[edited by - Leyder Dylan on October 10, 2003 4:56:45 PM]

Share this post


Link to post
Share on other sites
OK. So you are using 3D texture for distance attenuation. I tought so but you were talking about loading textures so animated normal maps also came to mind. I used both in my shaders.
Then it should be better if you just build texture form some formula at load time instead of loading texture from disk. It alos saves you some space.
You can use something like :
dist = distance from point to center
value = (1-(dist^2))^2
clamp value to [0..1] range.

If you need full code to generate this texture I'll post some old source code.


(To use vincoofs idea you just replace 2D texture with 3D, but still keep the 1D. This is just to test if your 3D texure loads correctly.)

You should never let your fears become the boundaries of your dreams.

[edited by - _DarkWIng_ on October 10, 2003 5:23:48 PM]

Share this post


Link to post
Share on other sites
To all, you'll find a demo for both (2D and 3D texture using) on my website.

You'll see yourself what's wrong but I hope that for the next week, the code will be OK and that I could release the source code.

Thanks Drakwing, I'll try to generate a 3D texture at the runtime.

For :

quote:

You can use something like :
dist = distance from point to center
value = (1-(dist^2))^2
clamp value to [0..1] range.



For me, the problem comes from the fake 3D texture.

Because with 2 textures, everything is OK. But thanks anyway.

For :

quote:
(To use vincoofs idea you just replace 2D texture with 3D, but still keep the 1D. This is just to test if your 3D texure loads correctly.)


I tested that, so for you it's not a good idea for only using a 3D texture for lighting a scene ?

What about your lighting engine ? It's possible to have some screenshots ?

========================
Leyder Dylan (dylan.leyder@slug-production.be.tf
http://www.slug-production.be.tf/

[edited by - Leyder Dylan on October 10, 2003 7:05:55 PM]

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!