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

Per-vertex lighting - Are these ugly lines normal?

10 posts in this topic

I am lighting a patch of terrain per-vertex in webgl, and finding highlights that stand out way too much between some vertices. Is that normal? Does switching to per-pixel lighting magically solve that. If I smooth out the terrain does it go away?

Here is a live example:
[url="http://dl.dropbox.com/u/17165428/terrain/terrain.html"]http://dl.dropbox.co...in/terrain.html[/url]

[img]http://dl.dropbox.com/u/17165428/terrain/example.png[/img]

Separate topic: I am showing the vertex normals to prove they are reasonably sane and they appear to be. I tried to draw lines by drawing triangles where two points are identical, but nothing was displayed at all, so I offset one of the points by a small amount, which is why the lines look like needles. Is that normal? What is the correct way to render lines?

My main issue is that the linear interpretation of the light weighting between vertices just seems ugly. Will interpolating the normals and calculating the light weighting per pixel improve things at all for a directional light?

Here's my glsl:
[CODE]

<script id="shader-fs" type="x-shader/x-fragment">
precision mediump float;

varying vec4 vColor;
varying vec3 vLightWeighting;

void main(void) {
gl_FragColor = vec4(vColor.rgb * vLightWeighting, vColor.a);
}
</script>

<script id="shader-vs" type="x-shader/x-vertex">
attribute vec3 aVertexPosition;
attribute vec3 aVertexNormal;
attribute vec4 aVertexColor;

uniform mat4 uMVMatrix;
uniform mat4 uPMatrix;
uniform mat3 uNMatrix;

uniform vec3 uAmbientColor;

uniform vec3 uLightingDirection;
uniform vec3 uDirectionalColor;

varying vec4 vColor;
varying vec3 vLightWeighting;

void main(void) {
gl_Position = uPMatrix * uMVMatrix * vec4(aVertexPosition, 1.0);
vColor = aVertexColor;

vec3 transformedNormal = uNMatrix * aVertexNormal;
float directionalLightWeighting = max(dot(transformedNormal, uLightingDirection), 0.0);
vLightWeighting = uAmbientColor + uDirectionalColor * directionalLightWeighting;
}
</script>
[/CODE]

I did something similar to this with per-vertex lighting (although using the standard pipeline, not glsl) a few years ago and didn't see these kinds of artifacts:
[url="http://claritydevjournal.blogspot.com/2007/12/clarity-progress-week-11.html"]http://claritydevjou...ss-week-11.html[/url]
[img]http://3.bp.blogspot.com/_z55pSmkRjK8/R2WYGEAzLsI/AAAAAAAABLU/xQuNj2EHArs/s1600/Week11ZoomInSmall.png[/img]
0

Share this post


Link to post
Share on other sites
The lighting pattern/artifact is an unfortunate problem when you have a fixed-repeating grid of lowly tessellated heightmap data. Doing per-pixel lighting does not necessarily help (but can alleviate the issue), since the geometry position and normal data is interpolated across the geometry. As possible solutions, I have heard people choosing randomly the diagonal split direction they chop up the height map quads into two triangles. This makes the pattern a bit more random, and not repeating in an obvious fashion. Another option might be to add a bit of noise to the computed lighting values to de-emphasize the repeating pattern.

When you render a degenerate triangle with at least two of the three coordinates being equal, there's a good chance no pixels will be rasterized. One can either use GL_LINE_LIST or GL_LINE_STRIP to draw lines, or use a pair of triangles to produce quads oriented towards the camera in billboard fashion to make them look like fat lines.
1

Share this post


Link to post
Share on other sites
Once you apply a typical ground texture, it is very difficult to notice.
0

Share this post


Link to post
Share on other sites
clb - thanks for the tips. I switched to GL_LINES for the normal lines. No more silly needles!

I tried per-pixel lighting and confirmed what I suspected - there is no point in per-pixel lighting with a directional light. You need point lighting.
[img]http://dl.dropbox.com/u/17165428/terrain/example2.png[/img]
Live example: [url="http://dl.dropbox.com/u/17165428/terrain/perpixel.html"]http://dl.dropbox.com/u/17165428/terrain/perpixel.html[/url]

In the example image, I dropped out the ambient light and am just using the directional component. You both suggested adding noise to the problem, but I'd like to start from something a little less ugly to begin with. I might try smoothing the normals now that I have a better idea what that actually means.
0

Share this post


Link to post
Share on other sites
[quote name='mg_mchenry' timestamp='1339792572' post='4949650']
there is no point in per-pixel lighting with a directional light. You need point lighting.
[/quote]

There should be a difference if you've implemented it correctly. Remember to renormalize the incoming interpolated normals in the fragment shader.
0

Share this post


Link to post
Share on other sites
I was absolutely sure that I had re-normalized. Until I looked. You're right, it is better and different when the fragment's interpolated normal is re-normalized.

It's still not great. I'll post pictures later. It's better, but it doesn't make nearly as striking an improvement as smoothing the normals. Again, I will post pictures later. Smoothing the normals was the answer I was looking for, I think.
0

Share this post


Link to post
Share on other sites
Splines. Yes. Good answer. :) That blog post is full of interesting information. Thanks for posting, skytiger.

I kept staring at those nasty linear interpolations and thinking there ought to be a better way. It would be pretty cool if you could define a non-linear interpolation between the vertex and fragment shaders or if the fragment shader could be aware of non-interpolated vertex data.

I was surprised the difference it makes even doing a very clumsy smoothing pass on the vertex normals.
0

Share this post


Link to post
Share on other sites
skytiger, a question about how you are interpolating points in your grid:


I would like to use Catmull Rom to subdivide my grid. If I have points defined at each 1.0 unit interval and I want to get the point for x,y = 2.5, 2.5, I could generate values for y=2.5 for x 1 through 4. Then with 4 samples for y=2.5, I could interpolate for x=2.5 on that intermediate spline.

I hope that makes sense, but it's obviously the wrong approach. The subdivision would be more oriented to one axis than the other. I'm having trouble explaining what I mean by that without writing a paragraph about it. Maybe it's good enough, or maybe the math magically works in a way that is not intuitive to me.

I know there are splines you can use on surfaces, but I really like how Catmull Rom passes through the control points.
0

Share this post


Link to post
Share on other sites
"more oriented to one axis than the other" // I don't think it matters, if you switch the primary axis you may get a different result, but it will still be correct ...
also if you use Catmull Rom to calculate normals you will get similar artifacts to Linear Interpolation
that is why I "mix" catmull rom and bspline (technically incorrect but results are fantastic)
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