Jump to content
  • Advertisement
Sign in to follow this  
denisve

Matching pixels on webgl canvas with mesh faces

This topic is 1045 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Edited by denisve

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites

 


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,

Edited by denisve

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites


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.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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

Edited by denisve

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!