Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 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 /
avatar image
1
Question by hobwell · Sep 28, 2015 at 10:16 PM · shadertexturematerialshadow

Why does my opaque texture seem to be transparent?

I'm having a strange issue where I have set all objects to use a standard opaque material (with their own textures) but when two objects are overlapping, they appear to be transparent. That is, the two textures are simultaneously visible and seem to be combined.

This is the material in question (the texture is applied in code):

alt text

Below are 2 overlapping objects with the same texture. The darker diamond shape is where there is NO overlap. The 'brighter' areas are where the two objects overlap. I don't know if it matters, but the objects are custom meshes (rather than sprites).

alt text

My question is, how can I make the textures fully opaque (such that you would not see the diamond)? I tried changing the shader to various other values, but doing so caused the shadows cast and received by the objects to disappear.

UPDATE 1

Here is the function which constructs the object mesh (note that texture and material are set prior to this call. texture is of type Texture2D ):

     override public void Construct() {
         mesh.Clear();
         float halfHeight = Mathf.Sqrt (0.75f);
         Vector3[] Vertices = {
             new Vector3( 0f,    0f,         0f),//Z //FRONT
             new Vector3( 1f,    0f,         0f),//A
             new Vector3( 0.5f, -halfHeight, 0f),//B
             new Vector3(-0.5f, -halfHeight, 0f),//C
             new Vector3(-1f,    0f,         0f),//D
             new Vector3(-0.5f,  halfHeight, 0f),//E
             new Vector3( 0.5f,  halfHeight, 0f),//F
             new Vector3( 0f,    0f,         0f),//Z //BACK
             new Vector3( 1f,    0f,         0f),//A
             new Vector3( 0.5f, -halfHeight, 0f),//B
             new Vector3(-0.5f, -halfHeight, 0f),//C
             new Vector3(-1f,    0f,         0f),//D
             new Vector3(-0.5f,  halfHeight, 0f),//E
             new Vector3( 0.5f,  halfHeight, 0f) //F
         };
 
 
         Vector2 scale = new Vector2 (0.5f, 0.5f);
         
         float unitWidth = scale.x;
         float unitHeight = scale.y;// * Mathf.Sqrt (0.75f);
         float unitHalfWidth = scale.x * 0.5f;
         Vector2 FZ = new Vector2 (offset.x, offset.y);
         Vector2 FA = new Vector2 (offset.x + unitWidth, offset.y);
         Vector2 FB = new Vector2 (offset.x + unitHalfWidth, offset.y - unitHeight);
         Vector2 FC = new Vector2 (offset.x - unitHalfWidth, offset.y - unitHeight);
         Vector2 FD = new Vector2 (offset.x - unitWidth, offset.y);
         Vector2 FE = new Vector2 (offset.x - unitHalfWidth, offset.y + unitHeight);
         Vector2 FF = new Vector2 (offset.x + unitHalfWidth, offset.y + unitHeight);
 
         Vector2[] UV = {
             FZ, FA, FB, FC, FD, FE, FF,
             FZ, FA, FB, FC, FD, FE, FF
         };
 
 
         int[] Triangles = {
             0,1,2,0,2,3,0,3,4,0,4,5,0,5,6,0,6,1,
             7,9,8,7,10,9,7,11,10,7,12,11,7,13,12,7,8,13
         };
 
         Vector3[] Normals = new Vector3[14];
         for (int i=0; i<=14; i+=3) {
             Vector3 left = Vertices[Triangles[i+1]] - Vertices[Triangles[i]];
             Vector3 right = Vertices[Triangles[i+2]] - Vertices[Triangles[i]];
             Normals[i] = Vector3.Cross(left, right);
         }
 
         GetComponent<MeshFilter>().mesh = mesh;
         mesh.vertices = Vertices;
         mesh.uv = UV;
         mesh.normals = Normals;
         mesh.triangles = Triangles;
 
         MeshFilter filter = GetComponent<MeshFilter>();
         filter.mesh = mesh;
 
         mesh.RecalculateBounds ();
         mesh.RecalculateNormals ();
         mesh.Optimize ();
 
         MeshCollider mc = gameObject.GetComponent<MeshCollider> ();
         mc.sharedMesh = mesh;
         
         GetComponent<Renderer>().material = material;
         GetComponent<Renderer>().material.SetTexture ("_MainTex", texture);
 
     }

UPDATE 2

I checked and the material.color is set to RGBA(1.0,1.0,1.0,1.0) which makes this even more baffling.

Could lighting be causing this issue?

screen-shot-2015-06-19-at-34307-pm.png (41.4 kB)
screen-shot-2015-06-19-at-35711-pm.png (57.2 kB)
Comment
Add comment · Show 4
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 Calum1015 · Jun 20, 2015 at 03:12 AM 0
Share

I believe you would have to use sprites for this to work.

avatar image hobwell Calum1015 · Sep 28, 2015 at 07:23 PM 0
Share

Why would that be? Should an opaque texture on a 3D mesh be transparent?

avatar image cjdev · Sep 28, 2015 at 08:20 PM 0
Share

Have you tried mesh.RecalculateNormals() already?

avatar image hobwell cjdev · Sep 28, 2015 at 08:58 PM 0
Share

It gets called right after I set all the vertices/normals/triangles/uv, is there somewhere else I should be doing it? I'll update the question with the initializer.

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by $$anonymous$$ · Sep 28, 2015 at 07:52 PM

Opaque allows transparency. You can control it by applying alpha values in a picture editor.

Comment
Add comment · Show 1 · 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 hobwell · Sep 28, 2015 at 09:31 PM 0
Share

The texture files are already fully opaque, I'm not sure that editing the texture file will help. This was helpful though, as until now I didn't understand that opaque would allow transparency.

avatar image
0

Answer by Teadaddy · Sep 28, 2015 at 07:29 PM

do the textures (.png?.tif?) have variable opacity?

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 hobwell · Sep 28, 2015 at 09:26 PM 0
Share

I'm not sure what you mean. The textures are png files, but they are fully opaque when I open them in GI$$anonymous$$P.

avatar image Teadaddy hobwell · Sep 29, 2015 at 02:27 AM 0
Share

one other thing to check is on import, it may be that you have use alpha from grayscale as transparency - if you look at the texture in the project view that option is found in the inspector. Just a thought, good luck

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Cutout Material is not showing texture transparency? 0 Answers

Blending between arbitrary numbers of textures on the same material 0 Answers

Shader Shadow Effect Issues 0 Answers

CRT/LCD screen shader (for materials) 4 Answers

White dots between two cubes? 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