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 erick_weil · Feb 16, 2014 at 08:27 PM · materialtrianglessubmeshfading

multimaterial mesh, how to smooth fade between the materials?

I is making a game, like minecraft, that allows you to break or place blocks, but, using a Marching Cubes algoritm to create the mesh of the terrain. an a LOT of issues appear because is a Marching procedural mesh. One of this problems is the material asign, if I Have two materials, I need two submeshes, the triangles assign is solved but I dont know how to fade between the materials. A image to exemplificate:

alt text

( if the image not appears see in the bottom of the post, will have a append) how I can Fade this? the code of submesh SetTriangle is below:

 static function definirmateriais (data : float[,,],objeto : GameObject,mesha : Mesh,sub : int) {
 var verts : Vector3[]= mesha.vertices;
 var i : int;
 var tris : int[] = new int[mesha.triangles.Length];
 var C : int;
 var contador : int;
 var qbioma : int;
 // qbioma is a index material of terrain for current biome.
 qbioma = grade3D.qbioma;
 // loop once for all tris
 for(i=0;i<tris.Length/3;i++)
 {
     C=(i*3);
     // now Calculate the center of the triangle
     var centro : Vector3;
     centro = objeto.transform.TransformPoint((verts[mesha.triangles[C]] +verts[mesha.triangles[C+1]] +verts[mesha.triangles[C+2]])/3);
     // verify in the voxel data if in the triangle center position the index refer to material what is being seting the triangles
     if(fazerconta(centro,sub,data,qbioma))
     {
         for(var j=0;j<3;j++)
         tris[contador+j] = mesha.triangles[C+j];
         contador+=3;
     }
 }
 var trismenor : int[] = new int[contador];
 for(i=0;i<contador;i++)
 trismenor[i] = tris[i]; 
 // assign the triangles to the current submesh to color the terrain with this material
 mesha.SetTriangles(trismenor,sub);
 return(mesha);
 }
 
 static function fazerconta (centro : Vector3 , sub : int,data : float[,,],qbioma:int) {
 var booleano : boolean;
 
 // convert the float triangle position in a readable value in the voxel data
 var x : int=Mathf.FloorToInt(centro.x+1.5);
 var y : int=Mathf.FloorToInt(centro.y+0.5);
 var z : int=Mathf.FloorToInt(centro.z+1.5);
 var dat : float = data[x,y,z];
 
 // this if is to correct the issue of the triangles that pertents a air voxel ( 0 or >100) by painting this with the current biome material
 if(sub ==qbioma)
 {
 // verify if is this current material or is air
 if(dat>=sub && dat<=sub+1||dat>100||dat==0)
 booleano = true;
 }
 else
 {
 // verify if is this current material
 if(dat>=sub && dat<=sub+1&&dat!=0)
 booleano = true;
 }
 
 return booleano;
 }


which is the approach needed to correct this issue, an make a nicely fade?

Download of the windows player : http://www.mediafire.com/download/ot6zedf4edcllyb/smoothcraftv003.rar

how to play: WASD walk,

E swicth the block edit offset,

T swicth the block edit scale,

holding SHIFT and clicking the arrow keys, put lines of blocks,

clicking broken blocks,

right-clicking put blocks,

numpad plus or numpad minus change the density of the puting block,

and 1,2,3,4 change the current block .

.

.

.

.

.

any help will be apreacited,

( sorry for the bad english, I am brazilian)

problema.jpg (115.2 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

Answer by MakeCodeNow · Feb 17, 2014 at 02:22 AM

You have two options in this case. One is to render the given tri twice, with the second pass alpha-blending over the first pass with the amount of alpha based on vert colors or whatever else you find convenient.

You can create a new material/shader that internally blends between two materials/textures in the shader, again based on vertex colors or a constant color or whatever works for you. This approach will take less CPU and GPU time than the previous approach, but requires that you be at least a little comfortable with shader programming.

Comment
Add comment · Show 2 · 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 erick_weil · Feb 17, 2014 at 12:49 PM 0
Share

thanks very much for fast reply, I am interested in the second approach, a Shader to fade between two materials using vertex colors aplpha... this looks great,no uses transparency

,I also tried the first approach,but I no have find any shader that mask the transparency using vertex alpha. I need to create this for myself.

so... where I can find a nice shaderlab tutorial? or have you a shader that makes it?

avatar image MakeCodeNow · Feb 17, 2014 at 05:33 PM 1
Share

Probably good to start with surface shaders.

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

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

Related Questions

Do submeshes get sorted properly for transparent materials? 0 Answers

Remove triangle from submesh 0 Answers

Getting material from triangle returns wrong material 0 Answers

How can I ensure Unity does not rearrange the sub-mesh order of a mesh from Maya?,How can I ensure Unity does not rearrange sub-mesh order of a mesh? 0 Answers

Fading multiple objects 0 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