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 LindseyB · Jul 03, 2015 at 01:55 PM · shadershaders

Prevent texture from drawing over itself

I am trying to cover an object with a silhouette which I have working, however, I wanted to try to display a simple image of diagonal lines over the 3D object instead of a solid color. I have this mostly working, but since it's a 3D object I'm converting into 2D the texture is being drawn on the silhouette seemingly twice (on the areas when flattened that overlap) causing my diagonal lines to look like a bunch of diamonds.

I have the following shader (and I figure if I can somehow determine if the coordinate was already drawn on I can fix it):

 Shader "Custom/Silhouette" {
 Properties  {
     _MainTex ("RGBA Texture Image", 2D) = "white" {}
     _Cutoff ("Alpha Cutoff", Float) = 0.5
 }
 
 SubShader { 
     Pass {
         ZTest Greater
         Cull Off
      
         CGPROGRAM
         #pragma fragment frag
         #pragma vertex vert alpha
         #include "UnityCG.cginc"
 
         uniform sampler2D _MainTex; 
         uniform float _Cutoff;
 
         struct v2f {
             float4 pos : SV_POSITION;
             float4 tex : TEXCOORD0;
         };
 
         struct appdata_t {
             float4 vertex : POSITION;
             float4 texcoord : TEXCOORD0;
         };
 
         v2f vert (appdata_t v) {
             v2f o;
             o.pos = mul (UNITY_MATRIX_MVP, v.vertex);
             o.tex = v.texcoord;
             return o;
         }
       
         half4 frag (v2f i) : COLOR {
             float4 textureColor = tex2D(_MainTex, i.tex.xy);
             if (textureColor.a < _Cutoff) {
                 discard;
             }
             return textureColor;
         }
         
         ENDCG 
     }
 }
 
 FallBack "Diffuse"
 }

this is what I have
alt text

Which is close to what I want except I just want the stripes displayed once without any of the weird distortion that is happening here. Biggest problem being that they appear to be drawn on the front and back.

screen-shot-2015-07-03-at-55750-pm.png (100.0 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 Jessespike · Jul 03, 2015 at 09:08 PM 0
Share

I want to say change the Cull Off to Cull Back. But I think I might be misinterpreting what you mean. Can you provide a screenshot?

avatar image LindseyB · Jul 03, 2015 at 10:02 PM 0
Share

I added a screenshot of what I currently have for ya. I'm not sure if I am describing what I want clear enough.

1 Reply

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

Answer by LindseyB · Jul 04, 2015 at 06:36 PM

This isn't so much a solution to the "texture drawing over" problem as much as I figured out a better way to achieve the look that I wanted. Looking at the detail texture in screen space from http://docs.unity3d.com/Manual/SL-SurfaceShaderExamples.html I was able to get the effect I wanted.

Hopefully this helps someone else looking to achieve this sort of effect.

Comment
Add comment · 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

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

2 People are following this question.

avatar image avatar image

Related Questions

How to do an outline shader?,How to do an outline? 0 Answers

Shader Problem 0 Answers

How is _WorldSpaceLightPos0 calculated for a directional light? 0 Answers

shader problem 0 Answers

Curved Screen Post Processing Effect 1 Answer


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