• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
lipsryme

Normal encoding problems

10 posts in this topic

I've been trying to correctly encode my view-space normals for a while now but it's just not working.
I tried every algorithm in here ([url="http://aras-p.info/texts/CompactNormalStorage.html#intro"]http://aras-p.info/t...rage.html#intro[/url]) but every time I get wrong normals.
Well except the basic one.
[CODE]
half4 encode (half3 n, float3 view)
{
return half4(n.xyz*0.5+0.5,0);
}
half3 decode (half4 enc, float3 view)
{
return enc.xyz*2-1;
}
[/CODE]

This works perfectly but my specular keeps jumping around. I guess that would be a precision issue because of the 8bit target.
Well so then I try the next easiest thing which is storing X&Y and reconstructing Z like this:
[CODE]
half4 encode (half3 n, float3 view)
{
return half4(n.xy*0.5+0.5,0,0);
}
half3 decode (half2 enc, float3 view)
{
half3 n;
n.xy = enc*2-1;
n.z = sqrt(1-dot(n.xy, n.xy));
return n;
}
[/CODE]

And it's error all over again. The lighting changes with my view direction. (where I look at)
I tried this with both an R8G8B8A8 and R16G16 format but no change.
How is it that every encoding method I try fails.
Any idea what I'm fundamentally doing wrong ?

Normals are calculated this way:
[CODE]
float4x4 WorldView = mul(World, View);

// Output view space normals
output.Normal.xyz = mul(input.Normal, (float3x3)WorldView);
[/CODE] Edited by lipsryme
0

Share this post


Link to post
Share on other sites
You should ensure to input only normalized normals to your encoding function, if you take the interpolated vertex normals you might encounter artifacts. Test if this works:
[CODE]
half4 encode (half3 n, float3 view)
{
half3 tmp = nomalize(n);
return half4(tmp.xy*0.5+0.5,0,0);
}
[/CODE] Edited by Ashaman73
0

Share this post


Link to post
Share on other sites
Nope, still not correct somehow : /

Also with this algorithm the z direction seems to be inverted.

Added video showcasing the problem:
[media]http://www.youtube.com/watch?v=xKjusqHV0q8&feature=youtu.be[/media]
(Diffuse only)
Directional light source is shining towards (0, 0, -1) so only the front face of the cube should be lit.

And here's the pixel shader code:
[CODE]
float4 encodedNormals = NormalTarget.Sample(PointSampler, input.UV);
float3 N = decode(encodedNormals);
float3 LightDir = mul(_LightDirection, View);
float NdotL = saturate(dot(N, -LightDir));
lighting.rgb = float3(NdotL, NdotL, NdotL);
[/CODE] Edited by lipsryme
0

Share this post


Link to post
Share on other sites
You can't use normal.z=sqrt(1-....) because you will lose the sign of the z component (even in view space there can still be normals that have z component negative).
0

Share this post


Link to post
Share on other sites
Have you tried debugging with PIX?

Or at the very least drawing your encoded normal rendertarget so you can look at it and see if the problem lies in the encoding or the decoding.
0

Share this post


Link to post
Share on other sites
It may be that you'll need to negate your normals for the compression algorithm and negate them again in the decompression algorithm.

Also, ensure that your normals are normalized.

Cheers!
0

Share this post


Link to post
Share on other sites
Okay so I've tried them all again (except per pixel view space [method #8]) and the only thing that seems to work without any problems is the spherical coordinates one.
stereographics projection doesn't work (view dependent and wrong direction), same with the spheremap (mittring). The lambert-azimuthal equal area projection works almost but has some error with specific viewing angles (the NdotL becomes 0 suddenly for a second).

So I guess I'll be using the spherical coordinates for now but I still don't understand how more than half of the algorithms on this page just doesn't work for me.
If I could I'd probably use the spheremap transform...does anyone have an idea why this doesn't work ?
And yes sure I have been debugging this for a while with PIX I'm not seeing anything exceptional there that you couldn't already tell when going through the encoding/decoding in your head/on paper.

Also a little off topic but should bloom and tonemapping be used on specular ? It does seem to loose quite a bit of "energy" and form when going through those passes.
0

Share this post


Link to post
Share on other sites
I use RG16_FLOAT target for the normals and the following code adapted from the stereographic projection. I had to negate the normals to make it work correctly.

[CODE]
#define STEREOSCALE 1.77777f
#define INVSTEREOSCALE (1.0f/STEREOSCALE)
float3 StoreNormal(float3 n)
{
n = normalize(-n);
float2 enc = (n.xy / (n.z+1)) * INVSTEREOSCALE;

return float3(enc,0);
}
float3 RestoreNormal(float3 enc)
{
float scale = STEREOSCALE;

float3 nn = enc.xyz * float3(scale,scale,0);
nn.z = 1.0f;
float g = 2.0 / dot(nn.xyz,nn.xyz);
float3 n;
n.xy = g*nn.xy;
n.z = g-1;
return normalize(-n);
}
[/CODE]

Cheers!
2

Share this post


Link to post
Share on other sites
@kauna that actually works [img]http://public.gamedev.net//public/style_emoticons/default/tongue.png[/img]
I'm not sure why as I normalize before passing the normals to the encode function and after I decode them but that normalize and negation seems to be the key. Just negating alone doesn't do the trick. At least for the stereographic projection. Tried the same on the spheremap but didn't work as good unfortunately ;p

Thanks a lot though [img]http://public.gamedev.net//public/style_emoticons/default/smile.png[/img]

btw what is it that you're doing different with the algorithm than the version on aras page ?
I see you calculate the stereoscale yourself but there appears to be a few other changes.

Also is it correct to sample the encoded normals bilinear ? Edited by lipsryme
0

Share this post


Link to post
Share on other sites
The Ares page version is storing the value to a integer target so there is some math done to map the values between 0..1 and vice versa for the decoding step. I realized that it was unnecessary with a floating point target.

Cheers! Edited by kauna
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0