Skip to main content
gamedev.net
🔒 Locked

[HLSL] Optimize HeightMap

Started by mika91 2 replies 1.6k views
Original Post
mika91
mika91
Hi, My scientifical software use Direct3D and Shaders for large heightmap rendering (512x512). It's working great, but I'd like to optimize memory footprint. X and Y coordinates can easily be computed from vertex position in VertexBuffer. So only Z coordinates are pertinant and should be stored in tables and buffers. My VS function should be like this: struct VertexToPixel { float4 Position : POSITION; float4 Color : COLOR0; }; VertexToPixel VS( float inZ : PSIZE ) { VertexToPixel Output = (VertexToPixel)0; float4x4 preMatrix = mul(xWorldMatrix,xViewProjectionMatrix); float4 inPos; inPos.x = VERTEX_POSITION % xWidth; inPos.y = VERTEX_POSITION / xWidth; inPos.z = inZ; Output.Position = mul(inPos, preMatrix); Output.Color.r = inPos.x / xWidth; Output.Color.g = inPos.y / xHeight; Output.Color.b = 1; return Output; } So there is a way to get vertex indice in the VertexBuffer ? Or someone haa any idea to improve ? Thanks, Mickael
Adam_42
Adam_42
What you probably want is to create one vertex buffer containing only x and y coordinates. This buffer never changes.

You then create a second vertex buffer with your height data, and set that as a separate vertex stream.
FeverGames
FeverGames
Another idea is to use the heightmaps for texture fetching in the Vertex Shader (VS3+)and use 1 vertex buffer grid of 256x256 for example, and use shader parameters to offset the positions to actual world data.
mika91
mika91
Quote:

What you probably want is to create one vertex buffer containing only x and y coordinates. This buffer never changes.

You then create a second vertex buffer with your height data, and set that as a separate vertex stream.


It's a pretty good compromise.
I will try it.

Quote:

Another idea is to use the heightmaps for texture fetching in the Vertex Shader (VS3+)and use 1 vertex buffer grid of 256x256 for example, and use shader parameters to offset the positions to actual world data.


I don't understand this solution, sorry :s

Thanks

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.