What a couple of *minor* patches can do :)

Post those lines of code you feel like sharing or find what you require for your project here; or simply use them as tutorials.
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

I'm currently very short on time, so I just read through this patch really quickly - but I did not get the sense of all changes. Could you please explain some parts in detail?
The affector matrix is for temporary view changes, right? Shouldn't be too much of a problem to add it.
The clipping planes are used for what? You are enabling the clip planes each cycle, this seems to be quite expensive?
And finally the culling mode. Why would one want to switch the culling of all faces at once? There are many things that don't work for incorrectly oriented faces, so this would not help to overcome wrong mesh orientations. What is wrong with the material attribute?
mandrav
Posts: 117
Joined: Sat Aug 27, 2005 8:29 pm
Contact:

Post by mandrav »

hybrid wrote:I'm currently very short on time, so I just read through this patch really quickly - but I did not get the sense of all changes. Could you please explain some parts in detail?
Errm, ok. These patches gives the programmer flexibility to do things that are not possible to do otherwise in Irrlicht. Let's visit them one by one:
hybrid wrote: The affector matrix is for temporary view changes, right? Shouldn't be too much of a problem to add it.
Temporary or not, it is up to the programmer. Basically the camera has a new member called ViewMatrixAffector (which defaults to identity). Each time the camera's view matrix is recalculated, it is then post-multiplied with this affector matrix. This allows the programmer to actually control the view in any way imaginable.
In the effect presented in this topic, this affector is used to flip the screen upside-down by using an affector matrix equivalent to what a call to glScalef(0, -1, 0) would do.

hybrid wrote: The clipping planes are used for what? You are enabling the clip planes each cycle, this seems to be quite expensive?

Clipping planes, err, clip the view that is in the back of each of these planes. They are not updated each frame. You could see that if you 'd take a look at the code. They are enabled/disabled only when the programmer enables/disables them.
In the presented effect, they 're used to render only parts of the scene, which are then used as the reflection and refraction on the water.

hybrid wrote: And finally the culling mode. Why would one want to switch the culling of all faces at once? There are many things that don't work for incorrectly oriented faces, so this would not help to overcome wrong mesh orientations. What is wrong with the material attribute?
What's wrong with the material attribute?!? :shock:
a) the material attribute works only for one material
b) the material attribute does not do the same thing. It decides if backface culling should be enabled or not. This patch instead allows you to set which faces you want culled: the front-facing or the back-facing ones. It's clearly not the same thing...
There are many cases this is needed, especially for special effects like the one in this topic...
omaremad
Competition winner
Posts: 1027
Joined: Fri Jul 15, 2005 11:30 pm
Location: Cairo,Egypt

Post by omaremad »

Nice work madrav

@hybrid clipping planes are used since underwater polygons viewed from below shouldnt appear on the reflection.

For a pic of the bug look at this thread:
http://irrlicht.sourceforge.net/phpBB2/ ... hp?t=16079

Edit: he removed the picture of the bug. Anyway the clamping shader should be done on a per vertex basis(remove the comparision from the pixel shader put it in he pixel sahder and pass the transparency float to the ps), i just used the per pixel method when i wrote that thread because i thought it may still show artifacts.
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

In many cases I know what the technique would do, but it depends on the typical usage of the technique where in the Irrlicht architecture it should be added. That's why I asked - I know what clipping is :wink:
I asked for temporary effect of affector because you could change the view matrix otherwise - which might require more cpu/gfx power, though. We should also consider a boolean flag "isIdentityMatrix" inside matrix4 to reduce the number of multiplications applied (or avoid uploading of matrices such as the texture matrix).
I had a (quick) look at the code and I thought that it would call the enable each cycle. If this is not the case it is perfect :D
Where in the underwater effect do you use "cull front face but not back face"? And what is the effect of setting "global cull front face, material cull back face" or "global cull back face, material don't cull back face"? This addition is really not clear to me. But I've never programmed any fancy effects, yet, so I'm just wondering here.
BTW: I've moved the thread because it's some major code addition :)
mandrav
Posts: 117
Joined: Sat Aug 27, 2005 8:29 pm
Contact:

Post by mandrav »

hybrid wrote: Where in the underwater effect do you use "cull front face but not back face"? And what is the effect of setting "global cull front face, material cull back face" or "global cull back face, material don't cull back face"? This addition is really not clear to me. But I've never programmed any fancy effects, yet, so I'm just wondering here.
This is used to render the environment's reflection. To do this, you need to alter the view matrix (see affector) so that it renders the scene upside down. But by altering the view matrix like that (like glScalef(1,-1,1)), you have actually reversed the front and back faces (the -1 scale is responsible for that). So you have to change the culling mode in opengl so it culls the correct faces again.

The material's setting still affects each mesh. This patch just allows you to alter the definition of what is considered a front-face and what a back-face. That's all.
Last edited by mandrav on Sat Oct 28, 2006 6:49 pm, edited 1 time in total.
Klasker
Posts: 230
Joined: Thu May 20, 2004 8:53 am
Contact:

Post by Klasker »

When you say glScalef(0,-1,0) you really mean glScalef(1,-1,1) right? Or did I miss something completely?
mandrav
Posts: 117
Joined: Sat Aug 27, 2005 8:29 pm
Contact:

Post by mandrav »

Klasker wrote:When you say glScalef(0,-1,0) you really mean glScalef(1,-1,1) right? Or did I miss something completely?
lol, yes, you 're right :).
I wanted to emphasize the -1 and didn't notice what I wrote :lol:.
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

Ok, now I understand the third addition. I'd rename it, though, as it does not define the culling mode but the front facing orientation or something like that. Any suggestions?
mandrav
Posts: 117
Joined: Sat Aug 27, 2005 8:29 pm
Contact:

Post by mandrav »

hybrid wrote:Ok, now I understand the third addition. I'd rename it, though, as it does not define the culling mode but the front facing orientation or something like that. Any suggestions?
In opengl it's called glCullFace().

setCulledFaces() ?
Saturn
Posts: 418
Joined: Mon Sep 25, 2006 5:58 pm

Post by Saturn »

I'd stay with CullMode, but change ECM_BACK_FACES / ECM_FRONT_FACES to ECM_CLOCKWISE / ECM_COUNTER_CLOCKWISE. Because this is what it is about. In the sample, not the front faces are to be culled, but the back faces, which just happen to have their orientation flipped.

This would also fit well with DirectX/OpenGL, which have the options D3DCULL_CCW, D3DCULL_CW, GL_CCW, GL_CW. And the affected RenderState in DirectX is D3DRS_CULLMODE.
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

Ok, another one for the clipping planes: They *are* updated each render call of the camera, causing unnecessary OpenGL/DirectX calls. Why not simply enabling them when being set?
Post Reply