Culling faces

So I’m debating this right now. Should I let OpenGL let its magic choose what face to cull, or should I use the normal to calculate if a face should be drawn.

Vertex Shader:


	out bool shouldDraw;
	
	void main(void) {
		vec3 fdx = dFdx(pass_position);
		vec3 fdy = dFdy(pass_position);
		vec3 faceNormal = normalize(cross(fdx,fdy));
		shouldDraw = dot(pass_surfaceNormal, faceNormal) > 0.0 // backface
	}

and discard; any pixels with shouldDraw be to true

or


GL11.glEnable(GL11.GL_CULL_FACE);
GL11.glCulLFace(GL11.GL_BACK);

I find it awarding doing the first one because you can control cull settings in the shader when you have a transparent object. But there might be this large overhead due to me not knowing if OpenGL does some per-frame lengthy determination which might be true because of how it renders.

It is not “magic” what OpenGL is doing with backface culling. Read the OpenGL specification.
Also, your test would be per fragment with “support/helper” fragment shader invocations to compute the differentials (also read the OpenGL specification) and is very very very very much more expensive than the per-primitive test that OpenGL’s shader (non-programmable) does internally.

[quote]I find it awarding doing the first one because you can control cull settings in the shader when you have a transparent object.
[/quote]
Separate the drawcalls for solid objects from the ones that are transparent.

So: Definitely and absolutely by all means use OpenGL’s default backface culling method instead of rolling your own backface culling method!

Culling entire “objects” is of course an entire different topic (see “frustum culling” or “occlusion culling” for examples).

I wonder why nobody ever gets what I mean. They are so quick to attack.

No one is attacking you. And if you think people are, maybe you should look at the root of the problem instead of throwing blame on everyone else automatically.

You should definitely not implement backface culling in a shader. I don’t know how else you wanted readers to interpret your post.

The only time when backface culling should be done manually in a shader is when doing tessellation to avoid tessellating back faces.

EDIT: The same logic applies if you have an expensive geometry shader you can early out from, but if you have an expensive geometry shader you’re probably doing something else wrong anyway. Otherwise it’s rarely ever worth it.

What’d be the odds for everybody to attack an arbitrary new member… We luv new brainzz. :point:

You seem to have been a touch confrontational the last few days though, and deeply empathics beings that we are, it leaves its mark in our otherwise wonderful responses. It takes two to tango :slight_smile:

I think you are overplaying a lot of the members here. Through my learning process, I have no been supported once and told to just get things or just conform to standards. I’ve told one person I wouldn’t fight with them because they are arguing semantics over the actual topic. I’d myself give criticism and feedback to the games displayed in the case, saying good job, but the internet shows the spiteful people.

A good example is KaiHH. I asked him for help and he just called me annoying even though I’ve only talked to him once there. ‘Just get JMOL you don’t need to understand the backgrounds of what is happening.’ It annoys me.

Another reason why we need more devoted people to tutorials and such rather than picking from everyone’s crappy attempts. LWJGL is nice, but then again ‘Just get Vulkan you don’t need to understand the backgrounds of what is happening, well you want to start with OpenGL first.’

And me saying I don’t understand something is just an invitation for other people I am then claiming to attack the people.

You did a whole lot more than just asking for help. In the PM you sent me and before that.
I will not replay here what you called me in a PM you sent… seriously, man. Pull yourself together!
And when you want to replay what I wrote you, then do it verbatim, and not saying, I told you wouldn’t understand it.

Let’s say that, for the sake of argument, ‘culling faces’ is still an appropriate title for the discussion :slight_smile:

Your last reply exactly shows what I meant with your being confrontational. We hardly ever spoke, but you’re addressing me like we have this sour history together. JGO is one of the most welcoming Java dev communities you’ll find, but it simply might not match your style, it happens.

There are some experts in their fields here - ofcourse everybody is a stranger to you, we get that - these experts tend to speak with a certain flair… of authority, which seems to rub you the wrong way. What may rub us the wrong way is that you open a topic stating (almost demanding) we need more tutorials in the area you happen to need more information on, that we need more of an community effort on these topics, while you are ditching quite a few of these community efforts in the same breath. People put years of their lives into it, for the greater good, and you merely discard them as making you almost vomit, and again, in the same breath, mentioning you cannot get your own crafty solution to work. These are conflicting messages you are sending, and not very friendly at that.

We are not as lenient as we could be, but just like you, we’re not perfect. :emo:

Conforming to standards is nothing new and a great idea when you’re starting out. I think we all fight it starting out to some extent, but there really is no reason to manually implement backface culling (other than what theagentd said). If you want to, go for it. There’s a reason openGL does it based off rotation order of vertices though…it’s efficient.

As for being told to use JOML. The more people that use it the better for all of us and honestly converting my engine JOML is one of the best decisions I’ve made for it. Sure there are things I don’t like out of personal preference, but everything I need and will need :point: is there and I didn’t have to spend the time adding any new functionality (it really is a pain building your own math library after a while).

Adding onto what everyone has said, utilizing knowledge from others is a huge thing everyone should be comfortable with. People spend their entire lives researching and working in some of these fields, that is some incredibly valuable information they have. Saying screw it, I won’t use it does not mean you are “conforming”. It means you are leveraging the resources available to you in a smart fashion. At work I would love it if I could just use pre-made libraries/solutions for most of our systems because that means less code that I have to actively develop and maintain. I already have enough on my plate, why would I want to take it upon myself to re-invent the wheel when someone has already went out of their way to provide everyone with a good solution already?

Like thedanisaur said, there definitely seems to a trend of new developers wanting to re-invent everything. I went through it, and honestly I learned a lot but none of the information I learned really went to good use. I tried on multiple occasions to create a graphics library to base my games off of; it went terribly each time because it’s hard stuff to get right. The stuff I learned was cool, but I don’t use any of it now. I could have had a game made with LibGDX or some other graphics library if I had just decided to utilize what’s available to me. But being a newbie, I was very headstrong.

There just comes a point where you realize no one cares what you used to create the end result, so long as it’s functional and conforms to their wants/needs. The only person who will care what standards were used to produce the application is you, and why would you want more work for the same profit? Maintaining efficiency while still outputting high quality work is key, and paramount, in any work you’ll do in life. It’s a good idea to start hammering that into your head so you understand when to take a step back and re-think your solution.

My 2 cents on standards:

Something I try to keep in mind is to minimize how customized and “personal” my code formatting and my IDE is. There are people who when they started programming they immediately started to customize their IDE to make the code formatting look how they personally prefer, moved around menus, etc. By the time they’ve become decent programmers, their formatting has so many quirks and their IDE is such a Frankenstein that other (even very good programmers) have trouble understanding their code at first. Setting up the project environment in the IDE is a nightmare due to all the finicky settings they changed. Moving to a new computer or updating their IDE breaks everything and not even the person him/herself can remember all the settings they changed. This can be a huge problem when you try to read other people’s code as you’re not used to their formatting/style. Working with others become difficult due to the clashing styles, so debugging is more difficult. Hell, any kind of communication with other people involving code becomes more difficult because you’re essentially coding in this homemade dialect. This is especially important if you have intentions to work with programming. At work your personal preferences don’t matter. It’s much more important to adhere to the style of the existing code, no matter how weird it is to you, for the sake of maintainability and coherence. Also, the less quirks you have the easier it is to switch workstations.

The same goes to some extent for JOML. JOML was born and designed to solve the problems of previous math libraries, and it did so splendidly. Compared to LibGDX/LWJGL/others, it has: no garbage, no native dependencies, tiny library, better performance, double precision versions of classes and more features in general. There really isn’t much you can improve in it anymore, but if there is KaiHH is very accommodating and helpful with answering requests and spitballing ideas. You’re welcome to write your own math library for the learning experience; I was pretty much doing that myself before JOML came around. Saying that “JOML solves your problems already” may not be immediately helpful, but the JOML source is right there and available to anyone. I’m not sure what exactly you were asking about, so this may not be a spot-on response to what you were annoyed about. The tie-in here with standards is that the more people that use JOML the more mature the project will get as any remaining bugs will be fixed and quirks evened out. The “standard” here is beneficial to pretty much everyone, as it also lets us help each other more easily. It’s true that it means that a lot of people can use these classes without knowing the gory details of linear algebra and perspective projection math though, but if learning that is your main goal then maybe a Java game development forum is no the best place to ask in the first place.

To expand on my response to the topic at hand, face culling: Your technique may be more flexible, but also affects performance negatively. Face culling is generally implemented in hardware and only depends on the winding of the vertices after projection. A backface polygon therefore only has to go through the vertex shader (and geometry shader if you have one), and is then immediately discarded. Pretty much all hardware can enable face culling without any overhead whatsoever since it’s handled in fixed-functionality hardware that would simply be disabled if the feature is disabled. In contrast, your discard-based solution makes all triangles go through the rasterizer and finally runs a fragment shader for each of the pixels. In addition, fragment shaders that call discard() interferes with other hardware-based optimizations, semi-disabling early depth/stencil testing and hierarchical depth buffers used most discrete graphics cards.

Well i just have to post now.

We get soo many new people every week that wants to make the next minecraft only bigger and better… But by the way i don’t know any math and don’t want to learn any, I have never done any real code and well i wanted this finished last week before the end of the holidays. Why are you telling me i not do a great job? Ok so it seems to have slowed down these days thank god.

We get sick of it well you may get the shorter end of that deal. Having said that they are not attacking. Don’t assume you almost got it right. Trust me, old ra4king went through a much harder roasting… I think he even got banned from the irc and one point. But he came around and started to follow instructions and advice. And now he helps others.

As for face culling, you really never need to do that. These days i find it hard to be vertex limited, so let the shaders do it. If all 3 vertex give a negative normal, fragments are not even produced. Making it real fast.

[quote]I find it awarding doing the first one because you can control cull settings in the shader when you have a transparent object. But there might be this large overhead due to me not knowing if OpenGL does some per-frame lengthy determination which might be true because of how it renders.
[/quote]
I think you will feel much more rewarding writing a software renderer, where you have control of every piece of code in your rendering pipline.

I think you will feel much more rewarding writing a software renderer, where you have control of every piece of code in your rendering pipline.
[/quote]
This^ is one of the main reasons why I haven’t started openGL yet. I like the control I have over the graphics in software rendering.

Look, I know how opengl determines which face is facing where and has good ability to prevent that face from rendering, but this was just a very tired hmm kind of thing.

What in the hell are you talking about?

Hydroque went through this, he came to the #java-gaming channel, was just about as aggressive and confrontational as I’m seeing him here on this forum, blamed us for being alienating, then left and never came back.

Indeed, I was like “Ra can be unfriendly? o_O”…

guys this thread is scaring me