"...for you it''s not a good idea for only using a 3D texture for lighting a scene?..."
It is a good idea, but you have to generate full 3D texture not use just one plane (2D) of it. What vincoof sugested was just to test if your 3D texture loading even works. For making real use of it you have to use full 3d texture. 64x64x64 will be large enough.
I''ll try to make a small demo from old engine. (might take some time)
You should never let your fears become the boundaries of your dreams.
Per Pixel Lighting -> GL_TEXTURE_3D
quote:It is a good idea, but you have to generate full 3D texture not use just one plane (2D) of it. What vincoof sugested was just to test if your 3D texture loading even works. For making real use of it you have to use full 3d texture. 64x64x64 will be large enough.
Yes, Vincoof''s idea was good, but now, I''ll try to generate a 3D texture while the OpenGL initialisation and we will see ...
quote:I''ll try to make a small demo from old engine. (might take some time)
Thanks and no problem for the time.
========================
Leyder Dylan (dylan.leyder@slug-production.be.tf
http://www.slug-production.be.tf/
DarkWing's right about the fact that I simply proposed to test the 3D texture functionality by using a 3D texture wth depth==1. At least it shows that function pointers are initialized coorectly and the new tokens are used accordingly. With that said, the sole purpose was test
I think it's pretty easy to compute an attenuation cube from scratch. From the top of my head, I would write something like :
GLuint generateAttenuationTexture3D(GLuint size)
{
GLuint tex;
GLint x, y, z;
GLubyte *data;
GLfloat fsize = (GLfloat)size - 1.f;
GLfloat fcenter = .5f * fsize;
data = new GLubyte[size*size*size];
for (x = 0; x < size; x++)
for (y = 0; y < size; y++)
for (z = 0; z < size; z++)
{
GLfloat fx = ((GLfloat)x-fcenter)/fsize;
GLfloat fy = ((GLfloat)y-fcenter)/fsize;
GLfloat fz = ((GLfloat)z-fcenter)/fsize;
GLint index = z*size*size+y*size+x;
GLfloat fdistance;
GLubyte byte;
fdistance = (GLfloat)sqrt(fx*fx + fy*fy + fz*fz);
if (fdistance >= 1.f) byte = 0;
else if (fdistance <= 0.f) byte = 255;
else byte = 255.f * (1.f - fdistance);
data[index] = byte;
}
glGenTextures(1, &tex);
glBindTexture(GL_TEXTURE_3D_EXT, tex);
glTexParameteri(GL_TEXTURE_3D_EXT, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_3D_EXT, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexImage3D(GL_TEXTURE_3D_EXT, 0, GL_LUMINANCE, size, size, size, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, data);
delete[] data;
return tex;
}
Then call :
GLuint my3DTex = generateAttenuationTexture3D(64);
and bind this object whenever you want :
glBindTexture(GL_TEXTURE_3D_EXT, my3DTex);
glEnable(GL_TEXTURE_3D_EXT);
[edit: typo]
[edited by - vincoof on October 13, 2003 8:32:54 AM]
I think it's pretty easy to compute an attenuation cube from scratch. From the top of my head, I would write something like :
GLuint generateAttenuationTexture3D(GLuint size)
{
GLuint tex;
GLint x, y, z;
GLubyte *data;
GLfloat fsize = (GLfloat)size - 1.f;
GLfloat fcenter = .5f * fsize;
data = new GLubyte[size*size*size];
for (x = 0; x < size; x++)
for (y = 0; y < size; y++)
for (z = 0; z < size; z++)
{
GLfloat fx = ((GLfloat)x-fcenter)/fsize;
GLfloat fy = ((GLfloat)y-fcenter)/fsize;
GLfloat fz = ((GLfloat)z-fcenter)/fsize;
GLint index = z*size*size+y*size+x;
GLfloat fdistance;
GLubyte byte;
fdistance = (GLfloat)sqrt(fx*fx + fy*fy + fz*fz);
if (fdistance >= 1.f) byte = 0;
else if (fdistance <= 0.f) byte = 255;
else byte = 255.f * (1.f - fdistance);
data[index] = byte;
}
glGenTextures(1, &tex);
glBindTexture(GL_TEXTURE_3D_EXT, tex);
glTexParameteri(GL_TEXTURE_3D_EXT, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_3D_EXT, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexImage3D(GL_TEXTURE_3D_EXT, 0, GL_LUMINANCE, size, size, size, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, data);
delete[] data;
return tex;
}
Then call :
GLuint my3DTex = generateAttenuationTexture3D(64);
and bind this object whenever you want :
glBindTexture(GL_TEXTURE_3D_EXT, my3DTex);
glEnable(GL_TEXTURE_3D_EXT);
[edit: typo]
[edited by - vincoof on October 13, 2003 8:32:54 AM]
Thanks again Vincoof for having wasted your time for me, but I''ve found the solution.
I''ve not tryed your code because mine works. It''s pretty the same as yours :
As you can see, the result is perfect :
But, I''ve a last bug, in fact, it''s not a bug, it''s a setup.
The bug comes from thr Register Combiners and I need to correctly setting up the RC because :
I''ve 2 solutions to fix it :
1. Inverter the attenuation texture generation color
2. Setup up the RC
I want the 2 solutions, because it''s more logical, but I''m not a gouru with the RC, so if someone can help me to set up the RC, here''s the code :
========================
Leyder Dylan (dylan.leyder@slug-production.be.tf
http://www.slug-production.be.tf/
I''ve not tryed your code because mine works. It''s pretty the same as yours :
/* Slug Production (c) 2003 - http://www.slug-production.be.tf/ File : "Attenuation_3D_Texture_Generation.cpp" Programmed by : Leyder Dylan (slug-production@be.tf)*/# include <windows.h># include <gl\gl.h># include <math.h># include "GLExt.h"// EXT Texture 3D Initialisationextern PFNGLTEXIMAGE3DEXTPROC glTexImage3DEXT;// The Attenuation 3D TextureGLuint Attenuation_3D_Texture;// Attenuation 3D Texture GenerationGLuint Attenuation_3D_Texture_Generation(const int Attenuation_3D_Texture_Size){ // Create a strip of data for our 1d texture GLubyte * attenData=new GLubyte[Attenuation_3D_Texture_Size]; // Unable to create space to hold attenuation texture data if (!attenData) return false; // Attenuation 3D Texture Generation for(int i = 0; i < Attenuation_3D_Texture_Size; ++ i) { // Get distance from centre to this point float dist = (float)i; dist -= (float)Attenuation_3D_Texture_Size / 2 - 0.5f; dist /= (float)Attenuation_3D_Texture_Size / 2 - 0.5f; // Square and Clamp to [0,1] dist = dist * dist; if(dist > 1.0f) dist = 1.0f; if(dist < 0.0f) dist = 0.0f; // Fill this in as color attenData[i] = GLubyte(dist * 255); // Make sure the color is 255 at the edges attenData[0] = 255; attenData[Attenuation_3D_Texture_Size - 1] = 255; } // The 3D Texture Size GLubyte * Attenuation_3D_Texture_Data = new GLubyte[Attenuation_3D_Texture_Size * Attenuation_3D_Texture_Size * Attenuation_3D_Texture_Size]; // Unable to create space to hold attenuation texture data if(!Attenuation_3D_Texture_Data) return false; int currentByte = 0; GLubyte dataI, dataJ, dataK; for(i = 0; i < Attenuation_3D_Texture_Size; ++ i) { dataI = attenData[i]; for(int j = 0; j < Attenuation_3D_Texture_Size; ++ j) { dataJ = attenData[j]; for(int k = 0; k < Attenuation_3D_Texture_Size; ++ k) { dataK = attenData[k]; GLuint newData; newData = dataI+dataJ+dataK; if(newData > 255) newData = 255; // Invert data as there is no need to do any more summing // Thus the invert need not wait until the register combiners newData = 255 - newData; Attenuation_3D_Texture_Data[currentByte] = newData; ++ currentByte; } } } glGenTextures(1, &Attenuation_3D_Texture); glBindTexture(GL_TEXTURE_3D_EXT, Attenuation_3D_Texture); glTexParameteri(GL_TEXTURE_3D_EXT, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_3D_EXT, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_3D_EXT, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_3D_EXT, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_3D_EXT, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE); glTexImage3DEXT(GL_TEXTURE_3D_EXT, 0, GL_INTENSITY8, Attenuation_3D_Texture_Size, Attenuation_3D_Texture_Size, Attenuation_3D_Texture_Size, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, Attenuation_3D_Texture_Data); // Delete Attenuation 3D Texture Data if(Attenuation_3D_Texture_Data) delete [] Attenuation_3D_Texture_Data; Attenuation_3D_Texture_Data = NULL; return Attenuation_3D_Texture;}
As you can see, the result is perfect :
But, I''ve a last bug, in fact, it''s not a bug, it''s a setup.
The bug comes from thr Register Combiners and I need to correctly setting up the RC because :
I''ve 2 solutions to fix it :
1. Inverter the attenuation texture generation color
2. Setup up the RC
I want the 2 solutions, because it''s more logical, but I''m not a gouru with the RC, so if someone can help me to set up the RC, here''s the code :
// **********************************************void Setup_Register_Combiners() // Setup the Register Combiners{ // Register Combiners Initialisation. We use 1 Register glCombinerParameteriNV(GL_NUM_GENERAL_COMBINERS_NV, 1); // Light Color float Light_Color[] = { 1.0f, 1.0f, 1.0f, 1.0f }; // We give the Light Color params to the Register Combiners glCombinerParameterfvNV(GL_CONSTANT_COLOR0_NV, (float *) &Light_Color); // Register Combiners Calcul for the Light Attenuation // ( 1 * Texture0 + 1 * Texture1) glCombinerInputNV(GL_COMBINER0_NV, GL_RGB, GL_VARIABLE_A_NV, GL_TEXTURE0_ARB, GL_UNSIGNED_IDENTITY_NV, GL_RGB); glCombinerInputNV(GL_COMBINER0_NV, GL_RGB, GL_VARIABLE_B_NV, GL_ZERO, GL_UNSIGNED_INVERT_NV, GL_RGB); glCombinerInputNV(GL_COMBINER0_NV, GL_RGB, GL_VARIABLE_C_NV, GL_TEXTURE1_ARB, GL_UNSIGNED_IDENTITY_NV, GL_RGB); glCombinerInputNV(GL_COMBINER0_NV, GL_RGB, GL_VARIABLE_D_NV, GL_ZERO, GL_UNSIGNED_INVERT_NV, GL_RGB); glCombinerOutputNV(GL_COMBINER0_NV, GL_RGB, GL_DISCARD_NV, GL_DISCARD_NV, GL_SPARE0_NV, GL_NONE, GL_NONE, GL_FALSE, GL_FALSE, GL_FALSE); // Final Register Combiners Initialisation with "(1 - Attenuation) * Color" calcul glFinalCombinerInputNV(GL_VARIABLE_A_NV, GL_SPARE0_NV, GL_UNSIGNED_IDENTITY_NV, GL_RGB); glFinalCombinerInputNV(GL_VARIABLE_B_NV, GL_ZERO, GL_UNSIGNED_IDENTITY_NV, GL_RGB); glFinalCombinerInputNV(GL_VARIABLE_C_NV, GL_CONSTANT_COLOR0_NV, GL_UNSIGNED_IDENTITY_NV, GL_RGB); glFinalCombinerInputNV(GL_VARIABLE_D_NV, GL_ZERO, GL_UNSIGNED_IDENTITY_NV, GL_RGB); glFinalCombinerInputNV(GL_VARIABLE_G_NV, GL_ZERO, GL_UNSIGNED_INVERT_NV, GL_ALPHA); // We enable the Register Combiners glEnable(GL_REGISTER_COMBINERS_NV);}
========================
Leyder Dylan (dylan.leyder@slug-production.be.tf
http://www.slug-production.be.tf/
Oups, I forgot the say : The Lighting with 3D Texture demo has been updated so you can re-download it the see the result and send me feedback (if you want).
Thanks
========================
Leyder Dylan (dylan.leyder@slug-production.be.tf
http://www.slug-production.be.tf/
[edited by - Leyder Dylan on October 13, 2003 11:37:47 AM]
Thanks
========================
Leyder Dylan (dylan.leyder@slug-production.be.tf
http://www.slug-production.be.tf/
[edited by - Leyder Dylan on October 13, 2003 11:37:47 AM]
Great. You made it work. In to fix the problem in RC replace GL_UNSIGNED_IDENTITY_NV with GL_UNSIGNED_INVERT_NV on unit using attenuation texture. But it would be more logical to use inverted texture. It should be full white in center and full black at edges.
You should never let your fears become the boundaries of your dreams.
You should never let your fears become the boundaries of your dreams.
The texture has a white center and black border.
Now, I''ve used "GL_UNSIGNED_INVERT_NV" and that''s correct !
Thanks a million to you all, especially "Vincoof" and "_DarkWIng_" for your help.
I don''t have the time now to update the website, I''ll do that tomorrow.
Thanks a million again ...
========================
Leyder Dylan (dylan.leyder@slug-production.be.tf
http://www.slug-production.be.tf/
Now, I''ve used "GL_UNSIGNED_INVERT_NV" and that''s correct !
Thanks a million to you all, especially "Vincoof" and "_DarkWIng_" for your help.
I don''t have the time now to update the website, I''ll do that tomorrow.
Thanks a million again ...
========================
Leyder Dylan (dylan.leyder@slug-production.be.tf
http://www.slug-production.be.tf/
OK, now I''ve updated the demos : "Lighting with 3D Texture".
The source code will probably beeing release tomorrow (tuesday) in the afternoon.
I''ve only 2 things to fix :
- Clean and comment a maximum the source code.
- Use an ASCII file for the ARB String.
Next, the source code will be released.
Thanks.
========================
Leyder Dylan (dylan.leyder@slug-production.be.tf
http://www.slug-production.be.tf/
The source code will probably beeing release tomorrow (tuesday) in the afternoon.
I''ve only 2 things to fix :
- Clean and comment a maximum the source code.
- Use an ASCII file for the ARB String.
Next, the source code will be released.
Thanks.
========================
Leyder Dylan (dylan.leyder@slug-production.be.tf
http://www.slug-production.be.tf/
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement