Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 /
  • Help Room /
avatar image
0
Question by NewHouse9 · Feb 04 at 10:04 AM · scripting problemshaderscoloralpha

While generating Face Objects - What shader to use to get them appear 0.5f alpha?

Been trying find ways to add alpha value 0.333f or so but I have been having problems of many kinds. I wish there was easy way of doing this. Component where this script, part of it is doesn't have renderers or anything like that added - instead created from scratch since the "generation" script that I can use from editor view.

I am not sure what shader to look for that has alpha value - Shader.Find("what path?"); Been having hard times finding any info from which paths these shaders can be found in code.

  GameObject GenerateFaceObject(BSPFace face)
     {
         GameObject faceObject = new GameObject("BSPface");
         faceObject.transform.parent = gameObject.transform;
         Mesh faceMesh = new Mesh();
         faceMesh.name = "BSPmesh";
 
         // grab our verts
         Vector3[] verts = new Vector3[face.num_ledges];
         int edgestep = face.ledge_index;
         for (int i = 0; i < face.num_ledges; i++)
         {
             if (map.edgeLump.ledges[face.ledge_index + i] < 0)
             {
                 verts[i] = map.vertLump.verts[map.edgeLump.edges[Mathf.Abs(map.edgeLump.ledges[edgestep])].vert1];
             }
             else
             {
                 verts[i] = map.vertLump.verts[map.edgeLump.edges[map.edgeLump.ledges[edgestep]].vert2];
             }
             edgestep++;
         }
 
         // whip up tris
         int[] tris = new int[(face.num_ledges - 2) * 3];
         int tristep = 1;
         for (int i = 1; i < verts.Length - 1; i++)
         {
             tris[tristep - 1] = 0;
             tris[tristep] = i;
             tris[tristep + 1] = i + 1;
             tristep += 3;
         }
 
         // whip up uvs
         float scales = map.miptexLump.textures[map.texinfoLump.texinfo[face.texinfo_id].miptex].width * 0.03f;
         float scalet = map.miptexLump.textures[map.texinfoLump.texinfo[face.texinfo_id].miptex].height * 0.03f;
         Vector2[] uvs = new Vector2[face.num_ledges];
         for (int i = 0; i < face.num_ledges; i++)
         {
             uvs[i] = new Vector2((Vector3.Dot(verts[i], map.texinfoLump.texinfo[face.texinfo_id].vec3s) + map.texinfoLump.texinfo[face.texinfo_id].offs) / scales, (Vector3.Dot(verts[i], map.texinfoLump.texinfo[face.texinfo_id].vec3t) + map.texinfoLump.texinfo[face.texinfo_id].offt) / scalet);
         }
 
         faceMesh.vertices = verts;
         faceMesh.triangles = tris;
         faceMesh.uv = uvs;
         faceMesh.RecalculateNormals();
         faceObject.AddComponent<MeshFilter>();
         faceObject.GetComponent<MeshFilter>().mesh = faceMesh;
         faceObject.AddComponent<MeshRenderer>();
 
         // We make a material and then use shared material to work around a leak in the editor
         Material mat;
 
         if (lightMapsEnabled)
         {
             // Lightmap wankery
             mat = new Material(Shader.Find("Legacy Shaders/Lightmapped/Diffuse"));
             int pointer = face.lightmap;
             if (pointer != -1)
             {
                 int size = 10;
                 Texture2D lightmap = new Texture2D(size, size);
 
                 Color[] colors = new Color[size * size];
 
                 for (int i = 0; i < size * size; i++)
                 {
                     if (i >= map.lightLump.RawMaps.Length)
                         break;
                     var temp = map.lightLump.RawMaps[pointer + i];
                     colors[i] = new Color32(temp, temp, temp, 255);
                 }
                 lightmap.SetPixels(colors);
 
                 mat.SetTexture("_LightMap", lightmap);
             } 
         }
         else
         {
             mat = new Material(Shader.Find("Diffuse"));
         }
 
         // Set the texture we made above, after possible lightmapping circlejerk
         mat.mainTexture = map.miptexLump.textures[map.texinfoLump.texinfo[face.texinfo_id].miptex];
         
         /*
         mat.SetOverrideTag("RenderType", "");
         mat.SetInt("_SrcBlend", (int) UnityEngine.Rendering.BlendMode.One);
         mat.SetInt("_DstBlend", (int) UnityEngine.Rendering.BlendMode.Zero);
         mat.SetInt("_ZWrite", 1);
         mat.DisableKeyword("_ALPHATEST_ON");
         mat.DisableKeyword("_ALPHABLEND_ON");
         mat.DisableKeyword("_ALPHAPREMULTIPLY_ON"); 
         mat.renderQueue = -1;
         */
         
         ///*
         mat.SetOverrideTag("RenderType", "Transparent");
         mat.SetInt("_SrcBlend", (int) UnityEngine.Rendering.BlendMode.SrcAlpha);
         mat.SetInt("_DstBlend", (int) UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha);
         mat.SetInt("_ZWrite", 0);
         mat.DisableKeyword("_ALPHATEST_ON");
         mat.EnableKeyword("_ALPHABLEND_ON");
         mat.DisableKeyword("_ALPHAPREMULTIPLY_ON");
         mat.renderQueue = (int) UnityEngine.Rendering.RenderQueue.Transparent;
         //*/
         
         mat.SetColor("_Color", new Color (1f, 1f, 1f, 0.333f));
 
 
         // Set the material
         faceObject.GetComponent<Renderer>().sharedMaterial = mat;
 
         // Turn off the renderer if the face is part of a trigger brush
         string texName = map.miptexLump.textures[map.texinfoLump.texinfo[face.texinfo_id].miptex].name;
         
         if (texName == "trigger")
         {
             faceObject.GetComponent<Renderer>().enabled = false;
         }
 
         // Skip any textures that show a sky, if we want
         if (skipSky && texName.StartsWith("sky"))
             faceObject.GetComponent<Renderer>().enabled = false;
 
         faceObject.AddComponent<MeshCollider>();
         faceObject.isStatic = true;
         
         
         
 
 
         return faceObject;
     }
     #endregion

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

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

299 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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

I need a two Color gradient shader with alpha settings for for the top color. 0 Answers

random color not working 1 Answer

How to generate a random color? 5 Answers

Changing Camera Background Color 1 Answer

Standard way to set RGB color as alpha 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