Author Topic: Making custom filter: how to get a global normal  (Read 1245 times)

Shalmu Yakubov   «   on: June 04, 2012, 04:22:47 AM »
I am working on my own filter, written in FLSL. It5 gos well, the language is great! My filter is almost done, but I have one last question to finish it.
How do I get a global normal for a fragment? It was easy to get a local one:
input NORMAL no;
...
interpolated float4 iNO;
private void v_my()
{
    iNO = no;
}
private float4 f_terrain(){   
    return iNO;
}
Now I can see the colors of a normals on the object, but when I rotate the object, the normals do not change, which means they remain local. What should I do to make these normals global?

Ivan Vodopiviz   «   Reply #1 on: June 05, 2012, 09:55:31 AM »
Hi,

You can calculate it yourself like this:

private
WORLD world;

And then

float3
wNormal = normalize( normal * world );

Hope this helps!


Shalmu Yakubov   «   Reply #2 on: June 07, 2012, 04:36:46 PM »
Thank you so much!

Shalmu Yakubov   «   Reply #3 on: June 14, 2012, 08:06:55 AM »
Excellent, now how do i get the normal _relative_ to a camera, i.e. global for a camera, not for a world? Because now when a camera is rotated around the object, normals do not change, they change only when I rotate an object inside the world.

Ivan Vodopiviz   «   Reply #4 on: June 14, 2012, 10:49:08 AM »
It's pretty much the same, you just have to use WORLD_VIEW instead of WORLD:

private
WORLD_VIEW worldView;

And then

float3
wNormal = normalize( normal * worldView );

Hope this helps!

Shalmu Yakubov   «   Reply #5 on: June 14, 2012, 12:02:02 PM »
Well, it works weird. For example this code:
private WORLD_VIEW worldView;
input NORMAL no;
interpolated float4 iNo;
private void v_normalColor(){    iNo = no; }
private float4 f_normalColor() {   
    float3 n = iNo * worldView;
    n = normalize(n);   
    n = n*0.5+0.5;    /// set it to a 0-1 range to make it look good on the screen   
    return float4(n.x, n.y, n.z, 1);   
    delete n;
}
just fill all pixels with blue. If I remove the line "n = normalize(n);" -  then I see something which looks like a normal map (althought it's not), but when I translate the object by X or Y - all pixels turn to blue ot while or green... To see the normal-map-like pixels again, I need to move the object back to its original positions.

Jason Huang   «   Reply #6 on: June 18, 2012, 04:25:00 PM »

I also wonder how to get the shader calculation correlated to the camera. I am building my depth blur filter. Currently it is renderd to a texture to perform the blur, it is more like a "fast blur" in After Effects. How can I calculate the depth in this case?
P.S it is not a filter which apply to each objects. it is more like a mask of camera.

Best

Jason Huang   «   Reply #7 on: June 18, 2012, 08:59:01 PM »

I think I really need help here, I am creating DOF, at this moment all I have to do is figure out a way to linearlize the depth buffer, and then use it as factor to determine how the texture rendered from contex would be affected. I could get a 16x blur right now, Could any one give me a hint please?

Cheers 

Jason Huang   «   Reply #8 on: June 19, 2012, 09:43:01 AM »

Any news? I really need to render 2 images to the texture, one is for the blured image, another is for the linearized depth buffer( somthing like the whole scene has been rendered by one depth material(black and white), depending on the near and far limitations), this could easily done if I do not render blured image at the same time. The problem is the second image is just used for specail blending.... Do I need 2 cameras?

Ivan Vodopiviz   «   Reply #9 on: June 19, 2012, 12:15:39 PM »
Hi Jason,

One way to do that is to perform a render to texture of the scene using a only a material with fog filter, then create a shader that glues together that and the blurred texture. The fog filter should give you a linearized version of the scene.

Jason Huang   «   Reply #10 on: June 19, 2012, 12:23:06 PM »

well, I tried it too many times, here is the problem that how can I arrange the timing of render both Blur and Depth  texture? they are both using setRenderToTexture.... pls help...

Jason Huang   «   Reply #11 on: June 19, 2012, 12:24:52 PM »

if I rendered the scene with Fog filter, the original texture sample would not be renderd for my blur.
Inversly, dose not work either....

Jason Huang   «   Reply #12 on: June 20, 2012, 10:43:57 AM »
the current result is like this. But it might be tricky to do a real DOF effect. Ivan, I really need your help.

Jason Huang   «   Reply #13 on: June 20, 2012, 10:48:53 AM »

Sorry, the link is here.

Ivan Vodopiviz   «   Reply #14 on: June 21, 2012, 01:16:59 PM »
Hi,

What do you mean by "if I rendered the scene with Fog filter, the original texture sample would not be renderd for my blur."?

Are you rendering the fog to a texture and then blending that with the original one? By the way, the demo in your link seems to be down at the moment.

Cheers,