Creating grass... transparent textures and texture position?

Started by
26 comments, last by Thaumaturge 15 years, 11 months ago
I'll check it with Gimp :) but I'm not sure why there would be any whiteness, since I made that PNG in Gimp... I started with a totally transparent one and only added the text...

And yes, I'm rendering my grass after everything else in each of these 3 passes... the first pass renders the scene from the light's point of view and saves it to the GL_TEXTURE_2D, the second one renders a dark scene, and the third one renders the parts of the scene which aren't shadowed, so that they are brighter than the shadows... I think it's doing it by somehow projecting that texture saved after the first pass on the scene from the light's point of view. Maybe something's wrong when I also use GL_TEXTURE_2D for the grass texture and then don't change it back... I don't know how to do it, though...
Advertisement
Well, I use SDL to load my .png images and it works. Maybe add this if you haven't already?

glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_BLEND);

and make sure you use GL_RGBA since there are 4 alpha channels.
gluBuild2DMipmaps(GL_TEXTURE_2D, 4, image->width, image->height, GL_RGBA, GL_UNSIGNED_BYTE, image->pixels);
this is also happening to me!

when i enable BLEND:

glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

the window gets black :(

this is my results:

Blitting using SDL:
http://img375.imageshack.us/img375/7909/sdlfw2.png

Using OpenGL:
http://img48.imageshack.us/img48/3606/opengltd4.png
[]
Starshine_, I've taken a look at some of the description given in the tutorial that you linked to, and I think that I have a possible source of your grass not being shadowed.

According to the tutorial, part of the process is having OpenGL cull front faces, and record the depth results for the back faces. Since drawing the grass involves disabling depth testing, the depth of whatever was drawn behind the grass is used, leading to grass generally being lit. Similarly, when the depth of the point in question is tested to see whether it should be shadowed, it should produce the depth value for whatever was rendered behind the grass, which may well be unshadowed.

You might be able to get around this by rendering the grass into the stencil buffer, and then re-rendering with depth writing and testing on. There might also be a way to write to the depth buffer conditionally, having it write only when the alpha value is 1.0, although if there is, then I'm not sure of what that may be, offhand, I'm afraid. :/

However, I may well be wrong in some or all of this, and I'm not sure that my suggestion above is the best solution. I may well take another look once I've had some sleep, however. ^^;

artefon, may I please see your texture setup code for that texture map?

MWAHAHAHAHAHAHA!!!

My Twitter Account: @EbornIan

Thanks for telling me! I'll try do it later. :) Right now the grass shadow isn't my main concern yet... and at the moment I'm not even going to touch stencil buffers unless they are absolutely necessary, because I have no idea what they are, and I need to have the grass (even if it's without shadow yet) finished for Monday. O_o

Right now my main problem is still correctly displaying grass, because two things aren't working yet when I disable depth testing and render things that are farther away first. When I put an unshadowed grass cell behind a shadowed object, then the grass cell is still visible, because the third pass renders unshadowed elements (such as the grass) without rendering shadowed ones, so that even if there's a shadowed object in front of the grass, it doesn't cover it. I've read somewhere that it's possible to combine the second and third passes of shadow mapping together, maybe that would help somehow? I have no idea how to do it, though... and I don't know if it's easy or hard. I'm still an OpenGL newbie...

Another problem is that I don't know how to save the current GL_TEXTURE_2D so that when I temporarily change it, for example when rendering grass, I can change it back after that. When I looked in OpenGL documentation, I discovered glGet functions... but doing this:

GLuint currentTexture;
glGetIntegerv(GL_TEXTURE_2D_BINDING, currentTexture);

gives me the error:
'GL_TEXTURE_2D_BINDING' was not declared in this scope

as if there was no such thing as GL_TEXTURE_2D_BINDING :(

edit: I changed GL_TEXTURE_2D_BINDING to simply GL_TEXTURE_2D and it's working correctly :) Which is really strange, because it's against official OpenGL documentation which I found here: http://www.opengl.org/documentation/specs/man_pages/hardcopy/GL/html/gl/get.html

I still have the first problem, though :(
Hmm... According to this documentation page (from the documentation that I tend to use), it appears that you should be using GL_TEXTURE_BINDING_2D - note that "2D" comes after "BINDING" in this version. According to that same page, GL_TEXTURE_2D should return to you a boolean value, indicating whether 2D texture mapping is enabled or not. It occurs to me that if your texture binding happens to be 1, then using GL_TEXTURE_2D might appear to work, but for the wrong reason...

As to your visibility problem, surely you're writing to the depth buffer on your first, shadowed pass from the camera's perspective?

It occurs to me that surely you should be disabling depth masking (via glDepthMask(true/false)), rather than depth testing, for transparent objects? After all, semi-transparent objects should be tested against existing depth values (so that they're clipped properly), but not themselves write new depth values, so that transparent sections don't obscure objects behind them.

I'm sorry for not mentioning this earlier - I think that it did occur to me, but that I put it aside, perhaps because your code appeared to be working.

Perhaps, if you don't have depth masking disabled for the grass, try doing so. Presuming that depth masking is on otherwise (as I imagine that it is), you should have something roughly along these lines:
//In your rendering code//Perform everything intended to happen before grass is rendered//If depth testing is off, enable it here//Disable depth testing, so that the grass won't write to the depth bufferglDepthMask(false);//Render your grass, in order from furthest to nearest.//Re-enable depth testing, so that other things will perform depth writesglDepthMask(true);


If that doesn't work, then perhaps you should look into fitting a write into the depth buffer from the camera's perspective into your passes somewhere, preferably, I would think, as part of one of the existing passes (perhaps the "shadowed" pass).

As to combining the second and third passes, I don't know, I'm afraid. :/

Have you done any research on combining them, yet?

MWAHAHAHAHAHAHA!!!

My Twitter Account: @EbornIan

Thank you, that worked... it's generally displaying correctly now :D so I don't need to combine the two passes, hopefully. :)

It's strange that OpenGL has two different documentations which say different things. The one I found was the first result in Google... but maybe it's old?

There's still that little problem with the grass not being totally transparent... it's a small problem, but here's a screenshot...maybe you'll have an idea about what's causing it. Here it is: http://i11.photobucket.com/albums/a156/Miracle86/weirdtransparency.png I checked that texture in GIMP, and it's supposed to be totally transparent everywhere except for the text...

I also have another question, kind of unrelated to the topic, but you know a lot about OpenGL so maybe you'll know how to help. :) What's the easiest way to render the shadow map (the first pass) to a framebuffer and then to the texture, so that it's not rendered on the screen? I've tried using QGLFramebufferObject, but it's giving me strange errors. So I can try to do it using normal OpenGL functions for framebuffers, without using QT ones... but, to be honest, I don't really know how...
I would guess that the documentation that you found is indeed old.

As to your problem, that does look odd - it's not what I had imagined, I don't believe. Does it change at all as the point of view changes? If you change the colour of the backdrop plane, or the clear colour, does the colour of those lines change? I find it interesting that it only seems to show up against the cube, despite the floor plane having different shades of grey, thanks to the shadow.

As to rendering to a frame buffer, I'm afraid that I don't think that I've done that before, myself. Some searching (primarily of this site) turned up this article and these two threads; I haven't read much of them myself, and the article is a few years old, but might provide some help. It may be that there is a more recent method for creating framebuffers, or a more recent structure for that. I'm sorry that I'm not of more help on this. :/

Anyway, I don't think that I know that much about OpenGL #^_^# - what I know comes from experience with and use of it, having encountered discussion of such things elsewhere (particularly on this forum, I believe) and - notably - having found some good places in which to look when I want more information. ;)

MWAHAHAHAHAHAHA!!!

My Twitter Account: @EbornIan

I've tried doing some stuff and I found out three things... first, the color of the grass element around the word "MEEP" depends on the color which I set using glColor4f before rendering the grass quads. For example, when I set the color of the quads to green, here's what I got:

http://i11.photobucket.com/albums/a156/Miracle86/weirdtransparency2.png

as you can see, I also changed the color of the floor, but that doesn't affect the grass...

The second thing is that the color around MEEP only appears when it's rendered in front of shadowed areas... here's a screenshot which shows it better:

http://i11.photobucket.com/albums/a156/Miracle86/weirdtransparency3.png

The green thing doesn't show when it's rendered in front of unshadowed parts of the floor and an unshadowed face of the cube...

And the third thing I've noticed is that the intensity of the color around MEEP depends on the intensity of ambient light and shadowed light (the light used in the second pass which determines the light intensity of shadowed areas). With both the ambient light and shadowed light intensity set to zero, so that shadows are almost black, the color around MEEP is almost totally transparent. By the way, isn't it strange that with both ambient light set to zero and shadowed light set to zero, shadowed areas aren't totally black? Hmm... anyway, here's a screenshot :)

http://i11.photobucket.com/albums/a156/Miracle86/weirdtransparency4.png

And thanks for the link to the frambuffer tutorial, it seems that it's going to be really useful to me ^_^
Hmm... Well, from this I'm guessing that the erroneous sections are being drawn during the shadowed pass, with lit sections of geometry overdrawing them during the lit pass.

Since the erroneous results react to glColor and the current light source, and they can take a colour other than that of the floor plane, they would seem to be something drawn on the grass planes. This seems to me to suggest either an incorrect texture, or, given the sort of thing that you're doing, incorrect texture coordinates (or both, of course ;P).

So, are you drawing the grass at all during the shadowed stage? If so, are you sure that the grass texture is valid at that point, and that if it is, that it is the selected texture at that point, and that the texture coordinates are being properly set in that pass?

For that matter, if you comment out the entire lit pass (including any drawing of the grass in that stage), what do you get?

Quote:Originally posted by Starshine_
And thanks for the link to the frambuffer tutorial, it seems that it's going to be really useful to me ^_^


I'm glad to hear it, and it's my pleasure. ^_^

MWAHAHAHAHAHAHA!!!

My Twitter Account: @EbornIan

This topic is closed to new replies.

Advertisement