[HLSL] Optimize HeightMap

Started by
2 comments, last by mika91 14 years, 12 months ago
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
Advertisement
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.
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.
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

This topic is closed to new replies.

Advertisement