- Home /
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
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.
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?
I added a screenshot of what I currently have for ya. I'm not sure if I am describing what I want clear enough.
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.
Your answer
Follow this Question
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