Doom3world

The world is yours! Doom 3 - Quake 4 - ET:QW - Prey - Rage
It is currently Thu May 23, 2013 11:10 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 21 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: HowTo: Cube map projection and 3D attenuation
PostPosted: Mon Jan 17, 2011 3:24 am 
Offline
Last man standing
User avatar

Joined: Thu Aug 19, 2004 7:22 pm
Posts: 1125
Here's the shader code necessary to do lights with cube map projections and 3D (spherical) attenuation. Keep in mind that all projection textures must be cube maps, no 2D projection textures can be used, not even for projected lights. To use projected lights, use a cube map where +/-X, +/-Y, and +Z faces are completely black. -Z will be the projection face. Falloff textures are not used so they don't need to be defined in the light's material. And just use "cubeMap" instead of "map" in the light's material.

Let me know if you have any question.

Code:
# note:   lightFallTC = fragment.texcoord[2]
#         lightProjTC = fragment.texcoord[3]

# calculate point light tc
MOV    R1, lightProjTC;
MOV    R1.z, lightFallTC.x;
MAD    R1.xyz, R1, 2.0, -1.0;

# calculate projected light tc
MOV    R2, lightProjTC;
MOV    R2.z, -1.0;
RCP    R2.w, lightProjTC.w;
MUL    R2.xy, R2, R2.w;
MAD    R2.xy, R2, 2.0, -1.0;

# sample projection cube map
TEX    lightCube, R1, texture[3], CUBE;
TEX    lightProj, R2, texture[3], CUBE;

# calculate attenuation (x = point, y = projected)
DP3    R1.x, R1, R1;
POW    R1.x, R1.x, 0.5.x;
MOV    R1.y, lightFallTC.x;
ADD_SAT R1.xy, 1.0, -R1;
MUL    R1.xy, R1, R1;
MUL    lightCube, lightCube, R1.x;
MUL    lightProj, lightProj, R1.y;

# if w > 1.0, light = projected, else light = point
SLT    R1.x, 1.0, lightProjTC.w;
CMP    atten, -R1.x, lightProj, lightCube;



*Edit: Uploaded a test map showcasing cube map projection and ambient cube lighting. It's recommended to load it in the editor.
http://sikkpin.fileave.com/ambientcube_test.rar


Last edited by Sikkpin on Fri Jan 21, 2011 6:57 am, edited 1 time in total.

Top
 Profile E-mail  
 
 Post subject: Re: HowTo: Cube map projection and 3D attenuation
PostPosted: Mon Jan 17, 2011 5:23 am 
Offline
did just hit his 750th monster

Joined: Tue Jul 05, 2005 3:15 pm
Posts: 824
Location: Adelaide - Australia
So just to be clear, this works fine as an entity in stock standard Doom 3, no mods or anything required?

Would you expect much of a performance hit for a cube mapped light over a regular one?


Top
 Profile  
 
 Post subject: Re: HowTo: Cube map projection and 3D attenuation
PostPosted: Mon Jan 17, 2011 6:29 pm 
Offline
Last man standing
User avatar

Joined: Thu Aug 19, 2004 7:22 pm
Posts: 1125
If by mods you mean a custom dll, then yes, you don't need a mod for this to work. But you still need to have custom light materials and cube map projection textures.

As for performance, aside from the extra shader instructions, there will probably be a performance hit for the fact you'd have to overlap lights to have the same area coverage that you'd have with 2D+1D lights. Of course, this can be helped by doing an early-out test in the shader and to also use less but larger lights in your maps (with spherical lights with cube map projections, you'll find this looks better anyway, using less but larger lights I mean).


Top
 Profile E-mail  
 
 Post subject: Re: HowTo: Cube map projection and 3D attenuation
PostPosted: Tue Jan 18, 2011 1:05 pm 
Offline
did just hit his 750th monster

Joined: Tue Jul 05, 2005 3:15 pm
Posts: 824
Location: Adelaide - Australia
Awesome. You're the man Sikkpin! :D


Top
 Profile  
 
 Post subject: Re: HowTo: Cube map projection and 3D attenuation
PostPosted: Thu Jan 20, 2011 6:49 am 
Offline
Last man standing
User avatar

Joined: Thu Aug 19, 2004 7:22 pm
Posts: 1125
Another use for cube maps, image-based ambient lighting. Still needs to be flushed out a bit more but it's promising and looks to be a good ambient solution to compliment the cube map projection for direct lighting. All shots just use a single light in the center the room.

First two shots show my initial test, left is lighting only, right is with diffuse. Cube map used = env/cylinder
Image Image

These show diffuse+specular. Cube maps used from left to right: env/sheen, env/cylinder, Showroom256 from CubeMapGen
Image Image Image


Top
 Profile E-mail  
 
 Post subject: Re: HowTo: Cube map projection and 3D attenuation
PostPosted: Thu Jan 20, 2011 9:38 am 
Offline
picked up 200 ammo
User avatar

Joined: Tue Dec 09, 2008 1:05 pm
Posts: 208
wow, really awesome :D it look's like a hdri lighting :wink:
can you unpload your showcase and other stuff?please


Top
 Profile E-mail  
 
 Post subject: Re: HowTo: Cube map projection and 3D attenuation
PostPosted: Thu Jan 20, 2011 7:43 pm 
Offline
picked up the chaingun

Joined: Wed Mar 05, 2008 6:43 pm
Posts: 191
RipOutTheWings wrote:
wow, really awesome :D it look's like a hdri lighting :wink:
can you unpload your showcase and other stuff?please


Well, it more or less is, actually. :) Sikk, if you're paying attention, updating cubemaps to full HDR actually sounds like a worthwhile endeavor. Considering that you already have a halfway decent HDR encoding system set up, you think you could reauthor or convert the existing cubes over to use it?


Top
 Profile E-mail  
 
 Post subject: Re: HowTo: Cube map projection and 3D attenuation
PostPosted: Thu Jan 20, 2011 11:24 pm 
Offline
Last man standing
User avatar

Joined: Thu Aug 19, 2004 7:22 pm
Posts: 1125
Some shots that maybe better represent this shit. Why the fuck are the sky cubes and reflections cubes arranged differently. It's fucking hard to match them up. Especially when CubeMapGen's output is completely different than either setup.
Image Image Image Image

Yes, I know, that second shot looks fucking awesome. ;)


Top
 Profile E-mail  
 
 Post subject: Re: HowTo: Cube map projection and 3D attenuation
PostPosted: Fri Jan 21, 2011 2:12 am 
Offline
picked up 200 ammo
User avatar

Joined: Tue Dec 09, 2008 1:05 pm
Posts: 208
Quote:
Yes, I know, that second shot looks fucking awesome.

+1 :D


Top
 Profile E-mail  
 
 Post subject: Re: HowTo: Cube map projection and 3D attenuation
PostPosted: Fri Jan 21, 2011 3:10 am 
Offline
Last man standing
User avatar

Joined: Thu Aug 19, 2004 7:22 pm
Posts: 1125
Another one...
Image


Top
 Profile E-mail  
 
 Post subject: Re: HowTo: Cube map projection and 3D attenuation
PostPosted: Fri Jan 21, 2011 6:58 am 
Offline
Last man standing
User avatar

Joined: Thu Aug 19, 2004 7:22 pm
Posts: 1125
Update first post with a link to a demo map.


Top
 Profile E-mail  
 
 Post subject: Re: HowTo: Cube map projection and 3D attenuation
PostPosted: Fri Jan 21, 2011 8:28 am 
Offline
picked up 100 armour

Joined: Sat Dec 05, 2009 10:30 pm
Posts: 109
Is this already integrated into sikkmod? If not can we make adjustments for it to be integrated? Let me know thx.


Top
 Profile E-mail  
 
 Post subject: Re: HowTo: Cube map projection and 3D attenuation
PostPosted: Wed Jan 26, 2011 5:21 pm 
Offline
fired 300 rounds
User avatar

Joined: Sat Jun 28, 2008 2:17 pm
Posts: 350
This is cool, but can it do a cubemap thats not projected from infinity? I mean like a lantern with a grill mapped to all 6 sides, last I knew this was imppossible in d3.

_________________
"John Carmack needs to use more emoticons to get his message across."


Top
 Profile E-mail  
 
 Post subject: Re: HowTo: Cube map projection and 3D attenuation
PostPosted: Wed Jan 26, 2011 7:18 pm 
Offline
Last man standing
User avatar

Joined: Thu Aug 19, 2004 7:22 pm
Posts: 1125
That's what this thread is originally about. The code in the first post does exactly that. Cube map projection. In the little demo map I posted, the first room with the Hellknight shows all three light types in action: point, projected and ambient, all using cube maps in some way. All of the other skybox rooms just show of the ambient cube lighting.


Top
 Profile E-mail  
 
 Post subject: Re: HowTo: Cube map projection and 3D attenuation
PostPosted: Wed Jan 26, 2011 9:30 pm 
Offline
fired 300 rounds
User avatar

Joined: Sat Jun 28, 2008 2:17 pm
Posts: 350
My mistake, I sort of skipped over the first room and assumed they were just projected lights. *edit: it was your phong tile texture not recieving shadows, other materials work fine*

Also what are the disadvantages of this, if any? Seems like something id should have done to begin with.

_________________
"John Carmack needs to use more emoticons to get his message across."


Top
 Profile E-mail  
 
 Post subject: Re: HowTo: Cube map projection and 3D attenuation
PostPosted: Wed Jan 26, 2011 10:14 pm 
Offline
Last man standing
User avatar

Joined: Thu Aug 19, 2004 7:22 pm
Posts: 1125
Yeah, the tile textures I use have noShadows on as I use these just to test shading and such and having shadows on just interferes.

And there are no real disadvantages to using cube maps, only advantages, at least with modern hardware. But back in '04, id's decision to use 2D projection maps was most likely entirely due to keeping performance as high as possible. Performance advantages 2D+1D have over 3D+cubemap are, one: being able to maximize the area effected by lights without having to overlap the light volumes (square lights vs spherical lights) and two: only needing to load one texture for the projection instead of six. These may not seem like a big deal now but with the way id likes to light their maps (with many small lights) I'm sure it was back then.


Top
 Profile E-mail  
 
 Post subject: Re: HowTo: Cube map projection and 3D attenuation
PostPosted: Thu Jan 27, 2011 8:45 am 
Offline
fired 300 rounds
User avatar

Joined: Sat Jun 28, 2008 2:17 pm
Posts: 350
I am getting black shimmering.

Image
winxp, amd x4 810, GeForce 9500 GT

Also it seems like this is only supposed to work with tga format?

_________________
"John Carmack needs to use more emoticons to get his message across."


Top
 Profile E-mail  
 
 Post subject: Re: HowTo: Cube map projection and 3D attenuation
PostPosted: Tue Feb 21, 2012 3:34 pm 
Offline
is connecting to Doom3world.org

Joined: Tue Feb 21, 2012 2:37 pm
Posts: 3
Hi there, is there anybody aware of how i can basically find the coresponding index for a (row,col) in a 1D representation of 2D? I need to write funtions which can convert from track a cell phone 2D to 1D and next ID back to 2D because the 2D will be dislayed in a listbox as 1D.


Last edited by Alian_Morris on Tue Apr 10, 2012 8:19 am, edited 1 time in total.

Top
 Profile E-mail  
 
 Post subject: Re: HowTo: Cube map projection and 3D attenuation
PostPosted: Sun Feb 26, 2012 4:46 am 
Offline
picked up 100 armour

Joined: Tue Nov 24, 2009 2:51 am
Posts: 115
the link to the test map is dead :(

Can someone tell me were do i put the Sikkpin code is it on the glprogs foulder?


Top
 Profile E-mail  
 
 Post subject: Re: HowTo: Cube map projection and 3D attenuation
PostPosted: Mon Feb 27, 2012 4:47 am 
Offline
picked up 100 armour

Joined: Wed Dec 07, 2011 8:23 am
Posts: 128
Here's a Dropbox link of the file Argoon :D

http://dl.dropbox.com/u/17706561/ambientcube_test.rar


Top
 Profile E-mail  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 21 posts ]  Go to page 1, 2  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group