Matching pixels on webgl canvas with mesh faces

Started by
5 comments, last by denisve 8 years, 5 months ago

Basically I have a hexagonal mesh, on XY plane, upon which I draw a pseudo-randomly generated landscape.

gZ2yR.png

Then to decide which face is going to be water and which land, I check for white pixels per face. If white pixels > black pixels, it's land, otherwise water.

The way I do it right now is render the buffer offscreen, and then for each pixel on the canvas, I ray cast to know which face the pixel belongs to, and then sum up all the pixels per face. Problem is... the canvas is 1000x700 pixels, and it takes AGES to raycast 700,000 pixels in JS.

So the question is... is there any faster way to know which face is located at arbitrary (x,y) pixel on the canvas, without having to raycast the entire mesh to death biggrin.png

Advertisement


a pseudo-randomly generated landscape.

When constructing the landscape structure, what would restrict you from storing the information of land type right there, understood onto very face/hex?


a pseudo-randomly generated landscape.

When constructing the landscape structure, what would restrict you from storing the information of land type right there, understood onto very face/hex?

I generate landscape as image, using perlin noise. Also my landscape mesh is non-uniform, since it's sphere surface and the hexagons are also non-uniform size. I'm actually projecting the generated image on mesh UV map, but I can't really interpolate between the image and faces on the mesh, the mesh is too arbitrary, in size, shape, etc,

I'm trying to understand why the raycast step is needed. Can't you just sample the color of the render buffer to know if it is land or not?
My current game project Platform RPG


I'm trying to understand why the raycast step is needed. Can't you just sample the color of the render buffer to know if it is land or not?

Perhaps he needs to somehow extract the face information to assign with it.

I'm trying to understand why the raycast step is needed. Can't you just sample the color of the render buffer to know if it is land or not?

I can, but then I need to know what face that particular pixel belongs to.

I actually found an interesting solution. Find center of each field and translate it to screen coordinates. Then render to a buffer and run a simple flood fill starting at center of field, and restricted by wireframe yellow pixels. That way I can account for every pixel in every face.

But then I ran into this problem -> http://www.gamedev.net/topic/673088-missing-pixels-when-rendering-lines-with-webgl/

angry.png

This topic is closed to new replies.

Advertisement