• Create Account

## Humus' code (Help with Geometry Shader)

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

2 replies to this topic

### #1french_hustler  Members

479
Like
0Likes
Like

Posted 10 August 2012 - 01:48 PM

Hello,
I am going over Hummus' deferred shading code. I'm a bit confused about the geometry shader during his deferred lighting pass.

So he basically calculates the lights' bounds in the geometry shader and passes constants ex, ey, and zw to do his calculations. I don't really understand the purpose of these values, more specifically the ratio he ends up sending over to the shader.

[source lang="cpp"]float ex = tanf(fov * 0.5f); float ey = ex * height / width; renderer->setShaderConstant1f("ex", 0.5f / ex); renderer->setShaderConstant1f("ey", 0.5f / ey); renderer->setShaderConstant2f("zw", projection.rows[2].zw());[/source]

Here is the box calculation function in the geometry shader:
[EDIT]: I have attached the shader file instead since for some reason a lot of the code was getting cut out using the code tags.

float ex = tanf(fov * 0.5f);
float ey = ex * height / width;

At this point ex is 1/2 the near plane's width and ey 1/2 the near plane's height right?

But why does he do:
Wouldn't that be 1/w and 1/h?

Also what does a, b, f represent exactly in this section:
// Compute extents in X
float Lxz = dot(lightPos.xz, lightPos.xz); // This gives me the quare of the magnitude
float iLxz = 1.0 / Lxz;
float a = radius * lightPos.x * iLxz;
float b = (radiusSqr - lightPos.z * lightPos.z) * iLxz;
float f = -b + a * a;

In the geometry shader, how does this work exactly?
zn = saturate(zw.x + zw.y / z0);
zf = saturate(zw.x + zw.y / z1);
zw.x and zw.y represent proj[2][2] and proj[2][3]. How do those elements of the matrix help figure out zn and zf? The 3rd row isn't part of the translation....

This is a proj mat in dx:
2*zn/w 0 0 0
0 2*zn/h 0 0
0 0 zf/(zf-zn) 1
0 0 zn*zf/(zn-zf) 0
So isn't proj[2][3] always 1?

And how does the whole ex, ey make sense?
float x0 = saturate(0.5 - N0 * ex);
float x1 = saturate(0.5 - N1 * ex);
&
float y0 = saturate(0.5 - N0 * ey);
float y1 = saturate(0.5 - N1 * ey);

Also, is there a reason for which he insists on using multiplications for his divisions? Is it more efficient to do x*0.5 than x/2.0?

#### Attached Files

Edited by french_hustler, 13 August 2012 - 11:32 AM.

### #2french_hustler  Members

479
Like
0Likes
Like

Posted 13 August 2012 - 10:35 AM

Bump...

Thank you.

### #3french_hustler  Members

479
Like
0Likes
Like

Posted 14 August 2012 - 01:49 PM

http://www.gamasutra.com/view/feature/131351/the_mechanics_of_robust_stencil_.php?page=6

Makes sense now.

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.