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 noahzao · Nov 16, 2013 at 01:10 PM · meshmeshcollidermeshrendereruvmapping

why create dynamic mesh with shadows ?

alt text

When i create mesh and uvmap with script, there is some shadows when playing game. But if i use a plane and textured it , it works great.

alt text

How can i create mesh with no shadows?

Here is the code blew:

 using System;
 using System.Collections.Generic;
 using UnityEngine;
 
 public enum Blocks : byte
 {
     Dirt=0,
     Stone = 1,
     coal_ore = 2,
     iron_ore = 3,
     gold_ore = 4,
     Air = 255
 }
 
 public class Main : MonoBehaviour {
         
     public WorldMain worldMain;
     
     public bool isPause = false;
         
     public Texture2D[] worldTextures;
         
     List<Vector3> vectices = new List<Vector3>();
     List<Vector2> uvs = new List<Vector2>();
     List<int> triangles = new List<int>();
     int drawRectIndex = 0;
     
     private Chunk m_chunk;
     
     void Start()
     {        
         worldMain = new WorldMain( this );
         worldMain.init();
         
         System.Random ra = new System.Random();
         
         int areaSize = 32;
                 
         for( int i=-areaSize;i<areaSize;i++)
         {
             for( int j=-areaSize;j<areaSize;j++)
             {    
                 drawRect( i , 0 , j , (int)ra.Next( 0 , 5 ) );    
             }    
         }
         
         renderDraw();
     }
                 
     void drawRect( float x , float y , float z , int blockType )
     {
         vectices.Add( new Vector3( x, y , z ));
         vectices.Add( new Vector3( x, y , z + 1 ));
         vectices.Add( new Vector3( x + 1, y , z ));
         vectices.Add( new Vector3( x + 1, y , z + 1 ));
         
         BlockUVCoordinates blockUV;
         worldMain.m_BlockUVCoordinates.TryGetValue( blockType , out blockUV);
         
         float u = (float)blockUV.data[ (int)BlockFace.Top ].x;
         float v = (float)blockUV.data[ (int)BlockFace.Top ].y;
         float w = (float)blockUV.data[ (int)BlockFace.Top ].width;
         float h = (float)blockUV.data[ (int)BlockFace.Top ].height;
         
         uvs.Add( new Vector2( u, v ));
         uvs.Add( new Vector2( u, v + h ));
         uvs.Add( new Vector2( u + w, v ));
         uvs.Add( new Vector2( u + w, v + h ));
         
         triangles.Add( drawRectIndex + 0 );
         triangles.Add( drawRectIndex + 1 );
         triangles.Add( drawRectIndex + 2 );
         triangles.Add( drawRectIndex + 3 );
         triangles.Add( drawRectIndex + 2 );
         triangles.Add( drawRectIndex + 1 );
         drawRectIndex += 4;
         
     }        
   
     void renderDraw ()
     {
         GameObject world = GameObject.Find( "world" );
         
         MeshRenderer meshRenderer = (MeshRenderer)world.GetComponent<MeshRenderer>();
         MeshFilter meshFilter = (MeshFilter)world.GetComponent<MeshFilter>();
         MeshCollider meshCollider = (MeshCollider)world.GetComponent<MeshCollider>();
         Mesh mesh = meshFilter.mesh;
         
         meshRenderer.material.mainTexture = worldMain.WorldTextureAtlas;
             
         mesh.vertices = vectices.ToArray();
         mesh.uv = uvs.ToArray();
         mesh.triangles = triangles.ToArray();
         mesh.RecalculateNormals();
         
         meshCollider.sharedMesh = mesh;
     }
 }
 


qq截图20131116204516.jpg (208.5 kB)
qq图片20131116205536.jpg (55.9 kB)
Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Bunny83 · Nov 16, 2013 at 01:22 PM

I'm not sure what exactly you mean, but i guess you mean the black area in the distance?

Well that's not a shadow. Is it possible that you have anisotropic filtering enabled on your texture? That's the only thing that come to my mind. Without more information on

  • what shader you use

  • what texture import settings you use

  • how the texture atlas looks like

We can't say much about that. Does the black area change when you move around or move up?

As far as i can tell your code looks correct. You should play with the settings and see if something changes. btw do you have a pro license? Just asking since "true" shadows are a pro feature.

pps: What's your target platform (windows/linux/mac/iOS/Android/web/...)?

Comment
Add comment · Show 4 · 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
avatar image Bunny83 · Nov 16, 2013 at 01:29 PM 0
Share

btw you have a very strange way to build quads... First i thought your indices are wrong, but you've swapped the last two vertices of each quad.

I recently made a Tesseract simulation, if i would have wrapped all 24 faces this way i guess i would go insane ;)

avatar image noahzao · Nov 17, 2013 at 07:34 AM 0
Share

Thx for your help, and I found something else.

I use Diffuse shader, and each texture is setting with advanced , Filter $$anonymous$$ode=Point, Aniso level=1 And the black area change when I move around or move up. I haven't pro license. $$anonymous$$y target platform is windows and web.

The actually problem is how can i create something look like tiled map. So I use double vertices and uvs to create each quad with a different part of one textureatlas.

Is the unity3d limited the counts of uv when game running?

$$anonymous$$y goal is to made a demo and base world system look like the $$anonymous$$ecraft. I have found some demo sources but they're not working well.

I uploaded the texture atlas when game running. alt text

alt text

qq图片20131117152454.jpg (83.0 kB)
qq图片20131117152854.jpg (253.3 kB)
avatar image Bunny83 · Nov 17, 2013 at 03:42 PM 0
Share

@noahzao:

As i thought ;) The black area is the black area in your texture, try change the color to red for example. Anisotropic filtering is a special kind of mipmapping which will create several versions of your texture in memory. When sampling the texture at a narrow angle the distorted texture version is used to compensate the typical blurry look of mipmapping. However for a tiled atlas, mipmapping and/or anisotropic filtering makes no sense since it will apply to your whole texture, so the tiles will be "mixed". You have to disable mipmapping and anisotropic filtering.

avatar image noahzao · Nov 17, 2013 at 04:01 PM 0
Share

Thank you very much. When I disabled mipmapping it works very well! ^_^

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

18 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 avatar image avatar image

Related Questions

combining meshes 0 Answers

Can you manually set the layer order for triangles inside a mesh? 2 Answers

Why The shareMesh isn't full load when i load a prefab with SkinnedMeshRenderer in unity? 1 Answer

Smoothing collisions with MeshColliders 0 Answers

Generate a highpoly sphere with mesh collider procedurally 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