• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
Saragan

Transparency Issue

6 posts in this topic

Right so i have a transparency issue that i hope someone could explain? i should see the texture through the red square.

transparencyissue_zps5f58ccb5.png?t=1404

 

I created a bounding box around my obj (yes that textured cube is an obj tongue.png) however i noticed a transparency issue, so i removed all sides of the box bar the top. the top is a solid red with an alpha of 0.2.

 

originally i rendered another transparent box behind the red one and i could see that fine, just not the textured obj, which leads me to believe it is a conbination of my shader and glblend thats the issue.

 

 

so here is my code for my frag shader, if it doesnt have a texture (coord -98) then just do colour, i dont currently have a world light set so it never goes into the first part for textures

if (pass_Texture[0] <= -98.0 && pass_Texture[1] <= -98.0)
    {
    	out_Color = pass_Color;

    } else {

    	if(WorldLight.isWorldSource)
    	{
    		out_Color = texture(myTexture, pass_Texture) * pass_Color * (AmbientColor + DiffuseColor);
    	} else {
   			out_Color = texture(myTexture, pass_Texture) * pass_Color;	
   		}
    }

my bounding box (in this case just the red square) as you can see ive tried a variety of options

//glDisable(GL_DEPTH_TEST);
//glEnable(GL_CULL_FACE);
glEnable(GL_BLEND);
//glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glBlendFunc(GL_SRC_ALPHA, GL_ONE);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, 0);
glUniformMatrix4fv(shader->modelMatrixLocation, 1, GL_FALSE, &transform[0][0]);
glBindVertexArray(Cube->VAOID); // Bind our Vertex Array Object

glDrawArrays(GL_TRIANGLES, 0, Cube->points.size()); // Draw our square


glBindVertexArray(0); // Unbind our Vertex Array Object
glDisable(GL_BLEND);
//glDisable(GL_CULL_FACE);
//glEnable(GL_DEPTH_TEST);

and finally my obj which again ive tried a variety of blend options and depthtest options, most of it is my own code but didnt want to cut incase it was something else entirely that i missed

glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
//glBlendFunc(GL_SRC_ALPHA, GL_ONE);
//glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
glUniformMatrix4fv(shader->modelMatrixLocation, 1, GL_FALSE, &ModelMatrix[0][0]);

glBindVertexArray(VAIO); // Bind our Vertex Array Object	

std::map<std::string, Group>::const_iterator itr;

for (itr = Groups.begin(); itr != Groups.end(); itr++)
{
    Group gp = itr->second;
    cMtl* mtl = &Materials[gp.Mtl];

    if (mtl->MainTexture.loaded && !mtl->MainTexture.GeneratedBuffer)
    {
        if (mtl->MainTexture.TextType == SARAGAN_PNG)
	{
	    mtl->MainTexture.GenerateAlphaBuffer();
	} else {
	    mtl->MainTexture.GenerateBuffer();
	}
    }

    if (mtl->MainTexture.loaded && mtl->MainTexture.GeneratedBuffer)
    {
	if (CurrentTextureID != mtl->MainTexture.TextureID)
	{
	    CurrentTextureID = mtl->MainTexture.TextureID;
	}
	glActiveTexture(GL_TEXTURE0);
	glBindTexture(GL_TEXTURE_2D, mtl->MainTexture.TextureID); 

	glDrawArrays(GL_TRIANGLES, gp.index, gp.Endindex); // Draw our square
    }
}
glBindVertexArray(0); // Unbind our Vertex Array Object
glDisable(GL_BLEND);

for the love of me i cant seem to get the right combination, which to me suggests i dont really understand whats really going on here

 

if anyone could shed some light onto the situation then i would be very greatful

 

Kind Regards
Rob

 

 

 

 

 

 

 

0

Share this post


Link to post
Share on other sites

You probably have depth writing enabled (glDepthMask), so when you draw the transparent quad first, it will write the depth for those transparent pixels. And now when you try to draw the other object behind it, it will skip the drawing the pixels because of depth testing (something is in front of the pixel). Simplest way to solve this is to render opaque objects first, then transparent objects from back to front. It still won't work for all kinds of shapes though.

 

Try changing the order you render, first the textured box and then the transparent thing.

1

Share this post


Link to post
Share on other sites

Thanks for the reply I changed the render order and indeed that did seem to fix the issue which is great.

 

You said it still wont work for all kinds of shapes though? how do you mean?

0

Share this post


Link to post
Share on other sites

The problem is basically that the triangles are not still sorted. For example, if you want one object which has two transparent boxes in it, how do you know which box of those will be drawn first? It will look weird depending on the viewing direction.

2

Share this post


Link to post
Share on other sites

Right ok, thanks for your input, as im doing basics i think ill just try and avoid that situation for now until i have a firmer grasp

 

out of interest would culling the faces be a solution to that? not sure how that would work with transparency

0

Share this post


Link to post
Share on other sites

Culling would not help much, it just hides some of the faces. I haven't done much this kind of stuff, but "order independent transparency" is something you could google for more information. Youtube also has some nice videos about how much better it looks like.

0

Share this post


Link to post
Share on other sites

Culling won't change the matter that with certain kind of a scene from certain point of view the transparency will fail. 

 

Generally, transparent surfaces should be drawn from back to front. Or more precisely, transparent pixels should be drawn from back to front. Now, for a typical rendering setup, it is already very difficult (at least in performance wise) to guarantee that the surfaces are in correct order ... and it is impossible to guarantee that the pixels are in correct order (without some scene preprocessing such as BSP ... which you don't want to implement these days) in the general triangle soup case.

 

Consider that transparent triangles intersecting other transparent triangles already pose a problem since you can't draw them in a correct order, and then, if different objects intersect, you'll have the same problem. 

 

There is a technique called OIT (order independent transparency) and there is a lot of research done in that field. The general solution is quite somewhat simple, but maybe not very efficient. In the simplest version, you'll gather all the transparent pixels in a per-pixel linked list, then perform sorting based on the distance. Other technique is called stochastic transparency which works differently than the linked list version, but it produces noisy results at low qualities. 

 

Cheers!

0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0