GI Baby Steps

Discuss the Wing Commander Series and find the latest information on the Wing Commander Universe privateer mod as well as the standalone mod Wasteland Incident project.
klauss
Elite
Elite
Posts: 7243
Joined: Mon Apr 18, 2005 2:40 pm
Location: LS87, Buenos Aires, República Argentina

GI Baby Steps

Post by klauss »

I just made my first steps on the GI field.
And that's not military talk.

I implemented basic static environment sampling with the filtering in the pixel shader (eventually, that will be "somewhat" (1) moved to a precomputation stage at every environment update - so not even once per frame).

No ambient occlusion of any kind... yet.
Mosty because I couldnt nor didn't have time to get a baking, bust also because there are some details (about baking) that I haven't resolved yet (like, for instance, I think I'll need more than one coordinate set to transport the info, which I'd like to avoid).

(1) - Some will still remain on the pixel shader to allow dynamic ambient occlusion.


Ok... why talk...

Indirect diffuse (Ambient)
Indirect diffuse + Direct diffuse
Indirect diffuse + Direct diffuse + Indirect specular + Direct specular
Oíd mortales, el grito sagrado...
Call me "Menes, lord of Cats"
Wing Commander Universe
chuck_starchaser
Elite
Elite
Posts: 8014
Joined: Fri Sep 05, 2003 4:03 am
Location: Montreal
Contact:

Post by chuck_starchaser »

Looks good, so by "ambient specular" you mean like environment mapping?
How did you filter in the shader?; I thought it couldn't be done. Manual multi-sampling and averaging?
You intend to compute specular dynamic occlusion with environment mapping somehow?
My original idea for static specular occlusion was to square the radiosity baking (darken it) and premultiply the the spec map with it. Gross, I know, but it would have been a way of "playing safe", kind of.
Just upload it if you need a baking; I can do one in 5 minutes; I got that figured out I think. Not sure what you mean by more than one coord set, tho.
If you have a bumpmap for the bricks, I could try and compute a radiosity baking of it in Gimp and combine it with Blender's baking. I guess I'll need to compute 2nd derivative (concavity), or something faking it...
(Actually, best thing would be to use height field to generate subdivision geometry, heard there's a script for that, then do the baking...)
klauss
Elite
Elite
Posts: 7243
Joined: Mon Apr 18, 2005 2:40 pm
Location: LS87, Buenos Aires, República Argentina

Post by klauss »

chuck_starchaser wrote:Looks good, so by "ambient specular" you mean like environment mapping?
Wel... yes... but I find "direct/indirect specular" a much more accurate term, because it so happens that everything in those pictures is some form of environment mapping.
chuck_starchaser wrote:How did you filter in the shader?; I thought it couldn't be done. Manual multi-sampling and averaging?
Yep.
In fact, I just saw the difference between the 6600 and the 9800: In the 6600, I could do this (in the pixel shader):

Code: Select all

const float ds=1.0/8.0;
const float d_mypos=8.0;
const int nsc=8;
for (int s=-nsc; s<=nsc; ++s)
   for (int t=-nsc; t<=nsc; ++t)
      dlighting += exrpand_rgbs(textureCube(EnvironmentMap,
         bump+ds(s*tgw+t*tgw)), d_mypos);
dlighting *= 0.5/float((2*nsc+1)*(2*nsc+1));
(and it would run - not too fast, but run nonetheless).
chuck_starchaser wrote:You intend to compute specular dynamic occlusion with environment mapping somehow?
Yep.
chuck_starchaser wrote:Just upload it if you need a baking; I can do one in 5 minutes; I got that figured out I think. Not sure what you mean by more than one coord set, tho.
Well... if you'd take the time to do it, I'd rather have you use something more interesting than a stone teapot ;) (though a stone teapot sounds interesting).
Have anything, with bumps and all?
chuck_starchaser wrote:If you have a bumpmap for the bricks, I could try and compute a radiosity baking of it in Gimp and combine it with Blender's baking. I guess I'll need to compute 2nd derivative (concavity), or something faking it...
(Actually, best thing would be to use height field to generate subdivision geometry, heard there's a script for that, then do the baking...)
Ya... subdivision geo + bake is really nice, but if you're doing the baking to a texture. If you do it to vertex attributes (color), like we talked, subdivision won't help.
We could have both techniques implemented - no sweat.
Oíd mortales, el grito sagrado...
Call me "Menes, lord of Cats"
Wing Commander Universe
chuck_starchaser
Elite
Elite
Posts: 8014
Joined: Fri Sep 05, 2003 4:03 am
Location: Montreal
Contact:

Post by chuck_starchaser »

klauss wrote: In fact, I just saw the difference between the 6600 and the 9800: In the 6600, I could do this (in the pixel shader):

Code: Select all

const float ds=1.0/8.0;
const float d_mypos=8.0;
const int nsc=8;
for (int s=-nsc; s<=nsc; ++s)
   for (int t=-nsc; t<=nsc; ++t)
      dlighting += exrpand_rgbs(textureCube(EnvironmentMap,
         bump+ds(s*tgw+t*tgw)), d_mypos);
dlighting *= 0.5/float((2*nsc+1)*(2*nsc+1));
(and it would run - not too fast, but run nonetheless).
Won't pretend I understand anything there, except perhaps that there's a nested loop scanning in x and y; just thought I'd mention though chances are 99.999% you already know, it will run fast if the number of iterations, unrolled, fit within the length of the pipeline.
chuck_starchaser wrote:You intend to compute specular dynamic occlusion with environment mapping somehow?
Yep.
Wow!
Have anything, with bumps and all?
That's just it; I have nothing yet. Wonder if there might be something, somewhere on the net... Let me do some googling.
Ya... subdivision geo + bake is really nice, but if you're doing the baking to a texture. If you do it to vertex attributes (color), like we talked, subdivision won't help.
Right, I forgot; unless we keep the subdivisions...
We could have both techniques implemented - no sweat.
Well, I'll just do a standard baking, for now; --better than no baking--; and a highly subdivided one if you want, later; just need to find out how to convert the bump-map to geometry...
klauss
Elite
Elite
Posts: 7243
Joined: Mon Apr 18, 2005 2:40 pm
Location: LS87, Buenos Aires, República Argentina

Post by klauss »

chuck_starchaser wrote:Won't pretend I understand anything there, except perhaps that there's a nested loop scanning in x and y; just thought I'd mention though chances are 99.999% you already know, it will run fast if the number of iterations, unrolled, fit within the length of the pipeline.
Well... all it does is average an area of the environment map. It's not the final version - because of it slowness, I had to unroll manually and implement a much more optimized (and accurate - I added some wieghting of the little pieces) version. It turns out that GLSL doesn't know how to unroll nested loops - if I had coded it with a single loop, it would have been unrolled - but not with two loops, so it was running dynamic branching on the pixel shader :shock: 8)
chuck_starchaser wrote:Well, I'll just do a standard baking, for now; --better than no baking--; and a highly subdivided one if you want, later; just need to find out how to convert the bump-map to geometry...
I think you just map the texture, instead of diffuse, specular, emissive or whatever, to "displace" (or something similar). Then you apply some tesselation (non-smoothing subsurfing), and you're set.
Oíd mortales, el grito sagrado...
Call me "Menes, lord of Cats"
Wing Commander Universe
chuck_starchaser
Elite
Elite
Posts: 8014
Joined: Fri Sep 05, 2003 4:03 am
Location: Montreal
Contact:

Post by chuck_starchaser »

Can't find... Closest I came is this NVidia demo I downloaded, but it uses 3D textures instead of normal maps, for self-occlusion, and all the files are in weird formats; well, all textures are .dds; problem is you can't tell what they are by looking at the filename... And all the models are .nmb, whatever the heck that is...
Tons of models out there for download, but nothing complete...
klauss
Elite
Elite
Posts: 7243
Joined: Mon Apr 18, 2005 2:40 pm
Location: LS87, Buenos Aires, República Argentina

Post by klauss »

Hm... I remember Mamiya once oferred to send a "complete" version of the Tarsus. I don't remember if he did... I'll check tonight (if he did, I'll have it archived at home).
Oíd mortales, el grito sagrado...
Call me "Menes, lord of Cats"
Wing Commander Universe
chuck_starchaser
Elite
Elite
Posts: 8014
Joined: Fri Sep 05, 2003 4:03 am
Location: Montreal
Contact:

Post by chuck_starchaser »

I found a station from 2001, as an LWO, with bumpmaps and all, loaded it into Blender. The blender file seems to be okay
http://www.deeplayer.com/claudio/stationV.blend
though it uses multiple textures and tiling textures, of course...
I tried exporting to .obj, tho, and, looking at the .mtl file, I notice the bumpmaps didn't get exported. I'm putting the zip there anyways, as you probably need those bmp's in it... Hope you can export well to Ogre mesh.
http://www.deeplayer.com/claudio/stationV.zip
klauss
Elite
Elite
Posts: 7243
Joined: Mon Apr 18, 2005 2:40 pm
Location: LS87, Buenos Aires, República Argentina

Update

Post by klauss »

Ok... lots of bugfixes (you can't imagine how many errors there were - proof that high precision in GI is overrated).

Overrated and all... look how much improvement the bugfixes brought:
Indirect only - shot 1
(no direct lighting in this environment - proof that we can depend on GI with lightless environments, which aren't uncommon - like inside planetary shadows)
Indirect only - shot 2
Indirect only - shot 2
Indirect + Direct - shot 1

PS: And guess what... without the bugs, it runs faster :D
Oíd mortales, el grito sagrado...
Call me "Menes, lord of Cats"
Wing Commander Universe
chuck_starchaser
Elite
Elite
Posts: 8014
Joined: Fri Sep 05, 2003 4:03 am
Location: Montreal
Contact:

Post by chuck_starchaser »

Looking very natural. So, I take it "Indirect" means that there's no standard OGL lighting, but GI only? And the last one has some OGL light to extend dynamic range?
klauss
Elite
Elite
Posts: 7243
Joined: Mon Apr 18, 2005 2:40 pm
Location: LS87, Buenos Aires, República Argentina

Post by klauss »

Exactly - the last one has the sun, as a "standard" light.
It's not a prominent shot of the lit part, because direct lighting tends to hide ambient lighting (quite rightly) and it wouldn't show off GI much.
Oíd mortales, el grito sagrado...
Call me "Menes, lord of Cats"
Wing Commander Universe
chuck_starchaser
Elite
Elite
Posts: 8014
Joined: Fri Sep 05, 2003 4:03 am
Location: Montreal
Contact:

Post by chuck_starchaser »

So, if I'm beginning to understand something, diffuse lighting there works like environment mapping, exept that it uses only the surface normal;-- and the cube map is super-ultra-mega filtered?
That's probably more correct than the ambient occlusion feature in Blender's integrated renderer, in that it takes angle into account. I just can't imagine how you do self-occlusion, if you do. But then again, I can't imagine how you do or think of doing self-occlusion in specular environment mapping, either; unless there's a cone of visibility quaternion stored in each vertex of the mesh or something...
klauss
Elite
Elite
Posts: 7243
Joined: Mon Apr 18, 2005 2:40 pm
Location: LS87, Buenos Aires, República Argentina

Post by klauss »

chuck_starchaser wrote:But then again, I can't imagine how you do or think of doing self-occlusion in specular environment mapping, either; unless there's a cone of visibility quaternion stored in each vertex of the mesh or something...
Bingo - I'll use Blender's radiosity bakings to get such a quaterion, though it wouldn't be a quaterion, rather, a rough sampling of from which directions light can come through (and how much of it) - then I adjust filtering to do that - take that much light from those directions. Cool... huh?
Oíd mortales, el grito sagrado...
Call me "Menes, lord of Cats"
Wing Commander Universe
chuck_starchaser
Elite
Elite
Posts: 8014
Joined: Fri Sep 05, 2003 4:03 am
Location: Montreal
Contact:

Post by chuck_starchaser »

That's super cool! So you'll need bakings from six directions, or is this using different color lights from different directions?
klauss
Elite
Elite
Posts: 7243
Joined: Mon Apr 18, 2005 2:40 pm
Location: LS87, Buenos Aires, República Argentina

Post by klauss »

Two bakings, using different colors for the 3 positive axes, and 3 for the three negative.

I think I can summarize the information into a single 4-component channel, but I'm not certain. I'd love to.
Oíd mortales, el grito sagrado...
Call me "Menes, lord of Cats"
Wing Commander Universe
chuck_starchaser
Elite
Elite
Posts: 8014
Joined: Fri Sep 05, 2003 4:03 am
Location: Montreal
Contact:

Post by chuck_starchaser »

klauss wrote: I think I can summarize the information into a single 4-component channel, but I'm not certain. I'd love to.
Better maximize info than minimize size, since vertices are so much fewer than, and improve the value of so many more, texels.
klauss
Elite
Elite
Posts: 7243
Joined: Mon Apr 18, 2005 2:40 pm
Location: LS87, Buenos Aires, República Argentina

Post by klauss »

Yes, but that info has to be transferred to the pixel shader, and it takes up vector slots - add the matrix I have to pass (another 3 slots), and they're 5 slots only for GI info - it's a lot... I know... 5... 4... not much of a difference, the matrix is probably the worst offender, but still I really feel there's a way to do it - yet I feel like you... maximize info... it's just a slot... arghh... decisions, decisions...
Oíd mortales, el grito sagrado...
Call me "Menes, lord of Cats"
Wing Commander Universe
chuck_starchaser
Elite
Elite
Posts: 8014
Joined: Fri Sep 05, 2003 4:03 am
Location: Montreal
Contact:

Post by chuck_starchaser »

I understand GPU's understand quaternions. That would save 5 out of 9 floats... if my info is right...
klauss
Elite
Elite
Posts: 7243
Joined: Mon Apr 18, 2005 2:40 pm
Location: LS87, Buenos Aires, República Argentina

Post by klauss »

It doesn't, but I could code everything necessary to teach it.
Thing is, you trade register space for performance - and performance is a bit a higher priority right now (in fact, one of the optimizations was by sending the matrix instead of building it, as I was doing before).

Also, since it's an orthonormal matrix, I could send only two vectors, and derive the third with an optimized cross-product (no division, since vectors are normalized).

But... well... it's all trading one resource by the other - so, I say again, decisions... decisions...

I think I'll settle for having the full information in the vertex shader and, if I want, I can compress it there (and send it compressed to the pixel shader) - yes, that sounds like a nice option.
Oíd mortales, el grito sagrado...
Call me "Menes, lord of Cats"
Wing Commander Universe
mkruer
Site Administrator
Site Administrator
Posts: 1089
Joined: Thu Jan 02, 2003 10:07 am
Contact:

Post by mkruer »

chuck_starchaser wrote:I understand GPU's understand quaternions. That would save 5 out of 9 floats... if my info is right...
This is where the Programmable GPU is coming. The later Graphics cards Nvidia' > G70 and ATi > 1x00 I think support this kind of opperation.
I know you believe you understand what you think I said.
But I am not sure you realize that what you heard is not what I meant.

Wing Commander Universe Forum | Wiki
Wing Commander: The Wasteland Incident
chuck_starchaser
Elite
Elite
Posts: 8014
Joined: Fri Sep 05, 2003 4:03 am
Location: Montreal
Contact:

Post by chuck_starchaser »

[CRAZY... NUTS]
Could have a texture where each pixel is indexed by vertex number, containing all the extra vertex info. Is there a 75-color format? :)
[/CRAZY... NUTS]
Halleck
Elite
Elite
Posts: 1832
Joined: Sat Jan 15, 2005 10:21 pm
Location: State of Denial
Contact:

Post by Halleck »

Not sure about the crazy-go-nuts, but for image formats you could try a palleted PNG or GIF file.
klauss
Elite
Elite
Posts: 7243
Joined: Mon Apr 18, 2005 2:40 pm
Location: LS87, Buenos Aires, República Argentina

Post by klauss »

Actually, he probably meant 75-channel.
I guess you could have a 4*2^n-channel one if you use cubic textures.
It's a nice way of getting lots of information to the pixel shader without having to bind the texturing coordinates - nice thinking.
Though... quite overkill (hence the "crazy nuts")
Oíd mortales, el grito sagrado...
Call me "Menes, lord of Cats"
Wing Commander Universe
chuck_starchaser
Elite
Elite
Posts: 8014
Joined: Fri Sep 05, 2003 4:03 am
Location: Montreal
Contact:

Post by chuck_starchaser »

klauss wrote:Actually, he probably meant 75-channel.
Exactly, well, roughly 75 ;-)
I guess you could have a 4*2^n-channel one if you use cubic textures.
It's a nice way of getting lots of information to the pixel shader without having to bind the texturing coordinates - nice thinking.
Though... quite overkill (hence the "crazy nuts")
Lot's of info for the vertex shader, is what I was thinking. So, if for each vertex you have a vertex number, splitting the bits of that number and using them as U,V indexes into this (3D) texture. So, we could use some tool (mesher?) to put data from bakings from, say, 12 different directions (dodecahedral), into 3 layers of this 3D texture (3x4=12); IF, of course, that were as easy to process as only 6 directions and of benefit.
( OT: I'm going to see a doctor this afternoon. /OT )
klauss
Elite
Elite
Posts: 7243
Joined: Mon Apr 18, 2005 2:40 pm
Location: LS87, Buenos Aires, República Argentina

Post by klauss »

chuck_starchaser wrote:Lot's of info for the vertex shader, is what I was thinking. So, if for each vertex you have a vertex number, splitting the bits of that number and using them as U,V indexes into this (3D) texture. So, we could use some tool (mesher?) to put data from bakings from, say, 12 different directions (dodecahedral), into 3 layers of this 3D texture (3x4=12); IF, of course, that were as easy to process as only 6 directions and of benefit.
Texture samplers on the VS?
That's vs3... veeery advanced stuff, and Ogre doesn't support it yet (though they're working on it, it's in the list for Eihort - the upcoming version). Or was it that they added that to Dagon (the current RC)? Can't remember. Anyway... veeery advanced stuff... I see it much more likely for passing info to the pixel shader (and, since VS-to-PS varying attributes are a scarce resource, it makes a lot of sense).
chuck_starchaser wrote:( OT: I'm going to see a doctor this afternoon. /OT )
Good - I hope it's nothing too serious. Good luck.
Oíd mortales, el grito sagrado...
Call me "Menes, lord of Cats"
Wing Commander Universe
Post Reply