View Full Version : bent normals in shake
pldIII 03-06-2006, 12:33 PM Hi All,
I'm trying to implement a macro in Shake that would take a bent normal pass and an HDR environment map and would generate an "Ambient Environment" pass. If I understand correctly, I should be able to use the normal info (RGB represent direction) from by bent normal pass to lookup the HDR env file. This should create a new pass which is lit by the HDR environment. My question is how to do this in Shake? I don't seem to be able to do any per-pixel operations therefore I'm finding it hard to read the pixel values of my normal map and use the direction information from the RGB channels to lookup the HDR environment map.
any help would be appreciated!
cheers
| |
Aneks
03-06-2006, 11:44 PM
there are a bunch of macros around which do this at present. Search through some of the shake threads and you will find them.
From memory pocket-rocket had a the fastest one. http://www.pocket-rocket-fx.com/
Blur1
03-07-2006, 02:15 PM
Check out the Texture Map macro by Philip Graham. It's for UV remapping but he mentioned here on cgtalk that it works for bent normals too, since you are taking an image with U and V directions (or x/y) and warping it using the r+g channels of the bent normals image.
http://shake.pwgraham.com/
I think the reason the blue channel is not needed is that the contribution is implied because the red+green are known (and it's camera space, ie 2D).
You need to supply the environment map in mirrorball format. So if you have a latlong env map, first warp it using a normal sphere render then feed this downstream.
I used a Scroll node so I can rotate the "light dome".
I also blurred the image right out, to mimic an "importance sampled" image.
To do the UV stuff from scratch, digitalartform has a tutorial:
digitalartform.com/archives/2005/07/uv_map_now_or_u.html
HTH and would like to see your macro
Michael
pgraham
03-07-2006, 07:28 PM
Check out the Texture Map macro by Philip Graham.Thanks for recommending me.
I should be able to use the normal info (RGB represent direction) from by bent normal pass to lookup the HDR env file. This should create a new pass which is lit by the HDR environment.If you lookup directly into the HDR map (or mirrorball), the result will look like chrome reflecting the HDR map. If you want your normal mapped object to look like a diffuse shader, you should render a diffuse ball lit by the HDR map in a 3D program, then texture map the diffuse ball image onto your bent normal map in Shake.
Blur1
03-07-2006, 09:19 PM
Thanks for recommending me.
If you lookup directly into the HDR map (or mirrorball), the result will look like chrome reflecting the HDR map. If you want your normal mapped object to look like a diffuse shader, you should render a diffuse ball lit by the HDR map in a 3D program, then texture map the diffuse ball image onto your bent normal map in Shake.
How about blurring in post before the warping, with a super high blur value? I got quite good results from this. I remember reading that this is what ILM did on Pearl Harbor...at the time it was too expensive to calculate the hdri map lookup.
Thanks for posting the original tip! I've also had a go at NPR shading using the same basic idea.
pgraham
03-07-2006, 11:19 PM
How about blurring in post before the warping, with a super high blur value?This does simulate the fact that each pixel of the object is lit by many pixels of the HDR map. I was assuming that the sphere would be a reflection of the HDR map, which would make the blurry environment feel like a dull specular reflection. I suppose you could easily set up a shader that would sample the HDR directly from the normal vector instead of the reflected vector. Then the blurry HDR would look very similar to diffuse shading.
Maybe that's how HDR lighting in games is done. Pre-blur the HDR map and then it's just a normal vector lookup every frame.
I've also had a go at NPR shading using the same basic idea.As a matter of fact, the first google result for npr shading (http://www.google.com/search?hl=en&q=npr+shading&btnG=Google+Search) uses the technique.
Blur1
03-07-2006, 11:42 PM
This does simulate the fact that each pixel of the object is lit by many pixels of the HDR map. I was assuming that the sphere would be a reflection of the HDR map, which would make the blurry environment feel like a dull specular reflection. I suppose you could easily set up a shader that would sample the HDR directly from the normal vector instead of the reflected vector. Then the blurry HDR would look very similar to diffuse shading.
I see what you are saying. If I was going to prepare this in 3D first and was not going ot use some form of GI to render the sphere reference, I would spherically project the map onto the sphere, and blur it within the the 3D program. This would simulate a sampling from the normal vector because as you point out, you get a different (incorrect) look if you do it along the reflection vector.
Speaking of, based on the post-methods we are discussing, how would you remap reflections in post, that behave correctly when the camera moves (ie the reflection map is probed along the reflection vector)?
As a matter of fact, the first google result for npr shading (http://www.google.com/search?hl=en&q=npr+shading&btnG=Google+Search) uses the technique.
Thanks for the tip, am checking it out.
pldIII
03-08-2006, 09:54 AM
Thanks for all your comments,
instead of blurring the HDR map, I usually apply a diffuse convolution which gives basically identical results to sampling with thousands of rays an HDR map. My only problem is how to do the look up of this "blurred" environment in shake. I have done it in 3D and works well however it might be even more useful in 2D...
Michael, thanks for your links they seem very interesting. I will try to have a look today and see if they help me :) Also, I saw in some other thread that you posted a screenshot of a shake script that does exactly this! What equation did you use in the DisplaceX and ColorX nodes?
cheers!
pgraham
03-08-2006, 06:54 PM
how would you remap reflections in post, that behave correctly when the camera movesI have the process for this written down, I want to create some images or a video of it in action before I post it.
instead of blurring the HDR map, I usually apply a diffuse convolutionThat's exacly what we want to do, what software has that convolution?
What equation did you use in the DisplaceX and ColorX nodes?My TextureMap macro uses ramps instead of a ColorX. I've found that ColorX is very slow and I avoid it when I can. The ramps create an image that will displace the entire texture to the (0,0) pixel using IDisplace. This way I have absolute displacement instead of relative. I add the UV coordinate (or normal map) image to the ramp image, so that IDisplace will map the texture to the UV's.
Blur1
03-08-2006, 11:38 PM
Thanks for all your comments,
instead of blurring the HDR map, I usually apply a diffuse convolution which gives basically identical results to sampling with thousands of rays an HDR map.
Do you do the diffuse convolution in something like HdriShop? Does it take long to calculate?
Michael, thanks for your links they seem very interesting. I will try to have a look today and see if they help me :) Also, I saw in some other thread that you posted a screenshot of a shake script that does exactly this! What equation did you use in the DisplaceX and ColorX nodes?
cheers!
Texture Map is really the one stop shop in this case, just check out the guts to see how it's put together - simple and effective! Doing it in a "graphical" way with UV ramps, and using IDisplace instead of DisplaceX...very nice.
@pgraham, looking forward to seeing the reflections demo.
Edit: I did find it useful to add extra controls for the UV wrap so you can tweak it a bit.
pldIII
03-09-2006, 11:34 AM
You can use HDRShop to compute a diffuse convolution or write your own (spherical harmonics is the usual method). There are a couple of SIGGRAPH papers from Stanford Uni that discuss how to use Spherical harmonics to compute a diffuse convolution.
It takes a while to generate these images so I usually reduce my HDRI to something like 256x128 which is enough resolution to get an accurate result...
pldIII
03-09-2006, 12:28 PM
Texture Map is really the one stop shop in this case, just check out the guts to see how it's put together - simple and effective! Doing it in a "graphical" way with UV ramps, and using IDisplace instead of DisplaceX...very nice.
PG_TextureMap seems a good macro. Unfortunately I cant get the "correct" result. If I use a blurred or convolved map the result seems good.. However if as a test I apply an unblurred environment map it's clear that the result is not right. I compared this to a 3D approach where I use an environment shader and my geometry relects using the normal. The results should be the same. Am I correct?
Blur1
03-09-2006, 12:41 PM
PG_TextureMap seems a good macro. Unfortunately I cant get the "correct" result. If I use a blurred or convolved map the result seems good.. However if as a test I apply an unblurred environment map it's clear that the result is not right. I compared this to a 3D approach where I use an environment shader and my geometry relects using the normal. The results should be the same. Am I correct?
Excuse my un-TD way of describing it but I would have thought an environment shader is implicitly for reflections which would always give you a result based on the reflection vector around the normal then heading towards the camera, which is a different look.
pldIII
03-09-2006, 02:39 PM
Well, I actually use a shader which reflects using the normal direction. So it gets the color of the environment in the normal direction...It's not a typical reflection.
This is what I'm trying to do with Shake..
pldIII
03-09-2006, 03:58 PM
This is a screenshot of what I get If I use the macro with an ENV map and a normal map...
pgraham
03-09-2006, 06:53 PM
This is a screenshot of what I get If I use the macro with an ENV map and a normal map...Yes, that looks correct. Your normal map is in world coordinate space, not camera space. The environment is planar mapped in the z direction.
edit: by correct here I mean, TextureMap is doing its job, but it's true the reflection is not mapped correctly.
What software are you making your normal map with? I can't get Maya to make a world space normal map.
Blur1
03-09-2006, 08:45 PM
I'm assuming the viewer should match the thumbnail for the filein, is that right? How about inverting the Y channel in the normal map? Just a guess because I don't have Shake open to check it out.
pgraham
03-10-2006, 02:51 PM
how would you remap reflections in post, that behave correctly when the camera moves?Okay, I got this...
You have to have 2 images to do this. One is the normal vectors of the surface, in world coordinate space. The other is the direction of light rays going from the camera to the surface, in world space. In Shake, you have to reflect the light rays across the normal vectors (I have a macro for this). So now you have the reflected vectors that point into the environment from the camera point of view.
The environment sphere is a reflection mapped onto normal vectors, so you can't just use the camera reflection to map it. You have to un-reflect the camera reflection from the point of view of the environment probe camera. Let's assume the camera took the environment photo from the z direction. To un-reflect, you have to find the vector halfway between the z vector and the reflection vector. The easy way to do this is by adding the vectors together and then normalizing the result. Finally you can map the environment onto the un-reflected vectors using TextureMap.
Here's a movie of the effect: PG_env_map.mov (http://shake.pwgraham.com/files/PG_env_map.mov)
Here's a screenshot of the Shake tree: PG_env_map_shk.gif (http://shake.pwgraham.com/files/PG_env_map_shk.gif)
for some reason my thumbnails aren't working in shake... the Z_Vector node is just a blue color node, the same size as the NormalVectors image.
Blur1
03-11-2006, 06:55 AM
Thanks for posting, it looks great!! What kind of render pass do you set up to get the camera rays? Is this like a radial fog from the camera?? Total non-TD here....
pgraham
03-11-2006, 04:10 PM
The camera rays pass is a shader I built in hypershade. I took the "point world" parameter of a surface shader and subtracted the camera translation from it to get the vector from the camera to each point on the surface. Then I used a distanceBetween to get the length of the vector. Then I divided the vector by the length to normalize it. Then I used setRange to map the normalized vector from vector space, -1.0 to 1.0, into the color space 0.0 to 1.0 so I could import it into shake.
By itself, distanceBetween would render a radial fog. For this render I need to know the direction of light entering the camera, not how far away it is.
dveight
03-12-2006, 03:46 AM
hey pgraham maybe i am confused but I took a look at your pG_Vec macros...but I thought a vector dot product was sqrt(x*x + y*y + z*z) or to represent rgb sqrt(r*r + g*g + b*b)?
Pat
pgraham
03-13-2006, 01:33 PM
I thought a vector dot product was sqrt(x*x + y*y + z*z)The dot product takes 2 vectors, and the expression is x1*x2+y1*y2+z1*z2. The expression you wrote takes 1 vector and calculates the length of the vector. In the VecNormalize macro, I perform the dot product of the vector with itself, then use a Lookup to perform the square root to get the length.
Blur1
03-13-2006, 01:51 PM
Here is a quick and dirty test for post-mapping reflections.
Quicktime (http://homepage.mac.com/michael_garrett/Sites/other/misc/rfltest.mov)
I compared this to bitmap reflections, spherical projection rendered from the 3D software (C4D) and it is different but looks close. I haven't checked to see why it's not exactly the same.
To achieve this result I baked normals from a sphere then projected them as an environment reflection on the geometry in the movie and rendered this as a pass. I then fed this into PG_TextureMap with an environment map. Not very scientific but interesting nonetheless.
Michael
pgraham
03-13-2006, 09:38 PM
That's a good idea. Actually it's probably the best solution for pldIII, because it uses one render and only the TextureMap macro. Theoretically it should look just like an environment render from the 3D software... I can't really tell how your render is wrong, or whether it's wrong for that matter.
CGTalk Moderation
03-13-2006, 09:38 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.
vBulletin v3.0.5, Copyright ©2000-2009, Jelsoft Enterprises Ltd.