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 CaioRosisca · Dec 10, 2014 at 12:20 PM · shadercg

How to overlay textures without border

I'm trying to make a shader that will print the eye's texture of a character over it's skin texture, my problem is that the eye's texture has a white border around it and I don't know what is causing it. Also the shader receives an rgb value that it will add to the grey areas of the eye to tint it (commented area). I've never tried programming shaders before and I don't really understand how they work.

Here's the code so far:

 Shader "Custom/EyeShaderTest" {
     Properties {
         _SkinTex ("Skin", 2D) = "white" {}
         _EyeTex ("Eye", 2D) = "white" {}
         _EyeColor ("EyeColor", Color) = (.34 , .85, .92, 1)
     }
     SubShader {
         Tags { "RenderType"="Opaque" }
         LOD 200
 
         CGPROGRAM
         #pragma surface surf Lambert
         #pragma target 3.0
 
         sampler2D _SkinTex;
         sampler2D _EyeTex;
         half4 _EyeColor;
 
         struct Input {
             float2 uv_SkinTex;
             float2 uv_EyeTex;
         };
 
         float3 overlayColor(float3 colorA, float4 colorB){
             return (colorA * (1 - colorB.a)) + (colorB.rgb * colorB.a);
         }
 
         void surf (Input IN, inout SurfaceOutput o) {
             half4 skin = tex2D (_SkinTex, IN.uv_SkinTex);
             half4 eye = tex2D (_EyeTex, IN.uv_EyeTex);
 
             //if( (0.2 < eye.g  &&  eye.g  <  0.8) ){
             //  eye.rgb = (_EyeColor.rgb * eye.rgb)*2;
             //}
 
             float3 mix = overlayColor(skin.rgb, eye);
 
             o.Albedo = mix;         
             o.Alpha = 1;
         }
 
         ENDCG
     } 
     FallBack "Diffuse"
 }

guess my overlayColor function isn't working as intended.

This is my eye texture:

alt text

This is the desired result :

alt text

And this is the result I'm getting:

Current result (click here)

screen shot 2014-12-09 at 6.22.44 pm.png (14.6 kB)
screen shot 2014-12-09 at 6.22.38 pm.png (15.9 kB)
Comment
Add comment · Show 2
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 screenname_taken · Dec 10, 2014 at 12:32 PM 0
Share

It could also be the import settings for that texture.

avatar image CaioRosisca · Dec 10, 2014 at 12:41 PM 0
Share

I think it's not the problem, I've tried many different settings, any ideia which one would be ideal?

1 Reply

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

Answer by Paulius-Liekis · Dec 10, 2014 at 01:43 PM

How does RGB channel look of your texture? I'm quite sure there is white (or some kind bright) color around your face features - that's why you're seeing this issue. There are several possible fixes:

  • Disable mipmaps

  • Change color around those features to match color of features (i.e. put black color with 1% opacity around eyebrows). I though Unity does that for your automatically, but that probably depends on settings and you need to have 0% alpha for Unity to "fix" color in those transparent pixels.

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 CaioRosisca · Dec 10, 2014 at 02:30 PM 0
Share

Thanks, I added a black layer with 1% opacity behind the facial features and it solved the problem.

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

27 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

Related Questions

How to force the compilation of a shader in Unity? 5 Answers

Shader: get nearest point light's color, direction and general custom lighting questions 0 Answers

Is there a way to enable shader pass from code? 0 Answers

Multiple Vectors in shader/CGINC 0 Answers

UI shader; get simple UV 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