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

Instancing my terrain patches

3 posts in this topic

Hello again! I'm currently rendering my terrain as a bunch of patches. There are different LOD levels of the patch. Each LOD level has it's own index buffer. No vertex buffer is used, the planar position of the vertex is calculated with SV_VertexID and the height is then sampled from a texture. Below is the shader for this:

[code]//======================================================================================//
// Constant buffers //
//======================================================================================//

cbuffer Initial : register(b0) {
int NumCells;
float SliceSize;
}

cbuffer EveryFrame : register(b1) {
matrix World;
matrix View;
matrix Projection;
}


//======================================================================================//
// Input/Output structures //
//======================================================================================//

struct AppToVertex {
uint VertexID : SV_VERTEXID;
};

struct VertexToPixel {
float4 Position : SV_POSITION;
};


//======================================================================================//
// Shader resources //
//======================================================================================//

Texture2D HeightMap : register(t0);


//======================================================================================//
// Samplers //
//======================================================================================//

SamplerState HeightMapSampler : register(s0) {
Filter = MIN_MAG_MIP_LINEAR;
AddressU = CLAMP;
AddressV = CLAMP;
};


//======================================================================================//
// Helper function prototypes //
//======================================================================================//

float2 GetPosition(uint vertexID);
float GetHeight(float2 position);


//======================================================================================//
// Vertex Shader //
//======================================================================================//

VertexToPixel VS(in AppToVertex input) {
VertexToPixel output = (VertexToPixel)0;

// Calculate the location of this vertex
float2 p = GetPosition(input.VertexID);

// Calculate the height of this vertex
float h = GetHeight(p);

// Apply transform
output.Position = float4(p.x, h, p.y, 1);
output.Position = mul(output.Position, World);
output.Position = mul(output.Position, View);
output.Position = mul(output.Position, Projection);

return output;
}


//======================================================================================//
// Helper method for calculating the position of a specific vertex //
//======================================================================================//

float2 GetPosition(uint vertexID) {
int numVerts = NumCells + 1;

float x = (float)(vertexID % numVerts) * (SliceSize / NumCells);
float z = (float)(vertexID / numVerts) * (SliceSize / NumCells);

return float2(x, z);
}


//======================================================================================//
// Helper method for sampling the height map //
//======================================================================================//

float GetHeight(float2 position) {
// Calculate the texture coordinate
float u = position.x / NumCells;
float v = position.y / NumCells;

// Sample the height map
return HeightMap[float2(u, v)].r;
}[/code]

Now, I would like to instance patches that currently have the same LOD level and has the same materials (if that's necessary, better if that's not needed).
I can have a structured buffer that contains data about each patch (patch X location, patch Z location, materials etc) and use SV_InstanceID to fetch it. But my concern is the height map. I tried using a simple array, like so: [code]Texture2D HeightMap[8][/code]
But you cant dynamically index an array using SV_InstanceID like you can do with the structured buffer. So does anyone know how I can do instead? Putting the height map in the structured buffer would be cool, but you can't really do that can you...? Is there any other way, like a texture buffer (is this what tbuffer is for?) or something like that?
Or maybe I can use a separate structured buffer like this:
[code]StructuredBuffer<Texture2D> HeightMaps;[/code]
?

Any ideas are welcome!

Thanks in advance!
0

Share this post


Link to post
Share on other sites
How about using a texture2darray? it can be indexed dynamically.

Best regards! Edited by kauna
1

Share this post


Link to post
Share on other sites
Hmm, yeah I thought a little about that. But they are stored as ONE object in the application, am I right? Like so:
[code] Texture2DDescription texture2DDescription = new Texture2DDescription();
texture2DDescription.ArraySize = 8;[/code]

That means it has to be of dynamic usage and write to before each draw call. Isn't that kind of performance heavy, if I have say an array size of 8 and the height maps would be something like 256 * 256? But maybe it's worth the fact that it's 7 less draw calls if you fill a batch with 8 patches...? Thoughts? :D

Thanks in advance!
0

Share this post


Link to post
Share on other sites
Yes you'll need to fill the textures before drawing, but the point is to fill only the parts which change. Check for toroidal updating.

Also, you may not need 8 levels of textures although you have 8 levels of LODs. Either you pack your heights inside one texture, or
If you don't mind wasting some texture space a you can create bigger texture which contain the height values of several lods.

If I remember correctly, I'm using 2 textures and LOD levels from 8km down to 32 or 64 meters.

Cheers!
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