Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 szimmermann · Oct 31, 2016 at 01:57 PM · shadersrender texturestencildrawmesh

DrawMesh / Stencil / RendureTexture topic

Hello!

In my slot game I am using DrawMesh calls to render thick win lines like shown in the screenshot. First I am rendering the background of the boxes with stencil write on, then I render the boxes with stencil write on, then I am rendering the lines with stencil testing, so the lines get not rendered where the boxes are. ( see screenshot )

The problem is that I have no control over the z position of the win lines. In the frame debugger they always are rendered at the end of the camera render loop job. The z values in my meshes are ignored. I played around with zwrite on/off in the shaders, different queues but the result will always be the same: my lines will be the last steps render jobs.

I tried to render the winlines into a RenderTexture and display that texture as sprite. That does not work because the RenderTexture does not support stencil operations ( RenderTexture. SupportsStencil returns false for my render texture, and true for main screen )

I want to have other sprites rendered in front of the winlines, but the lines need to rendered by the same camera, because I am using a post effects to blur the screen in some situations when I display overlay windows.

The shader I use for writing to stencil looks like this:

 Shader "Zentronic/Color/MaskStencil" 
 {
      Properties
      {
         [PerRendererData] _Color ("Main Color", Color) = (1,1,1,1)
         _Stencil ("Stencil ID", Float) = 2
     }
     
     SubShader 
     {
         Tags 
         { 
             //"RenderType"      = "Transparent"
             //"Queue"      = "Transparent" 
             "IgnoreProjector" = "True"
             "ForceNoShadowCasting"  = "True"
          }
      
         Pass 
         {
             ZWrite On
               Cull Off
             Lighting Off
             Blend One OneMinusSrcAlpha
             ColorMask 0
                          
             Stencil 
             {
                     Ref [_Stencil]
                     Comp equal
                     Pass decrWrap 
                     Fail keep 
                 }
                
             CGPROGRAM
             
                 #pragma vertex vert_shader
                 #pragma fragment frag_shader
                 #include "UnityCG.cginc"
 
                 fixed4 _Color;
 
                 struct appdata_t 
                 {
                     float4 vertex : POSITION;
                     fixed4 color : COLOR;
                 };
 
                 struct v2f 
                 {
                     float4 vertex : SV_POSITION;
                     fixed4 color : COLOR;
                 };
                   
                 v2f vert_shader (appdata_t v)
                 {
                     v2f o;
                     o.vertex = mul(UNITY_MATRIX_MVP, v.vertex);
                     o.color = v.color;
                     return o;
                 }
                 
                 fixed4 frag_shader (v2f i) : COLOR
                 {
                     i.color.rgb*=i.color.a;
                     return i.color;
                 }
                 
             ENDCG
         }
     }
 }

the other shader that renders the lines looks like so:

 Shader "Zentronic/Color/TestStencil" 
 {
     Properties
      {
         _Stencil ("Stencil ID", Float) = 2
     }
 
     SubShader 
     {
         Tags 
         { 
             "IgnoreProjector"     = "True"
             "ForceNoShadowCasting"  = "True"
          }
      
         Pass 
         {
             Blend One OneMinusSrcAlpha
             ZWrite On
               Cull Off
             Lighting Off
              
             Stencil 
             {
                     Ref [_Stencil]
                     Comp equal
                     Pass keep 
                     Fail keep 
                 }
                
             CGPROGRAM
             
                 #pragma vertex vert
                 #pragma fragment frag
                 #include "UnityCG.cginc"
 
                 struct appdata_t 
                 {
                     float4 vertex : POSITION;
                     fixed4 color : COLOR;
                 };
 
                 struct v2f 
                 {
                     float4 vertex : SV_POSITION;
                     fixed4 color : COLOR;
                 };
                   
                 v2f vert (appdata_t v)
                 {
                     v2f o;
                     o.vertex = mul(UNITY_MATRIX_MVP, v.vertex);
                     o.color = v.color;
                     return o;
                 }
                 
                 fixed4 frag (v2f i) : COLOR
                 {
                     i.color.rgb*=i.color.a;
                      return i.color;
                 }
                 
             ENDCG
         }
     }
 }

So my questions are

1) How can I get control of z ordering of my DrawMesh calls ?

2) Can anyone here figure out how to solve this scenario ( perhaps with MeshFilter / Mesh Renderer ) and point me in the right direction how to implement this.

3) Can anyone figure out a better solution to render those boxes/lines without stencil operations ? ( This would make the render texture aproach possible )

Thank you in advance for your help and thoughts!

[1]: /storage/temp/81238-bildschirmfoto-2016-10-31-um-142016.png

bildschirmfoto-2016-10-31-um-142016.png (474.8 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

60 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

Related Questions

Problem with transparency and stencil shader 1 Answer

Shader that renders pixel with highest alpha value? 0 Answers

Multi-shader Stencil Buffer not working as expected,Multi-shader Stencil not working as expected 0 Answers

Adding a Stencil to Particle Standard Surface shader 0 Answers

Standard Shader Still Visible through Stencil Shader 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