Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 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
0
Question by Eco-Editor · Feb 05, 2019 at 12:56 PM · shadercghlslwireframeopaque

Why color not rendering in my shader?

Hello all,

I'm trying to create a wireframe shader with inner color. So it's not transparent but has a color. So I have this shader:

 Shader "Custom/TransparentSingleColorShader" {
     Properties{
       _Color("Color", Color) = (1.0, 1.0, 1.0, 1.0)
       [PowerSlider(3.0)]
         _WireframeVal("Wireframe width", Range(0., 0.5)) = 0.05
         _FrontColor("Front color", color) = (1., 1., 1., 1.)
         _BackColor("Back color", color) = (1., 1., 1., 1.)
         [Toggle] _RemoveDiag("Remove diagonals?", Float) = 0.
     }
         SubShader
         {
             Tags { "Queue" = "Geometry" "RenderType" = "Opaque" }
 
             Pass
             {
                 Cull Front
                 CGPROGRAM
                 #pragma vertex vert
                 #pragma fragment frag
                 #pragma geometry geom
 
             // Change "shader_feature" with "pragma_compile" if you want set this keyword from c# code
             #pragma shader_feature __ _REMOVEDIAG_ON
 
             #include "UnityCG.cginc"
 
             struct v2g {
                 float4 worldPos : SV_POSITION;
             };
 
             struct g2f {
                 float4 pos : SV_POSITION;
                 float3 bary : TEXCOORD0;
             };
 
             v2g vert(appdata_base v) {
                 v2g o;
                 o.worldPos = mul(unity_ObjectToWorld, v.vertex);
                 return o;
             }
 
             [maxvertexcount(3)]
             void geom(triangle v2g IN[3], inout TriangleStream<g2f> triStream) {
                 float3 param = float3(0., 0., 0.);
 
                 #if _REMOVEDIAG_ON
                 float EdgeA = length(IN[0].worldPos - IN[1].worldPos);
                 float EdgeB = length(IN[1].worldPos - IN[2].worldPos);
                 float EdgeC = length(IN[2].worldPos - IN[0].worldPos);
 
                 if (EdgeA > EdgeB && EdgeA > EdgeC)
                     param.y = 1.;
                 else if (EdgeB > EdgeC && EdgeB > EdgeA)
                     param.x = 1.;
                 else
                     param.z = 1.;
                 #endif
 
                 g2f o;
                 o.pos = mul(UNITY_MATRIX_VP, IN[0].worldPos);
                 o.bary = float3(1., 0., 0.) + param;
                 triStream.Append(o);
                 o.pos = mul(UNITY_MATRIX_VP, IN[1].worldPos);
                 o.bary = float3(0., 0., 1.) + param;
                 triStream.Append(o);
                 o.pos = mul(UNITY_MATRIX_VP, IN[2].worldPos);
                 o.bary = float3(0., 1., 0.) + param;
                 triStream.Append(o);
             }
 
             float _WireframeVal;
             fixed4 _BackColor;
 
             fixed4 frag(g2f i) : SV_Target {
             if (!any(bool3(i.bary.x < _WireframeVal, i.bary.y < _WireframeVal, i.bary.z < _WireframeVal)))
                  discard;
 
                 return _BackColor;
             }
 
             ENDCG
         }
 
         Pass
         {
             Cull Back
             CGPROGRAM
             #pragma vertex vert
             #pragma fragment frag
             #pragma geometry geom
 
                 // Change "shader_feature" with "pragma_compile" if you want set this keyword from c# code
                 #pragma shader_feature __ _REMOVEDIAG_ON
 
                 #include "UnityCG.cginc"
 
                 struct v2g {
                     float4 worldPos : SV_POSITION;
                 };
 
                 struct g2f {
                     float4 pos : SV_POSITION;
                     float3 bary : TEXCOORD0;
                 };
 
                 v2g vert(appdata_base v) {
                     v2g o;
                     o.worldPos = mul(unity_ObjectToWorld, v.vertex);
                     return o;
                 }
 
                 [maxvertexcount(3)]
                 void geom(triangle v2g IN[3], inout TriangleStream<g2f> triStream) {
                     float3 param = float3(0., 0., 0.);
 
                     #if _REMOVEDIAG_ON
                     float EdgeA = length(IN[0].worldPos - IN[1].worldPos);
                     float EdgeB = length(IN[1].worldPos - IN[2].worldPos);
                     float EdgeC = length(IN[2].worldPos - IN[0].worldPos);
 
                     if (EdgeA > EdgeB && EdgeA > EdgeC)
                         param.y = 1.;
                     else if (EdgeB > EdgeC && EdgeB > EdgeA)
                         param.x = 1.;
                     else
                         param.z = 1.;
                     #endif
 
                     g2f o;
                     o.pos = mul(UNITY_MATRIX_VP, IN[0].worldPos);
                     o.bary = float3(1., 0., 0.) + param;
                     triStream.Append(o);
                     o.pos = mul(UNITY_MATRIX_VP, IN[1].worldPos);
                     o.bary = float3(0., 0., 1.) + param;
                     triStream.Append(o);
                     o.pos = mul(UNITY_MATRIX_VP, IN[2].worldPos);
                     o.bary = float3(0., 1., 0.) + param;
                     triStream.Append(o);
                 }
 
                 float _WireframeVal;
                 fixed4 _FrontColor;
 
                 fixed4 frag(g2f i) : SV_Target {
                 if (!any(bool3(i.bary.x <= _WireframeVal, i.bary.y <= _WireframeVal, i.bary.z <= _WireframeVal)))
                      discard;
 
                     return _FrontColor;
                 }
 
                 ENDCG
             }
         }
         SubShader{
           Tags { "RenderType" = "Transparent" "Queue" = "Transparent" }
           Blend SrcAlpha OneMinusSrcAlpha
           Cull Off
           LOD 200
 
           CGPROGRAM
           #pragma surface surf Lambert
 
           fixed4 _Color;
 
     // Note: pointless texture coordinate. I couldn't get Unity (or Cg)
     //       to accept an empty Input structure or omit the inputs.
     struct Input {
       float2 uv_MainTex;
     };
 
     void surf(Input IN, inout SurfaceOutput o) {
       o.Albedo = _Color.rgb;
       o.Emission = _Color.rgb; // * _Color.a;
       o.Alpha = _Color.a;
     }
     ENDCG
     }
         FallBack "Diffuse"
 }


The first two passes dealing with wireframe and it has two colors. the last subshader is dealing with color that is filing the cube, but it's not working... it's transparent. alt text

colorrenderingissue.png (47.4 kB)
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

160 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

Related Questions

Grabpass refraction masking 0 Answers

Triangulate image in realtime 0 Answers

How to prevent shader optimizations? 1 Answer

ShaderLab on Unity3d Indie 2 Answers

Where Is UNITY_POSITION(pos) Defined? 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