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

Terrain normals messed up, don't know why?

9 posts in this topic

I'm trying to generate normal maps for my chunked terrain at run time but it's not working. The normals for the level 0 chunk seem fine, but when i move closer to the terrain everything gets messed up. I believe some of the normals are being flipped.

Here:
http://youtu.be/ETd0HPRmSoQ

This is how i create my normal. I'm pretty sure the code is correct. (I skip the edges for now..)
[CODE]
for (int z = 1; z < mChunkSamples - 1; z++)
{
for (int x = 1; x < mChunkSamples - 1; x++)
{
D3DXVECTOR3 v0(x, pVertices[x + z*mChunkSamples].y , z);
D3DXVECTOR3 v1(x + 1, pVertices[(x + 1) + z*mChunkSamples].y ,z);

D3DXVECTOR3 v2(x, pVertices[x + (z + 1)*mChunkSamples].y , z + 1);
D3DXVECTOR3 n1 = v1 - v0;
D3DXVECTOR3 n2 = v2 - v0;

D3DXVECTOR3 n;
D3DXVec3Cross(&n, &n2, &n1);
D3DXVec3Normalize(&n, &n);
pNormalmap[x + z*mChunkSamples] = n;
}
}
[/CODE]

And this is how i create the normal map:
[CODE]
D3D11_SUBRESOURCE_DATA data;
data.pSysMem = pNormalmap;
data.SysMemPitch = mChunkSamples * 12;
data.SysMemSlicePitch = 0;

Texture2dConfig config;
config.Width = mChunkSamples;
config.Height = mChunkSamples;
config.Format = DXGI_FORMAT_R32G32B32_FLOAT;
Texture2D* pTexture = mRenderer->CreateTexture2D(config, &data);

ShaderResourceViewConfig r_config;
r_config.Format = DXGI_FORMAT_R32G32B32_FLOAT;
r_config.ViewDimension = D3D10_SRV_DIMENSION_TEXTURE2D;
r_config.Texture2D.MipLevels = 1;
r_config.Texture2D.MostDetailedMip = 0;

pChunk->mNormalMap = mRenderer->CreateShaderResourceView(pTexture, r_config);
[/CODE]

Now i thought that there is a problem with my normal maps, so i did a simple test. I filled the normal map with the vertex positions [x,z] : [-256, 256]
When i rendered, this is what i got:

http://youtu.be/5X5g1BX4ysU

Now why does this happen?

This is what is supposed to happen: (I think since i hardcoded the shader to output the vertex position as colour)

http://youtu.be/x-dng1UD85Y

With that i conclude that the problem is with the normal map itself. I think. I also don't know why the 3rd quadrant is black?

Help me :(
0

Share this post


Link to post
Share on other sites
[quote]
Now i thought that there is a problem with my normal maps, so i did a simple test. I filled the normal map with the vertex positions [x,z] : [-256, 256]
When i rendered, this is what i got:
[/quote]

I think you just replied to your question why the one quadrant is black : negative values positions will clip to 0.

In my opinion your problem is in the texture coordinates. It seems that your normal maps wraps multiple times over the terrain when you get closer. Ie. each patch uses texture coordinates from 0,0 to 1,1. Logically each patch will then fit the whole normal map texture over the terrain patch.

So you'll need to consider the texture coordinates for each terrain patch. You may calculate them in vertex shader quite easily, using the world position for example.

Cheers!
1

Share this post


Link to post
Share on other sites
[quote name='Waaayoff' timestamp='1346173855' post='4974173']
Actually i'm generating one normal map per chunk.
[/quote]

Oh ok ... I see. Your right-bottom chunk seems to be always correct anyway.

Have you tried to place the normals to your vertex structure? That should work as intended.

You could also render your terrain flat by setting the y value 0.0 at the shader (with the normal map) and see what's going on with the normal map.

Cheers! Edited by kauna
1

Share this post


Link to post
Share on other sites
Eventually i'm turning the normal map into a high resolution bump map so i kind of need it to work.
0

Share this post


Link to post
Share on other sites
[quote name='Waaayoff' timestamp='1346174565' post='4974177']
Eventually i'm turning the normal map into a high resolution bump map so i kind of need it to work.
[/quote]

Of course, but sometimes you'll need to step back to see what isn't working correctly.

Have you checked that you set the normal textures correctly for each patch?

Cheers!
1

Share this post


Link to post
Share on other sites
Oh ok. I sent the normals with the vertex and i got the correct results.

Maybe the problem is with the negative values being clipped to 0? Edited by Waaayoff
0

Share this post


Link to post
Share on other sites
[quote name='Waaayoff' timestamp='1346175363' post='4974183']
Oh ok. I sent the normals with the vertex and i got the correct results.

Maybe the problem is with the negative values being clipped to 0?
[/quote]

So, the pieces of code you have shown are working correctly. I don't think that the negative values are issue here. It is just that you can't output negative color value to the screen without it getting clipped to 0.

- I could be mistaken, but it seems to me that all the patches are rendered with the same texture (hard to say, because the terrain is pretty rough), that's why I asked you to render the terrain flat with the textures. You can see pretty easily if the texture is same everywhere. Also, that's why I asked you to verify that you are setting the textures correctly.

- You could also show some shader code.

Cheers! Edited by kauna
2

Share this post


Link to post
Share on other sites
Oh. My. God. Kill. Me. Now.

You were right. I forgot about some debugging code i left in my renderer where i bind the shader parameters only once. Changed that and everything worked. I feel so stupid right now.

Anyway, thank you!!!!!!!!
1

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