• 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

OpenGL
Normal mapping? Tangents? Binormals?

38 posts in this topic

I am just starting to get into normal/bump mapping, and am curious what the "current modern method" is for doing normal mapping. I have a lot of older 3D books which make passing references to computing tangents and normals. I currently include normals in my geometry vertex format, but haven't yet seen anything that exports tangents with the geometry.


Aside from not yet knowing anything about tangents (or binormals, or bitangents, ...), I'm also using OpenGL 3.2 and trying to avoid any old deprecated methodologies. I can only assume that tangents are still needed for normal mapping (I haven't read anything to say otherwise), but is it still best to precompute them and add them to the vertex format? Or are they computed as-needed in shaders these days?

What would be a good (modern/shader) reference for learning tangents (if needed) and the basics of normal mapping?
0

Share this post


Link to post
Share on other sites
[quote name='Nairou' timestamp='1314071692' post='4852639']
I am just starting to get into normal/bump mapping, and am curious what the "current modern method" is for doing normal mapping. I have a lot of older 3D books which make passing references to computing tangents and normals. I currently include normals in my geometry vertex format, but haven't yet seen anything that exports tangents with the geometry.


Aside from not yet knowing anything about tangents (or binormals, or bitangents, ...), I'm also using OpenGL 3.2 and trying to avoid any old deprecated methodologies. I can only assume that tangents are still needed for normal mapping (I haven't read anything to say otherwise), but is it still best to precompute them and add them to the vertex format? Or are they computed as-needed in shaders these days?

What would be a good (modern/shader) reference for learning tangents (if needed) and the basics of normal mapping?

[/quote]

Tangents and binormals (/bitangents) are perpendicular vectors that run along the surface of the model that describe the direction that 2 channels of the normalmap point in, for any point on a models surface. They're exported as part of DAE and FBX formats, as well as a few others. You can caclulate them yourself, using the texturecoordinates and vertex positions each vertex per triangle, then average them out ala smooth normals. Of course, because you can do this, you can also generate them in shaders but the cost is usually fairly prohibitive.
0

Share this post


Link to post
Share on other sites
[quote name='Digitalfragment' timestamp='1314072270' post='4852643']
Of course, because you can do this, you can also generate them in shaders but the cost is usually fairly prohibitive.
[/quote]

Ehh, depends on the platform. A bit of extra ALU isn't going to slow down any modern GPU. :P
1

Share this post


Link to post
Share on other sites
[quote name='MJP' timestamp='1314076208' post='4852652']
Ehh, depends on the platform. A bit of extra ALU isn't going to slow down any modern GPU. :P
[/quote]

Haha, this is true. My judgement gets skewed because I'm used to dealing with the RSX.
0

Share this post


Link to post
Share on other sites
Naughty dog proposed a [url="http://jbit.net/~sparky/sfgrad_bump/mm_sfgrad_bump.pdf"]method based on derivative functions[/url] to reconstruct the perturbed normal out of the height map alone. The performance of those functions has been a bit of a pain in the past. Hopefully those are now better performing, but I'm not going to use this for a while considering I know a lot of people still running shader model 2.
0

Share this post


Link to post
Share on other sites
Note that using the derivative instructions to get a screen-space basis results in a severe quality reduction. It's much better to use precomputed per-vertex tangents.

Here are some comparison images. In each one, the region left of the white line uses the derivative instructions as described by the paper above. The region right of the white line uses the conventional method in which tangents are precomputed per-vertex and bitangents are generated in the vertex shader.

[img]http://www.terathon.com/external/Floor1.jpg[/img]

[img]http://www.terathon.com/external/Floor2.jpg[/img]

[img]http://www.terathon.com/external/Floor3.jpg[/img]

[img]http://www.terathon.com/external/Wall1.jpg[/img]

[img]http://www.terathon.com/external/Wall2.jpg[/img]

[img]http://www.terathon.com/external/Wall3.jpg[/img]
1

Share this post


Link to post
Share on other sites
[quote name='Eric Lengyel' timestamp='1314085623' post='4852688']
Note that using the derivative instructions to generate tangents and bitangents results in a severe quality reduction. It's much better to use precomputed per-vertex tangents.

Here are some comparison images. In each one, the region left of the white line uses the derivative instructions as described by the paper above. The region right of the white line uses the conventional method in which tangents are precomputed per-vertex and bitangents are generated in the vertex shader.
[/quote]

I'm sure you know this, but that paper referenced above does not generate tangents and bitangents for normal mapping...methods for doing that in the fragment shader don't produce such terrible results (especially for simple tiled cases like the ones you posted).
0

Share this post


Link to post
Share on other sites
You are definitely going to want to generate the tangents and bitangents, and maybe normals too yourself. Doing it in a vertex shader or geometry shader for instance will only result in per-poly normals. I suppose given a big enough patch size you could calculate accurate per vertex TBNs in a tessellation shader but it will cost you. I have a TriangleMesh class in my engine that I pump in triangles with just vertices and texcoords and from there I calculate a face normal, using that and the texcoord I calculate the face bitangents and binormals. Then you have to go through your TriangleMeshes vertices and for each one you find the surrounding triangles and average the face normals, binormals, and bitangents to get the per vertex values. It's kind of a pain but the results are a big pay off!
0

Share this post


Link to post
Share on other sites
Does anyone have any references on [b]why[/b] tangents and bitangents and such are used in normal mapping?

I understand that tangent space is a plane that sits on a surface perpendicular to the normal, and I see lots of documents that give the math for tangent space and calculating the tangents for a vertex. But I haven't yet found a document which explains why tangents and tangent space is important.

The best article I've found on tangents so far is [url="http://www.terathon.com/code/tangent.html"]this one[/url], but even it assumes that I already want a tangent space and want it aligned a certain way.

I'd really like to understand how normal mapping works, rather than just memorize a set of required steps.
0

Share this post


Link to post
Share on other sites
[quote name='Nairou' timestamp='1314150156' post='4853048']The best article I've found on tangents so far is [url="http://www.terathon.com/code/tangent.html"]this one[/url], but even it assumes that I already want a tangent space and want it aligned a certain way.[/quote]

I wrote that. As Hodgman describes, the tangent frame provides a matrix that allows you to transform light and view directions from object or world space into the local axis-aligned coordinate system of the normal map, or vice-versa. Basically, the tangent and bitangent at each vertex point in the directions that the x and y axes of the normal map point at those locations if you were to pull the texture off of the mesh and project it onto the tangent plane.

Btw, the term [i]binormal[/i] is still used in a lot of places, but it's not correct in the context of normal mapping. The proper term for the direction perpendicular to both the normal and tangent is the [i]bitangent[/i].
2

Share this post


Link to post
Share on other sites
Hodgman:
Awesome explanation! That makes sense, I think I get it now! Thank you!

Eric:
Thanks for the article! I'll have to go back and read it again now that I understand better the purpose of what is going on. :)
0

Share this post


Link to post
Share on other sites
FWIW - Mikkelsen posted a follow up ([url="http://mmikkelsen3d.blogspot.com/"]http://mmikkelsen3d.blogspot.com/[/url]) to that unparametrized bump mapping paper, making use of a precomputed derivative map to increase visual quality.
0

Share this post


Link to post
Share on other sites
[quote name='synulation' timestamp='1314213869' post='4853346']
FWIW - Mikkelsen posted a follow up ([url="http://mmikkelsen3d.blogspot.com/"]http://mmikkelsen3d.blogspot.com/[/url]) to that unparametrized bump mapping paper, making use of a precomputed derivative map to increase visual quality.
[/quote]

These public test results were produced by a member of the blender community Sean Olson

[url="http://jbit.net/~sparky/blender_deriv/compare/"]http://jbit.net/~spa..._deriv/compare/[/url]

At a moderate distance it's difficult to tell the difference between using the listing 2 method in the paper which operates off of
a height map and the method from the blog using a derivative map.
But then up close as you see in these shots you can see the difference. The derivative operator deletes one order of smoothness essentially.
This is why filtering derivatives looks smoother then taking the derivative of the filtered height signal.

However, both listing 2 and the derivative map method from the blog produce results without the aid of vertex level tangent space.
And results are good. Using derivative map vs. the height map is a trade-off between quality during texture magnification and memory budget
and imo is a call that should be made by the artist on a case by case basis.


Blender is using the method from the paper and the blog btw so you can check it out with blender though you'd have to use a build
from graphicall.org or get code from trunk to see the derivative mapping.
It's easy to drop it into your own shader anyway.
The only thing that should be mentioned which I forgot to mention in the paper is that you're supposed
to scale the bump derivatives in listing 2 (and the blog) dBs and dBt by an adjustable user-scale.

Also surf_pos and surf_norm must be in the same space ie. obj/world/view


To anyone out there who doesn't know how to generate derivative maps
there's a freely available tool here --> [url="http://jbit.net/~sparky/makedudv/"]http://jbit.net/~sparky/makedudv/[/url]
which can make them from height maps in virtually any image format.
I recommend using min. 16 bit heights and preferably float32.
Once the derivative map has been made you can compress it
into BC5 (8 bits per texel).

ZBrush can export such float32 height maps and so can blender for those looking for free options.
Mudbox and Blender both allow you to paint bump maps as well in float32
and will show you the lit result as you paint the bumps.
If anyone is feeling adventurous then there's also Cinepaint which was used
on various movie productions such as "Harry Potter and the Philosopher's Stone"
and "The Last Samurai" (and others) to paint HDR textures.

Cheers,

Morten.
0

Share this post


Link to post
Share on other sites
[quote name='synulation' timestamp='1314213869' post='4853346']
FWIW - Mikkelsen posted a follow up ([url="http://mmikkelsen3d.blogspot.com/"]http://mmikkelsen3d.blogspot.com/[/url]) to that unparametrized bump mapping paper, making use of a precomputed derivative map to increase visual quality.
[/quote]
I've implemented this approach using OpenGL and got on 460gtx -11% in comparison with tangent space approach


0

Share this post


Link to post
Share on other sites
[quote name='Digitalfragment' timestamp='1314072270' post='4852643']
Tangents and binormals (/bitangents) are perpendicular vectors....[/quote]

Is that really the case?


The space that is created is usually based on some smoothed normal and this is not perpendicular to the tangent and bitangent. I know there is some orthogonalization formula, but after all the space is not orthogonal, the tangent space matrix need to stretch and shear (in addition to just rotating like an orthogonalized matrix does). So, can someone resolve the mystery I'm stumbled into? Do I miss an important bit or is the orthogonalization mathematically wrong but somehow not visible?




while I'm hijacking this thread anyway, 2nd thing that confuses me, is it really valid to average the tangents matrices on vertices? they usually represent individual spaces for one triangle(-edge) a neighboring triangle might have a completely unrelated space which is even flipped due to UV mirroring or something. I think if the orthogonalization would remove anything but rotation, this could work if you propagate per triangle the flipping bit, but that leads to my first question.




btw. the normal perturbation gave me the same bad results Eric got, in minification I see bad aliaing (especially in specular) and with magnification you notice the linear interpolated heightmaps.
0

Share this post


Link to post
Share on other sites
[quote name='es' timestamp='1314795515' post='4855860']
[quote name='synulation' timestamp='1314213869' post='4853346']
FWIW - Mikkelsen posted a follow up ([url="http://mmikkelsen3d.blogspot.com/"]http://mmikkelsen3d.blogspot.com/[/url]) to that unparametrized bump mapping paper, making use of a precomputed derivative map to increase visual quality.
[/quote]
I've implemented this approach using OpenGL and got on 460gtx -11% in comparison with tangent space approach



[/quote]

Hey es,

Very interesting. Just to clarify could you
please elaborate on what you mean by 11%?
Also could you show your pixel shader? And also are you using same texture format in both cases?

Has anyone else here tried some different configurations?

Cheers,

Morten.
0

Share this post


Link to post
Share on other sites
[quote name='ProfL' timestamp='1314803962' post='4855914']
[quote name='Digitalfragment' timestamp='1314072270' post='4852643']
Tangents and binormals (/bitangents) are perpendicular vectors....[/quote]
Is that really the case?
[/quote]

You're right, its not really the case - it's a generalisation. We have assets here which completely break that rule. The orthonormalisation just makes it easier to conceptualise the individual channels of a normalmap, and how they relate on the surface, especially when generating normalmaps from heightmaps.

For the most part, you want the tangent space orthonormal to make the most out of the normalmap, otherwise your space ends up heavily compressed in one axis.
1

Share this post


Link to post
Share on other sites
[quote name='ProfL' timestamp='1314803962' post='4855914']
while I'm hijacking this thread anyway, 2nd thing that confuses me, is it really valid to average the tangents matrices on vertices? they usually represent individual spaces for one triangle(-edge) a neighboring triangle might have a completely unrelated space which is even flipped due to UV mirroring or something. I think if the orthogonalization would remove anything but rotation, this could work if you propagate per triangle the flipping bit, but that leads to my first question.
[/quote]
Seams in UV mapping, or hard edges for normal smoothing, causes split vertices. In those cases you can't average the tangents for the edge, and the tangent spaces for the neighboring triangles are not continuous.
0

Share this post


Link to post
Share on other sites
[quote name='Ftn' timestamp='1314968619' post='4856709']
[quote name='ProfL' timestamp='1314803962' post='4855914']
while I'm hijacking this thread anyway, 2nd thing that confuses me, is it really valid to average the tangents matrices on vertices? they usually represent individual spaces for one triangle(-edge) a neighboring triangle might have a completely unrelated space which is even flipped due to UV mirroring or something. I think if the orthogonalization would remove anything but rotation, this could work if you propagate per triangle the flipping bit, but that leads to my first question.
[/quote]
Seams in UV mapping, or hard edges for normal smoothing, causes split vertices. In those cases you can't average the tangents for the edge, and the tangent spaces for the neighboring triangles are not continuous.
[/quote]that's kind of obvious :D

I'm talking of course about shared edges/vertices. without orthogonalization you clearly don't have to average the normal, but the tangent and bitangent kinda would need that for smoothing.





@Digitalfragment thank you for confirming my worries, maybe any more takers with opinion? I wonder how you guys are dealing with those issues, obviously no game stores a full tangent matrix per vertex, all seem to run with orthogonalization mostly because the inverse in shader is just a simple transpose, not an expensive full 3x3 inverse (although it could be normalized which would at least save calculating the determinant and the division, I assume).




0

Share this post


Link to post
Share on other sites
[quote name='mmikkelsen' timestamp='1314879714' post='4856252']
Hey es,

Very interesting. Just to clarify could you
please elaborate on what you mean by 11%?
Also could you show your pixel shader? And also are you using same texture format in both cases?

Has anyone else here tried some different configurations?

Cheers,

Morten.
[/quote]

Hi, Morten!

I used the same BC5 textures in both cases. Here are my shaders:

Vertex Shader(derivative maps)
[source lang="cpp"]
layout(location=0) in vec3 Position;
layout(location=1) in vec2 UV;
layout(location=2) in vec3 Normal;

out block {
vec2 vUV;
vec3 vPos;
vec3 vNormal;
vec2 vScaleDuDv;
flat mat3 mNormalsWV;
} Out;

void main() {
Out.vScaleDuDv=mWorldView[gl_InstanceID][3].xy;
Out.mNormalsWV=mat3(cross(mWorldView[gl_InstanceID][1].xyz,mWorldView[gl_InstanceID][2].xyz),
cross(mWorldView[gl_InstanceID][2].xyz,mWorldView[gl_InstanceID][0].xyz),
cross(mWorldView[gl_InstanceID][0].xyz,mWorldView[gl_InstanceID][1].xyz));
Out.vUV=UV;
Out.vNormal=Normal;
Out.vPos=Position;
gl_Position=vec4((vec4(Position,1.0)*mWorldView[gl_InstanceID]).xyz,1.0)*mProjection;
}
[/source]

Fragment Shader(derivative maps)
[source lang="cpp"]
uniform sampler2D texDiffuse;
uniform sampler2D texBump;

in block {
vec2 vUV;
vec3 vPos;
vec3 vNormal;
vec2 vScaleDuDv;
flat mat3 mNormalsWV;
} In;

layout(location=0) out vec4 FragColor;

//------------------------------------------------------------------------------
// mmikkelsen3d.blogspot.com/2011/07/derivative-maps.html
//------------------------------------------------------------------------------
vec3 GetUnNormalizedBumpNormal(in vec2 dBdUV,in vec2 vUV,in vec3 vPos,in vec3 vNormal) {
// chain rule
vec2 vDxUV=dFdx(vUV);
vec2 vDyUV=dFdy(vUV);
float dBs=dot(dBdUV,vDxUV);
float dBt=dot(dBdUV,vDyUV);
vec3 vSigmaS=dFdx(vPos);
vec3 vSigmaT=dFdy(vPos);
vec3 vR1=cross(vSigmaT,vNormal);
vec3 vR2=cross(vNormal,vSigmaS);
float fDet=dot(vSigmaS,vR1);
vec3 vSurfGrad=sign(fDet)*(dBs*vR1+dBt*vR2);
return (abs(fDet)*vNormal-vSurfGrad);
}

void main() {
vec2 vDuDv=In.vScaleDuDv*(texture(texBump,In.vUV).xy*2.0-1.0);
vec3 vBumpNormal=normalize(GetUnNormalizedBumpNormal(vDuDv,In.vUV,In.vPos,normalize(In.vNormal))*In.mNormalsWV)*(gl_FrontFacing ? 1.0:-1.0);
vec4 vDiffuse=texture(texDiffuse,In.vUV);
FragColor=vec4(ToneMapFilmicU2(vSunColor*(max(dot(vSunDirection,vBumpNormal),0.0)+0.01)*vDiffuse.rgb),vDiffuse.a);
}
[/source]

Vertex Shader(tangent space)
[source lang="cpp"]
layout(location=0) in vec3 vPosition;
layout(location=1) in vec2 vUV;
layout(location=2) in vec3 vNormal;
layout(location=3) in vec4 vTangent;

out block {
vec3 vTangent;
vec3 vBiTangent;
vec3 vNormal;
vec2 vUV;
} Out;

void main() {
mat3 mNormalsWV=mat3(cross(mWorldView[gl_InstanceID][1].xyz,mWorldView[gl_InstanceID][2].xyz),
cross(mWorldView[gl_InstanceID][2].xyz,mWorldView[gl_InstanceID][0].xyz),
cross(mWorldView[gl_InstanceID][0].xyz,mWorldView[gl_InstanceID][1].xyz));
Out.vUV=vUV;
Out.vNormal=normalize(vNormal*mNormalsWV);
Out.vTangent=normalize(vTangent.xyz*mNormalsWV);
Out.vBiTangent=normalize(vTangent.w*cross(Out.vNormal,Out.vTangent));
gl_Position=vec4((vec4(vPosition,1.0)*mWorldView[gl_InstanceID]).xyz,1.0)*mProjection;
}
[/source]

Fragment Shader(tangent space)
[source lang="cpp"]
uniform sampler2D texDiffuse;
uniform sampler2D texBump;

in block {
vec3 vTangent;
vec3 vBiTangent;
vec3 vNormal;
vec2 vUV;
} In;

layout(location=0) out vec4 FragColor;

void main() {
vec3 vBump;
vBump.xy=2.0*texture(texBump,In.vUV).xy-1.0;
vBump.z=sqrt(1.0-dot(vBump.xy,vBump.xy));
vec4 vDiffuse=texture(texDiffuse,In.vUV);
vec3 vBumpNormal=normalize(normalize(In.vTangent)*vBump.x+normalize(In.vBiTangent)*vBump.y+normalize(In.vNormal)*vBump.z)*(gl_FrontFacing ? 1.0:-1.0);
FragColor=vec4(ToneMapFilmicU2(vSunColor*(max(dot(vSunDirection,vBumpNormal),0.0)+0.01)*vDiffuse.rgb),vDiffuse.a);
}
[/source]

And here are screenshots with test scene:

Sponza (derivative maps approach, 373 fps)
[url="http://imageshack.us/photo/my-images/37/testdudv.jpg/"]http://imageshack.us...7/testdudv.jpg/[/url]

Sponza (tangent space approach, 419 fps)
[url="http://imageshack.us/photo/my-images/6/testtbn.jpg/"]http://imageshack.us.../6/testtbn.jpg/[/url]

Well, 373.0 fps / 419.0 fps ~ 0.89 -> derivative maps approach is slower than tangent space approach at 11% (in my tests)

Dima.
0

Share this post


Link to post
Share on other sites
[quote name='ProfL' timestamp='1314974241' post='4856757']
[quote name='Ftn' timestamp='1314968619' post='4856709']
[quote name='ProfL' timestamp='1314803962' post='4855914']
while I'm hijacking this thread anyway, 2nd thing that confuses me, is it really valid to average the tangents matrices on vertices? they usually represent individual spaces for one triangle(-edge) a neighboring triangle might have a completely unrelated space which is even flipped due to UV mirroring or something. I think if the orthogonalization would remove anything but rotation, this could work if you propagate per triangle the flipping bit, but that leads to my first question.
[/quote]
Seams in UV mapping, or hard edges for normal smoothing, causes split vertices. In those cases you can't average the tangents for the edge, and the tangent spaces for the neighboring triangles are not continuous.
[/quote]that's kind of obvious :D

I'm talking of course about shared edges/vertices. without orthogonalization you clearly don't have to average the normal, but the tangent and bitangent kinda would need that for smoothing.




@Digitalfragment thank you for confirming my worries, maybe any more takers with opinion? I wonder how you guys are dealing with those issues, obviously no game stores a full tangent matrix per vertex, all seem to run with orthogonalization mostly because the inverse in shader is just a simple transpose, not an expensive full 3x3 inverse (although it could be normalized which would at least save calculating the determinant and the division, I assume).


[/quote]


Some of your questions are discussed here

--> http://wiki.blender.org/index.php/Dev:Shading/Tangent_Space_Normal_Maps

and the rest are thoroughly discussed in the thesis referenced there.
It discusses things like when to average and when to split and also which approximations
are used in games, and why, and how the baker should support these choices to avoid visual errors (not the other way around).





0

Share this post


Link to post
Share on other sites
[quote name='es' timestamp='1314989171' post='4856880']
Hi, Morten!


Well, 373.0 fps / 419.0 fps ~ 0.89 -> derivative maps approach is slower than tangent space approach at 11% (in my tests)

Dima.
[/quote]


Thanks a lot for sharing.

I have a few comments. One observation is that you're applying a transformation in the pixel shader
which shouldn't be there. You should simply be passing in the normal and surface position in the same space to
the interpolators such that no additional transformations are necessary.
In other words take out vScaleDuDv and mNormalsWV entirely. You're needlessly burning up
interpolators. Using fewer interpolators is supposed to be one of the advantages.

Another observation is that I neglected to mention in my paper that you need a bump scale when doing bump mapping.
So you should have a user-defined scalar constant that you scale dBs and dBt by before using them in the perturbation.
For derivative maps you can also apply this scale to dBduv if you want (the sampled derivative).

That being said even if you change this it is quite possible it'll still be a little bit slower on current gen.
However, I believe this method will be faster on coming generations of cards since it replaces interpolators with a little bit of math.

However, even if I am wrong, you have to realize what you get with this method in return. You don't need to store any tangent spaces
in memory or split any vertices. You have the option of using BC4 height maps instead of derivative maps if you're starving for memory.
Finally, it allows you to, easily, bump map synthesized surfaces such as subdiv or even surfaces being subjected to "unconventional deformations (not just skinning)" such as cloth or water (ocean/lakes) without having to recompute tangents at the vertices.

For subdiv alone this method is really extremely convenient compared to traditional normal map baking.
It's not a very good idea to bake using the control mesh as your low poly when you intend to apply it
to a subdiv surface. And it doesn't entirely make sense to use traditional tangent space generation at the vertices of the
full res subdiv surface either. And even if you did you wouldn't be able to, efficiently, generate the same spaces on the gpu.

The other thing I want to point out is your pixel shader is very short. If you compare it to a next gen shader
with possibly fancier lighting models, shadows, rims, high lights etc then the difference in perturbing a normal one way or the other
becomes very marginal relative to the full fps.

Anyway, glad you shared all your results and took the time to give it a shot.

Morten.
0

Share this post


Link to post
Share on other sites
[quote name='mmikkelsen' timestamp='1315056704' post='4857138']
In other words take out vScaleDuDv and mNormalsWV entirely. You're needlessly burning up
interpolators. Using fewer interpolators is supposed to be one of the advantages.

[/quote]

Morten, thanks for the tips!
I would like to say few words about my variables (but my english is not so good and perhaps i didn't understand your words properly). The vScaleDuDv is a user-scale for dBs and dBt and the mNormalsWV is a matrix which apply world-view transformations to normals. The world matrix can has scale factor and there are 2 options for computation of bumped-normal:
1. I can get bumped-normal in object space and then transform it in camera space(there is matrix multiplication in pixel shader).
2. I can get bumped-normal directly in camera space(and all matrix multiplications are made in vertex shader)

These 2 approaches give different results and i had doubts about right way of computation. In the end i chose the first approach.

Naughty Dog rules!
Uncharted rules!

Dima.
0

Share this post


Link to post
Share on other sites
[quote name='es' timestamp='1315084523' post='4857256']


Morten, thanks for the tips!
I would like to say few words about my variables (but my english is not so good and perhaps i didn't understand your words properly). The vScaleDuDv is a user-scale for dBs and dBt and the mNormalsWV is a matrix which apply world-view transformations to normals. The world matrix can has scale factor and there are 2 options for computation of bumped-normal:
1. I can get bumped-normal in object space and then transform it in camera space(there is matrix multiplication in pixel shader).
2. I can get bumped-normal directly in camera space(and all matrix multiplications are made in vertex shader)

These 2 approaches give different results and i had doubts about right way of computation. In the end i chose the first approach.

Naughty Dog rules!
Uncharted rules!

Dima.
[/quote]

Thanks :)

As for the shader I am still having a tough time wrapping my brain around your vScaleDuDv. It looks like you are writing the .xy
of the translation part of your world view to it? The bump scale I had in mind is a single value (1 float) specified either per material, per object or both.

As for the transformation part you are right that if your aim is to perturb in object space while doing lighting in view space then you'd be
stuck doing a transformation in your pixel shader. Furthermore, using instancing as it seems you do you'd end up
passing it to interpolators instead of the matrix being a shader constant.

I would definitely do the perturbation in view-space especially when doing instancing to avoid passing a matrix to the interpolators.
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

  • Similar Content

    • By mapra99
      Hello

      I am working on a recent project and I have been learning how to code in C# using OpenGL libraries for some graphics. I have achieved some quite interesting things using TAO Framework writing in Console Applications, creating a GLUT Window. But my problem now is that I need to incorporate the Graphics in a Windows Form so I can relate the objects that I render with some .NET Controls.

      To deal with this problem, I have seen in some forums that it's better to use OpenTK instead of TAO Framework, so I can use the glControl that OpenTK libraries offer. However, I haven't found complete articles, tutorials or source codes that help using the glControl or that may insert me into de OpenTK functions. Would somebody please share in this forum some links or files where I can find good documentation about this topic? Or may I use another library different of OpenTK?

      Thanks!
    • By Solid_Spy
      Hello, I have been working on SH Irradiance map rendering, and I have been using a GLSL pixel shader to render SH irradiance to 2D irradiance maps for my static objects. I already have it working with 9 3D textures so far for the first 9 SH functions.
      In my GLSL shader, I have to send in 9 SH Coefficient 3D Texures that use RGBA8 as a pixel format. RGB being used for the coefficients for red, green, and blue, and the A for checking if the voxel is in use (for the 3D texture solidification shader to prevent bleeding).
      My problem is, I want to knock this number of textures down to something like 4 or 5. Getting even lower would be a godsend. This is because I eventually plan on adding more SH Coefficient 3D Textures for other parts of the game map (such as inside rooms, as opposed to the outside), to circumvent irradiance probe bleeding between rooms separated by walls. I don't want to reach the 32 texture limit too soon. Also, I figure that it would be a LOT faster.
      Is there a way I could, say, store 2 sets of SH Coefficients for 2 SH functions inside a texture with RGBA16 pixels? If so, how would I extract them from inside GLSL? Let me know if you have any suggestions ^^.
    • By KarimIO
      EDIT: I thought this was restricted to Attribute-Created GL contexts, but it isn't, so I rewrote the post.
      Hey guys, whenever I call SwapBuffers(hDC), I get a crash, and I get a "Too many posts were made to a semaphore." from Windows as I call SwapBuffers. What could be the cause of this?
      Update: No crash occurs if I don't draw, just clear and swap.
      static PIXELFORMATDESCRIPTOR pfd = // pfd Tells Windows How We Want Things To Be { sizeof(PIXELFORMATDESCRIPTOR), // Size Of This Pixel Format Descriptor 1, // Version Number PFD_DRAW_TO_WINDOW | // Format Must Support Window PFD_SUPPORT_OPENGL | // Format Must Support OpenGL PFD_DOUBLEBUFFER, // Must Support Double Buffering PFD_TYPE_RGBA, // Request An RGBA Format 32, // Select Our Color Depth 0, 0, 0, 0, 0, 0, // Color Bits Ignored 0, // No Alpha Buffer 0, // Shift Bit Ignored 0, // No Accumulation Buffer 0, 0, 0, 0, // Accumulation Bits Ignored 24, // 24Bit Z-Buffer (Depth Buffer) 0, // No Stencil Buffer 0, // No Auxiliary Buffer PFD_MAIN_PLANE, // Main Drawing Layer 0, // Reserved 0, 0, 0 // Layer Masks Ignored }; if (!(hDC = GetDC(windowHandle))) return false; unsigned int PixelFormat; if (!(PixelFormat = ChoosePixelFormat(hDC, &pfd))) return false; if (!SetPixelFormat(hDC, PixelFormat, &pfd)) return false; hRC = wglCreateContext(hDC); if (!hRC) { std::cout << "wglCreateContext Failed!\n"; return false; } if (wglMakeCurrent(hDC, hRC) == NULL) { std::cout << "Make Context Current Second Failed!\n"; return false; } ... // OGL Buffer Initialization glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT); glBindVertexArray(vao); glUseProgram(myprogram); glDrawElements(GL_TRIANGLES, indexCount, GL_UNSIGNED_SHORT, (void *)indexStart); SwapBuffers(GetDC(window_handle));  
    • By Tchom
      Hey devs!
       
      I've been working on a OpenGL ES 2.0 android engine and I have begun implementing some simple (point) lighting. I had something fairly simple working, so I tried to get fancy and added color-tinting light. And it works great... with only one or two lights. Any more than that, the application drops about 15 frames per light added (my ideal is at least 4 or 5). I know implementing lighting is expensive, I just didn't think it was that expensive. I'm fairly new to the world of OpenGL and GLSL, so there is a good chance I've written some crappy shader code. If anyone had any feedback or tips on how I can optimize this code, please let me know.
       
      Vertex Shader
      uniform mat4 u_MVPMatrix; uniform mat4 u_MVMatrix; attribute vec4 a_Position; attribute vec3 a_Normal; attribute vec2 a_TexCoordinate; varying vec3 v_Position; varying vec3 v_Normal; varying vec2 v_TexCoordinate; void main() { v_Position = vec3(u_MVMatrix * a_Position); v_TexCoordinate = a_TexCoordinate; v_Normal = vec3(u_MVMatrix * vec4(a_Normal, 0.0)); gl_Position = u_MVPMatrix * a_Position; } Fragment Shader
      precision mediump float; uniform vec4 u_LightPos["+numLights+"]; uniform vec4 u_LightColours["+numLights+"]; uniform float u_LightPower["+numLights+"]; uniform sampler2D u_Texture; varying vec3 v_Position; varying vec3 v_Normal; varying vec2 v_TexCoordinate; void main() { gl_FragColor = (texture2D(u_Texture, v_TexCoordinate)); float diffuse = 0.0; vec4 colourSum = vec4(1.0); for (int i = 0; i < "+numLights+"; i++) { vec3 toPointLight = vec3(u_LightPos[i]); float distance = length(toPointLight - v_Position); vec3 lightVector = normalize(toPointLight - v_Position); float diffuseDiff = 0.0; // The diffuse difference contributed from current light diffuseDiff = max(dot(v_Normal, lightVector), 0.0); diffuseDiff = diffuseDiff * (1.0 / (1.0 + ((1.0-u_LightPower[i])* distance * distance))); //Determine attenuatio diffuse += diffuseDiff; gl_FragColor.rgb *= vec3(1.0) / ((vec3(1.0) + ((vec3(1.0) - vec3(u_LightColours[i]))*diffuseDiff))); //The expensive part } diffuse += 0.1; //Add ambient light gl_FragColor.rgb *= diffuse; } Am I making any rookie mistakes? Or am I just being unrealistic about what I can do? Thanks in advance
    • By yahiko00
      Hi,
      Not sure to post at the right place, if not, please forgive me...
      For a game project I am working on, I would like to implement a 2D starfield as a background.
      I do not want to deal with static tiles, since I plan to slowly animate the starfield. So, I am trying to figure out how to generate a random starfield for the entire map.
      I feel that using a uniform distribution for the stars will not do the trick. Instead I would like something similar to the screenshot below, taken from the game Star Wars: Empire At War (all credits to Lucasfilm, Disney, and so on...).

      Is there someone who could have an idea of a distribution which could result in such a starfield?
      Any insight would be appreciated
  • Popular Now