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
0
Question by alexanderm006 · Sep 28, 2013 at 01:15 AM · errorproceduraluvuv mapping

Unity procedural mesh generation UV texture flickering horizontal lines

Here's a build: https://dl.dropboxusercontent.com/u/140141632/temp/web.html If you move along the y axis (w/s) you'll notice that you'll see horizontal blue lines flicker in and out.

I'm using this sprite sheet: https://dl.dropboxusercontent.com/u/140141632/temp/spritesheet.png

I think the problem has something to do with the spritesheet because when I change the color of the blue sprites, it changes the color flicker.

Here is my code used for generating the mesh:

'using UnityEngine; using System.Collections;

[RequireComponent(typeof(MeshFilter))] [RequireComponent(typeof(MeshRenderer))] [RequireComponent(typeof(MeshCollider))]

public class Map : MonoBehaviour {

 int width = 50, height = 50;
 float textureWidth = 4, textureHeight = 4;
 
 void Start () {
     BuildMesh();
     GenerateMap();
 }
 
 void Update () {
     
 }
 
 void BuildMesh() {
     Vector3[] vertices = new Vector3[width * height * 4];
     Vector3[] normals = new Vector3[width * height * 4];
     Vector2[] uv = new Vector2[width * height * 4];
     int[] triangles = new int[width * height * 2 * 3];
     
     for(int y=0; y<height; y++) {
         for(int x=0; x<width; x++) {
             int tl = (y * width + x) * 4;
             
             vertices[tl + 0] = new Vector3(x, -y, 0);
             vertices[tl + 1] = new Vector3(x + 1, -y, 0);
             vertices[tl + 2] = new Vector3(x + 1, -y - 1, 0);
             vertices[tl + 3] = new Vector3(x, -y - 1, 0);
             
             uv[tl + 0] = new Vector2(0.0f, 0.25f);
             uv[tl + 1] = new Vector2(0.25f, 0.25f); 
             uv[tl + 2] = new Vector2(0.25f, 0.0f);
             uv[tl + 3] = new Vector2(0.0f, 0.0f);
             
             int tri_start = (y * width + x) * 6;
             
             triangles[tri_start + 0] = tl + 0;
             triangles[tri_start + 1] = tl + 2;
             triangles[tri_start + 2] = tl + 3;
             
             triangles[tri_start + 3] = tl + 0;
             triangles[tri_start + 4] = tl + 1;
             triangles[tri_start + 5] = tl + 2;
         }
     }
     
     for(int i=0; i<width * height * 4; i++) {
         normals[i] = Vector3.forward;    
     }
     
     Mesh mesh = new Mesh();
     mesh.vertices = vertices;
     mesh.normals = normals;
     mesh.triangles = triangles;
     mesh.uv = uv;
     
     MeshFilter mf = GetComponent<MeshFilter>();
     mf.mesh = mesh;
 }
 
 void GenerateMap() {
     float xOff = (float)Random.Range(1, 1000000);
     float yOff = (float)Random.Range(1, 1000000);
     
     // 0 = Black empty thing grass maybe; 1 = forest; 2 = moutain; 3 = water
     int[,] tiles = new int[50,50];
     for(int y=0; y<50; y++) {
         for(int x=0; x<50; x++) {
             tiles[x,y] = 0;
         }
     }
     
     for(int y=0; y<height; y++) {
         for(int x=0; x<width; x++) {
             float noise = Mathf.PerlinNoise(x * 0.2f + xOff, y * 0.2f + yOff);
             if(noise < 0.25f) {
                 tiles[x,y] = 2;
             }
         }
     }
     
     for(int y=0; y<height; y++) {
         for(int x=0; x<width; x++) {
             float noise = Mathf.PerlinNoise(x * 0.15f + xOff, y * 0.15f + yOff);
             if(noise < 0.35f) {
                 tiles[x,y] = 1;
             }
         }
     }
     
     for(int y=0; y<height; y++) {
         for(int x=0; x<width; x++) {
             float noise = Mathf.PerlinNoise(x * 0.08f + xOff, y * 0.08f + yOff);
             if(noise < 0.27f) {
                 tiles[x,y] = 3;
             }
         }
     }
     
     
     for(int y=0; y<50; y++) {
         for(int x=0; x<50; x++) {
             if(tiles[x,y] == 0) {
                 SetTile(x, y, 0, 0);    
             }
             
             else if(tiles[x,y] == 1) {
                 SetTile(x, y, 0, 1);
             }
             
             else if(tiles[x,y] == 2) {
                 SetTile(x, y, 1, 0);    
             }
             
             else if(tiles[x,y] == 3) {
                 SetTile(x, y, 1, 1);    
             }
         }
     }    
 }
 
 void SetTile2(int x, int y) {
     MeshFilter mf = GetComponent<MeshFilter>();
     Vector2[] uv = mf.mesh.uv;
     int tl = (y * width + x) * 4;
     uv[tl + 0] = new Vector2(0.0f, 0.0f);
     uv[tl + 1] = new Vector2(1.0f, 0.0f); 
     uv[tl + 2] = new Vector2(1.0f, 1.0f);
     uv[tl + 3] = new Vector2(0.0f, 1.0f);
 }
 
 void SetTile(int x, int y, float tx, float ty) {
     //Only works for square sprite sheets, no rectangles
     ty = -ty;
     
     MeshFilter mf = GetComponent<MeshFilter>();
     
     Vector2[] uv = mf.mesh.uv;
     int tl = (y * width + x) * 4;
     
     float textureSize = 1f / textureHeight;
     float startX = tx / textureWidth;
     float startY = ty / textureHeight - textureSize;
     
     uv[tl + 0] = new Vector2(startX + 0.0f, startY + textureSize);
     uv[tl + 1] = new Vector2(startX + textureSize, startY + textureSize); 
     uv[tl + 2] = new Vector2(startX + textureSize, startY + 0.0f);
     uv[tl + 3] = new Vector2(startX + 0.0f, startY + 0.0f);
     
     mf.mesh.uv = uv;
 }

}'

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 Fattie · Sep 28, 2013 at 10:03 AM 0
Share

nobody will read that much code and nobody will click to links. using the "image" button post screen shots clearly showing your problem. regarding the code post the few relevant lines - if any

0 Replies

· Add your reply
  • Sort: 

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

16 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

procedural texture uv error 0 Answers

How do we generate a UV mapping data for a complicated mesh? 0 Answers

Automatic UV Mapping for a Cube in C# 1 Answer

Delete Uv2 of a mesh? 1 Answer

Help Uv mapping !!! 1 Answer


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