Probably a stupid question...

Started by
4 comments, last by TheChubu 10 years, 11 months ago

Hi! See, I have a regular grid of points for a heightmap, and I want to modify the heights of the points in a radius around an arbitrary point in the grid (sort of like a radial gradient). I cant figure out how to do that without hardcoding each point offset in my code.

Could someone help me with this? I know it should be doable in a few loops but I can't wrap my head around how to do it...

"I AM ZE EMPRAH OPENGL 3.3 THE CORE, I DEMAND FROM THEE ZE SHADERZ AND MATRIXEZ"

My journals: dustArtemis ECS framework and Making a Terrain Generator

Advertisement
I would imagine that each point.z is a function of the radius. As the distance from the mouse cursor increases, height decreases.

Go over the points in your grid, calculate distance from center point of circle to that point. If it's less than the radius of the circle, then do point.z+=(1-distance_away/radius)*height_change to get a gradient

Thanks for the answers. It is necessary to go all over the grid for calculating each single gradient? Since its a heightmap I'd have grids of 512x512 to 4k x 4k, maybe 8k x 8k. I have to calculate a few hundred small gradients (10 to 20 point radius). Seems wasteful.

Hm... You give me an idea... I can define a bounding box from the radius, loop over the points inside those bounds instead of the whole grid, and then calculate the gradient the way you described.

"I AM ZE EMPRAH OPENGL 3.3 THE CORE, I DEMAND FROM THEE ZE SHADERZ AND MATRIXEZ"

My journals: dustArtemis ECS framework and Making a Terrain Generator

Thanks for the answers. It is necessary to go all over the grid for calculating each single gradient? Since its a heightmap I'd have grids of 512x512 to 4k x 4k, maybe 8k x 8k. I have to calculate a few hundred small gradients (10 to 20 point radius). Seems wasteful.

Hm... You give me an idea... I can define a bounding box from the radius, loop over the points inside those bounds instead of the whole grid, and then calculate the gradient the way you described.

Yes that is precisely what I would do.

"In order to understand recursion, you must first understand recursion."
My website dedicated to sorting algorithms

Sweet! Not only worked but its also way shorter than my previous half finished method (90 lines against 30 biggrin.png).

The gradients end in massive black holes since there are still a few things I need to fix, but it looks good. Thanks again!

"I AM ZE EMPRAH OPENGL 3.3 THE CORE, I DEMAND FROM THEE ZE SHADERZ AND MATRIXEZ"

My journals: dustArtemis ECS framework and Making a Terrain Generator

This topic is closed to new replies.

Advertisement