- Home /
why create dynamic mesh with shadows ?
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.
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;
}
}
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/...)?
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 ;)
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.
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.
Thank you very much. When I disabled mipmapping it works very well! ^_^
Your answer
Follow this Question
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