It’s legit, up to +64 IIRC
I tested the code…The mistake I made was not the buffer thing. But I gave the glGetUniformLocate the handler as parameter instead of the program. The result of this function is now, that the int variable is now set to 0. I think that is a good thing. But… I still got a black screen whenever I try to call the glUseProgramObjectARB function. Strange… Does the uniform variable be set BEFORE or AFTER this function? By the way… what is a IIRC, is it “If I Recall Correctly”?
I made a quick and dirty (comments are all incorrect I think) java/glsl version of nehe lesson 47 to learn the basics of GLSL usage. It uses a trivial vertex shader with an attribute variable, but it gives a working example of using a GLSL shader. Might help…
[quote=“bahamut,post:42,topic:24846”]
I was under the impression that jogl handles the String conversion for you. At least it worked by just passing a String on my mac.
[quote=“bahamut,post:42,topic:24846”]
Seems correct
[quote=“bahamut,post:42,topic:24846”]
Maybe there’s an error in your shader(s) I got a black screen as well when I forgot to set the vertex color in my vertex shader. When you enable a vertex/fragment shader it disables just about all built in vertex/fragment processing, so you might be forgetting something. (See the glUseProgramObjectARB reference page for details)
You have to enable your program before you can set variables in it, so first call glUseProgram, then glUniform.
[quote=“bahamut,post:42,topic:24846”]
Yep, IIRC == If I recall correctly
[quote]I was under the impression that jogl handles the String conversion for you. At least it worked by just passing a String on my mac.
[/quote]
Under Java on windows. This method requires a byte[] or a ByteBuffer. Appearantly my byte[] was not correct. Don’t ask me how, cuz… “string”.getBytes() seems to return a byte[]. But instead of that, I used the ByteBuffer method and works fine now.
I designed an another test program to test the shaders. I made a texture which contains a black and white image. Sets the right params… blablabla…etc… Everything works perfect. I can also set the Uniform variable before I called the useProgramARB ( after linking ) and change it with a small gui. The thing is that I also have defined the uniform sampler2D grayscaleTexture. But I never setted that variable. I think whenever you use a single texture, the shader will automatically attach the texture to the uniform variable.
In my real application I use more textures. Whenever I use multitexture shading program ( in my case I use 6 textures), the screen turns black. I really don’t know what it means. The only thing I know, that the vertex/fragment don’t have any compile problems. Also no linking problems.
Maybe I did something stupid again, maybe this:
uniform sampler2D grayscaleTexture
.......
The type of a textureID is an “int”. The pointer of the grayscaleTexture will be set with a int. sampler2D == int???
[quote]Yep, IIRC == If I recall correctly
[/quote]
By the way… IIRC = Isn’t It Really Cool ;D ;D ;D ( also funny )
Ok, guys… You can kill me for free for my stupid mistakes. Appearently my screen turns black because of one stupid mistake I made in the past. I didn’t put a Grayscaled picture in RGB texture, in fact I put it in a Luminance texture. For fun, I did a System.out.println (image.getColorFormat()), which returns a number (6309) and identical to GL.GL_LUMINANCE. The GLSL script works only for my test application, which has a RGB texture. So, the only thing for me to do is put a grayscale picture in the RGB texture and that is it. My question is, do I have to convert the Grayscale to RGB first???
GLSL supports LUMINANCE textures… it will return a vec4 containing (L, L, L, 1)
it shuold work, but without any code, we can just guess what you’re doing wrong.
[quote=“pepijnve,post:43,topic:24846”]
Actually in the 1.1.1 release of JOGL there were some entry points missing the String to char* conversion including this one. These should all be fixed in the JSR-231 branch of the JOGL tree. We should be able to release the first build of this new source base within a week. In the meantime you can look at the new code with
cvs -d :pserver:guest@cvs.dev.java.net:/cvs co -r JSR-231 -P jogl jogl-demos
Note that the APIs differ in several ways from the 1.1.1 release but are definitely the direction the JOGL project is going.
I will post the new code tomorrow. I was thinking… if the format of the texture parameter is set to GL.GL_LUMINANCE. Can GLSL still change this to RGB? I mean… the GLSL sets the grayscale to a color, but the actual texture is 8bit. So, by turning this in to color the 8bit becomes 32bit automatically? Or shouldn’t I really worry about this matter?
( I think this is the most stupid question I ever asked, cuz I had some alcohol ).
Ok, here below the GLSL code…still the same as allways… but I converted this code not from HSV to RGB, but from HSL to RGB. And I guarantee that it works very fine.
uniform sampler2D grayscaleTexture;
uniform float Hi, Si, Li;
uniform float Hg, Sg, Lg;
vec3 fastHslToRgb (float h, float s, float l )
{
..................
..................
}
void main()
{
vec4 grayscale = texture2D(grayscaleTexture, gl_TexCoord[0].st);
float G = grayscale.r;
float H = G * (Hg / 360.0 ) + Hi;
float S = G * (Sg / 360.0 ) + Si;
float L = G * (Lg / 360.0 ) + Li;
vec3 RGB = fastHslToRgb ( H, S, L );
gl_FragColor = vec4(RGB, 0.0);
}
I actually think the bottleneck lies at the moment when I ask the grayscale for the red color. Does the luminance texture contains red color?
I mean if I use gl.glGetTexLevelParameteriv( GL.GL_TEXTURE_2D, 0, GL.GL_TEXTURE_LUMINANCE_SIZE, lum), it returns 8 and gl.glGetTexLevelParameteriv( GL.GL_TEXTURE_2D, 0, GL.GL_TEXTURE_LUMINANCE_SIZE, red), it returns 0.
Does GLSL still return a red value from a Luminance-Texture when I use this for float G = grayscale.r. If true, why do I still have a black screen. Else if this is not true, what should I do to get the value of the luminance? The thing I know is whenever I set the gl_FragColor to grayscale (which is a vec4), then everything is black and white again… so ( that is ok), I am really sure that the error lies in my GLSL script.
Yes texture2D should return a vec4 filled with the luminance value from your GL_LUMINANCE texture.
Shader programs cannot be stepped into for debugging, nor can they emit text messages. The only way to debug a shader program is to let it communicate with you via its only output, the pixel color. To debug this program, just start outputting interesting data directly to the screen to find out what part of your program is failing, and why.
Mmm… I have done some research about GLSL. It seems there is nothing wrong with my code. Okok… lets just start over again:
When I start the program… the whole screen turns black. Actually if I change this code so, that the gl_FragColor = vec4 (1.0, 0.0, 0.0, 1.0), then the whole screen will turn red. That is the correct result for this test. If I set the gl_FragColor = grayscale, then the whole screen turns black… After some of these tests, I made a conclusion that I did not correctly set the uniform variable.
public void init ( GLDrawable glDraw )
{
glslLoader = new GLSLLoader ( glDraw );
glslLoader.setShaders ( "shading.frag", "f" );
..........
}
public void updatePicture( GLDrawable glDraw, GLSection section )
{
int textureID = GLContextBase.getTextureID ( section.getTextureName () ); // textureID = 5
.............
............. //refreshes the texture and updates this with a new image from the server.
.............
int IRHandle = glslLoader.getProgramHandle ();
int IRLocation = gl.glGetUniformLocationARB ( handle, stringToByteBuffer ( "grayscale" ) );
System.out.println ( IRLocation ); //prints a 0, that is good, because it found the uniform variable
gl.glUniform1iARB( IRLocation , textureID);
}
With this code, I got a black screen. There are in total 2 layers. Each layer contains 3 textures. The lower layer is a normal video image and the upper layer is a IR. There is an ability to make the upperlayer from 0% to 100% transparant, which means I can let it fade. The upperlayer is also the layer which gain falsecoloring. GLSection is a some kind a wrapper for the texture which also contains a container for all textures. Each texture got different parameter, such as: upper or lower layer, ID, etc… When redrawing each texture will become redrawed with different image (because it’s a movie), so the parameter will become set again, etc… After this I do the uniform things, and then I got a black screen By the way, after all the textures are set… the redraw will be called, so all the textures will become drawed at once.
Can someone review this and tell me what I do wrong? Every suggestion may get me closer to my destination.
Seems like your test environment is far too complex. The rule is if you have a bug that haunts you, narrow it down. Remove as much as code as possible, allowing you to fucos on what goes wrong.
For example drop the whole color-converting thing. Render your LUMINANCE texture with a fragment-shader like:
void main()
{
vec4 grayscale = texture2D(grayscaleTexture, gl_TexCoord[0].st);
gl_FragColor = vec4(greyscale.rgb, 1.0);
}
And if you want help that’s actually helpful, make a self-contained and compilable source-code example, so we can run it on our own systems.
You are hiding code from us all the time by thinking “that’s not important, that other code is correct”, but… how can you be so sure? Often your bugs are where you least expect. So give us code that we can compile and run right away, so we can actually help you, instead of guessing.
Perhaps that is not possible, because… you are missing the serverside. The serverside is far more complex than this one, but I got my own reasons in this case. Without the serverside, this client side is useless and it will not able to be tested. Anyway… I will use your advice and try to fix this bug my self. Thanks for all your helps.
Okok, I changed this message… anyway…
The layer of my InfraRed had a blending option. With a JSlider of Java, I could change the transparancy of this layer. But now I use GLSL for false coloring, the blending option lost his functionality. That is because the transparancy of the texturelayer is statically changed. Is there any way to make this dynamically? I mean the gl_fragColor = vec4 ( rgb, 1.0 ), but is there a way to make the alpha dynamically?
In fact I tried to reload the script for each time I use the blending option. The uniform of the script changes each time I use the JSlider. My opinion is, that this solution is a little bit nasty. So…
Just make a uniform for the alpha and set it whenever it changes?
Based on Rivens example:
uniform float alpha;
void main()
{
vec4 grayscale = texture2D(grayscaleTexture, gl_TexCoord[0].st);
gl_FragColor = vec4(greyscale.rgb, alpha);
}
Ok, everything is now done. The IR camera has false coloring and also the blending option. Thanks guys.
My new project is to make the IR camera so, that the night-vision camera turns the night into day. By storing a picture from a day of the same location or the same landscape as the night, there is an ability to turn the IR picture into day. By using an advanced mathematical calculation, there is an ability to stretch the histogram of both pictures so that the curve are equal. After this, you simply match the closest colors, and you have the nightvision turned into daylight. I think that the fake colors has an psychedelical and distracting effect. The colors aren’t real and it could gives your brain the wrong idea of interpretation.
Greedz,
Bahamut
That sounds awesome. I’d like to see some screenshots of that algorithm in action!
Hey there,
I need a formula to calculate the demean of a texture.
The formula of the demean goes as follow:
For instance, the texture = 256 * 256
select the first row of a texture, devide it with the width of texture ( which is 256 in this case ). After you have the mean, you simply return the gl_color = texture2D ( texture, gl_TexCoord[0].st) - mean
I don’t exactly know how you have to calculate the mean color of a row. Suggestion is needed.