Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by ashking · Jan 19, 2015 at 07:44 AM · texture2dsetpixelsprocedural texturing

I generated Voronoi data. No idea how to render it.

Right now I'm generating a voronoi graph. (I plotted some random points, did a Delaunay Triangulation, then drew edges between the triangle circumcenters and stored them to a list of voronoi cells.)

The whole graph is a series of float values between (0,0) and (1,1). I can render all the edges using debug lines, as seen here:

alt text

But I realized I have NO CLUE how to render this to a plane in the world, where I fill in the cell using various terrain textures.

Each voronoi cell has its own array of edges. And each edge is a pair of vectors (a and b).

An example voronoi cell might have the following data (procedurally generated):

e[0].a = (0.4, 0.4); e[0].b = (0.5, 0.45);

e[1].a = (0.5, 0.45); e[1].b = (0.48, 0.5);

e[2].a = (0.48, 0.5); e[2].b = (0.43, 0.48);

e[3].a = (0.43, 0.48); e[3].b = (0.38, 0.44);

e[4].a = (0.38, 0.44); e[4].b = (0.4, 0.4);

(e.g.: it's 5 edges that join up to create a closed polygon.)

I originally created a more grid-based tile map. It was too blocky for my tastes, but was more intuitive to render. I set a two dimensional array of "tile codes" for a grid of 100x100 square tiles. I then used those codes to getpixels/setpixels on a texture2D, one tile at a time. (I then applied that texture2D to a mesh.)

The voronoi diagram isn't so straightforward.

I can't figure out how to turn my graph of random floating point values into a texture2D. Since the voronoi polygons aren't uniform, or even square, I don't know the best way to fill in the area between the edges with some kind of texture data. I imagine I'd still use getpixels/setpixels? But don't know how to do it for more irregular shapes, starting from the edge/vector data.

Code would be most helpful. But any advice is appreciated.

voronoidebuglines.png (108.8 kB)
Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Kronnect · Jan 30, 2016 at 04:19 PM 0
Share

I'd recommend taking a look at Terrain Grid System as it seems it does what you're looking for.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by cjdev · Jan 31, 2016 at 12:16 PM

Rendering lines is surprisingly hard. It's possible in a shader but pretty difficult, especially if you've never programmed one before. Although for something that size you might as well stick with the Texture2D and SetPixels. If it were me, I'd make a list of the line segments and compare every pixel to the distance from each nearby segment. To get which line segments are nearby a bounding box could be found around the segment which would give the ability to quickly check every segment for every pixel. Then to find the distance to the line segment I'd use it's line equation Ax + By + C and the formula: abs(Ax +By + C)/sqrt(A^2 + B^2). At that point if aliasing isn't a concern the job's done but if it is then if the pixel is within range of the segment the exact range would be compared to the range of the whole values representing the pixel and the ratio would determine the amount to color it.

That should at least give you some ideas of where to start, good luck.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

getPixel/setPixels or stencil eraser brush 2 Answers

Setpixels leads to a blank texture? 1 Answer

Baking decals into a texture 3 Answers

Setpixels creates gradient texture instead of raw colored pixels 1 Answer

Texture2D SetPixels/Apply changes not permanent. 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges