• 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
Nairou

How do you double-check normal map output? (screenshot)

10 posts in this topic

I'm currently trying to learn how to do deferred shading, and in the process I'm trying to make sure my normals are being rendered properly to my FBO texture. I'm using gDEbugger to examine the contents of the FBO textures, and the normal texture is a GL_RGBA16F.

The problem is, I don't know if I am properly transforming my normal map to view space in preparation for deferred lighting. The transformed MRT image appears correct, in terms of the positions of the color variations, but the overall coloring of the result is different from what I've seen in tutorials and other examples. In the examples I've seen, the resulting output remains as vibrant as the original normal map image. That isn't the case for me, but I'm not sure what I'm doing wrong.

Here is a comparison image. The left one is a plain render of the normal map texture to the cube. The one on the right has the normal map transformed into view space.

[img]http://dl.dropbox.com/u/4349589/normal_comparison.jpg[/img]


Gradient positions look right in the transformed image, but the overall coloring seems weird. I don't know how well gDEbugger visualizes RGBA16F textures, or how to check what the actual values are (all gDEbugger shows me are 0-255 color channel values).

Here are the (minimal) shaders I'm using currently, if it helps:

Vertex shader:

[code]

#version 150

uniform mat4 worldproj;
uniform mat4 world;
in vec4 position;
in vec3 normal;
in vec3 tangent;
in vec3 bitangent;
in vec2 texture;

out vec3 v2f_normal;
out vec3 v2f_tangent;
out vec3 v2f_bitangent;
out vec2 v2f_texture;

void main()
{
gl_Position = worldproj * position;
mat3 worldrot = mat3(world);
v2f_normal = worldrot * normal;
v2f_tangent = worldrot * tangent;
v2f_bitangent = worldrot * bitangent;
v2f_texture = texture;
}
[/code]

Fragment shader:
[code]

#version 150

in vec3 v2f_normal;
in vec3 v2f_tangent;
in vec3 v2f_bitangent;
in vec2 v2f_texture;
out vec4 outColor;
out vec4 outNormal;
out vec4 outPosition;
uniform sampler2D texture0;
uniform sampler2D texture1;

void main()
{
outColor = texture2D( texture0, v2f_texture );
outColor.a = 1;
vec3 normal = vec3( texture2D( texture1, v2f_texture ) ) - 0.5;
mat3 t;
t[0] = v2f_tangent;
t[1] = -v2f_bitangent;
t[2] = v2f_normal;
normal = normalize( normal * t );
outNormal = vec4(normal * 0.5 + 0.5, 1.0);
outPosition = texture2D( texture1, v2f_texture );
}
[/code]
0

Share this post


Link to post
Share on other sites
I guess this isn't a very common question? :)

How about this: Is there a way for me to view the values being sampled from a GL_RGBA16F texture? I'm assuming the values are not clamped at 0..1, but I'd like to see what the range actually is, so I know if my math is right is converting them to -1..1.
0

Share this post


Link to post
Share on other sites
[quote name='Nairou' timestamp='1314742651' post='4855655']
I guess this isn't a very common question? :)

How about this: Is there a way for me to view the values being sampled from a GL_RGBA16F texture? I'm assuming the values are not clamped at 0..1, but I'd like to see what the range actually is, so I know if my math is right is converting them to -1..1.
[/quote]
To render your normal map just map -1..1 to 0..1 (color = normal * 0.5 + 0.5). Then start with a plain sphere without any normal map applied. This way you can "read" the normal map, i.e.
red = (1,0,0) = x-axis
green=(0,1,0)=y-axis
1

Share this post


Link to post
Share on other sites
Just from briefly looking over your shader, when you get the normal from the normal map texture you should do value * 2 - 1 to bring it into the range [-1, 1] before you do the tangent space transformation.
0

Share this post


Link to post
Share on other sites
[quote name='johnchapman' timestamp='1314769776' post='4855764']
Just from briefly looking over your shader, when you get the normal from the normal map texture you should do value * 2 - 1 to bring it into the range [-1, 1] before you do the tangent space transformation.
[/quote]

I originally thought that as well, but I have to be doing something wrong as that gives even weirder results.

Changing the vertex shader to this:

[code]

#version 150

in vec3 v2f_normal;
in vec3 v2f_tangent;
in vec3 v2f_bitangent;
in vec2 v2f_texture;
out vec4 outColor;
out vec4 outNormal;
out vec4 outPosition;
uniform sampler2D texture0;
uniform sampler2D texture1;

void main()
{
outColor = texture2D( texture0, v2f_texture );
outColor.a = 1;
vec3 normal = vec3( texture2D( texture1, v2f_texture ) ) * 2 - 1;
mat3 t;
t[0] = v2f_tangent;
t[1] = -v2f_bitangent;
t[2] = v2f_normal;
normal = normalize( normal * t );
outNormal = vec4(normal, 1.0);
outPosition = texture2D( texture1, v2f_texture );
}
[/code]

Results in this:

[img]http://dl.dropbox.com/u/4349589/normal2.jpg[/img]
0

Share this post


Link to post
Share on other sites
Try doing as Ashaman73 says; render a 'plain' normal map on a sphere, map the normals into [0,1] and visualize the result.
0

Share this post


Link to post
Share on other sites
[quote name='Nairou' timestamp='1314801797' post='4855902']
Results in this:

[img]http://dl.dropbox.com/u/4349589/normal2.jpg[/img]
[/quote]

This looks good and correct.
As already said, red=x-axis, the right cube surface normals seems to point in the correct direction.
Green=y-axis, this seems to be correct too when looking at the upper half of the spheres.
Finally blue=z axis, pointing in the screen. This is seems to be correct too, in a deferred shader not all z values are negative , there're always some values which will get positive.
The black colors are just negative values which the videocard clamps to 0, to display them correctly use a mapping from -1..1 to 0..1.
0

Share this post


Link to post
Share on other sites
[quote name='Ashaman73' timestamp='1314857537' post='4856158']
This looks good and correct.
As already said, red=x-axis, the right cube surface normals seems to point in the correct direction.
Green=y-axis, this seems to be correct too when looking at the upper half of the spheres.
Finally blue=z axis, pointing in the screen. This is seems to be correct too, in a deferred shader not all z values are negative , there're always some values which will get positive.
The black colors are just negative values which the videocard clamps to 0, to display them correctly use a mapping from -1..1 to 0..1.
[/quote]

I only just noticed last night that the color differences were due to the blue (z-axis) pointing into the screen rather than outward. I thought the normal values were supposed to point outward from the surface. Is it different for deferred shading? Why do deferred shading tutorials always show the rendered normals to be very blue, the z-axis pointing towards the screen, as they do in regular normal mapping? I've yet to find a tutorial that covers this.

I'm also curious why, with the second version of the vertex shader (remapping 0..1 to -1..1 before transformation), the colors don't blend as well as the original version (remapping after transformation). Green appears very strongly in the upper half of the sphere, then cuts off in the middle. Where as the original screenshot shows the green to be much more blended, like the original normal map texture. I would have assumed this to mean the second version is wrong, since the sphere should have a smooth curve to it. Perhaps my math is still bad somewhere?
0

Share this post


Link to post
Share on other sites
[quote name='Nairou' timestamp='1314889892' post='4856316']
Why do deferred shading tutorials always show the rendered normals to be very blue, the z-axis pointing towards the screen, as they do in regular normal mapping? I've yet to find a tutorial that covers this.
[/quote]


It is just a question of coordinate space. XYZ -> RGB, where positive Z is toward the screen surface. I, for one, use that coordinate space since it seems logical.

Cheers!

0

Share this post


Link to post
Share on other sites
The orientation of the z component of the normals will depend on the handedness of the coordinate system you are usng; looks like you're view-space is left-handed, since +x goes to the right, +y goes up and +z goes into the screen (hence you see very little blue).

As for the colours not "blending as well" - it's because you're not remapping into [0,1] to visualize the normals.
1

Share this post


Link to post
Share on other sites
[quote name='johnchapman' timestamp='1314896885' post='4856373']
The orientation of the z component of the normals will depend on the handedness of the coordinate system you are usng; looks like you're view-space is left-handed, since +x goes to the right, +y goes up and +z goes into the screen (hence you see very little blue).

As for the colours not "blending as well" - it's because you're not remapping into [0,1] to visualize the normals.
[/quote]

Ahh... That makes perfect sense now. Thank you!
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