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 PetterDK · Nov 20, 2012 at 12:43 PM · shadermaskingztest

Is my book not working because of a shader problem?

Hi everybody! I'm currently developing an application where part of it is a virtual book and a pageflip animation. When the user clicks and drags the mouse to the left the page is turned.

I'm having a problem with showing the pages and I really need your help! The setup is branching off this project (specifically what Bérenger Mantoue answered in this thread) and looks like this:

There is a camera for every page. There are other objects such as stencils and masks.

The above mentioned objects are associated with a layer like this:

Object – Layer

  • Page 1 – A

  • Page 2 – B

  • Page 3 – C

  • Page 4 – D

  • Page 5 – E

  • Page 1 – F

  • Mask1 – mLayer

  • Mask2 – mLayer2

  • Mask1's stencil – Stencil

  • Mask2's stencil – Stencil2

  • Page 4's stencil – D

  • Page 6's stencil - F

Each camera has a depth and one or more layers to display:

  • Camera - Layer(s) - Depth

  • Main cam - A - (-1)

  • cam 2 - B, mLayer - 1

  • cam 3 - C, Stencil - 2

  • cam 4 - D, mLayer2 - 0

  • cam 5 - E, Stencil2 - 3

  • cam 6 - F - (-2)

Besides that, each page also has a shader:

Page - Shader

  • Page1 - Pageunlit

  • Page2 - Pageunlit

  • Page3 - Overmask

  • Page4 - Overmask

  • Page5 - Overmask

  • Page6 - Overmask

The role of Mask1 is to uncover page2 so that the 4th page is shown as the 3rd page turns. When the pageturn is done page 3 and page 4 are then fully viewable.

The role of Mask2 is to uncover page4 so that the 6th page is shown as the 5th page turns. When the pageturn is done page 5 and page 6 should be viewable but they are not. For some reason, when I make the second page turn (which should reveal page 5 and 6), page 4 is not masked like page 2 is – even though they have the same setup.

My guess is that this behaviour is caused by the shaders and the way it interprets Ztest, but I can't figure out what is wrong. Here is the code of the shaders:


Overmask.shader:

 Shader "Livre/Over Mask" 
 {
     Properties {
         _Color ("Main Color", Color) = (1,1,1,1)
         _MainTex ("Base (RGB)", 2D) = "white" {}
     }
     
     SubShader {
         Tags { "Queue" = "Geometry-9" }
         Lighting Off
         ZTest GEqual
         LOD 200
     
         CGPROGRAM
         #pragma surface surf Lambert
         
         sampler2D _MainTex;
         fixed4 _Color;
         
         struct Input {
             float2 uv_MainTex;
         };
         
         void surf (Input IN, inout SurfaceOutput o) {
             fixed4 c = tex2D(_MainTex, IN.uv_MainTex) * _Color;
             o.Albedo = c.rgb;
             o.Alpha = c.a;
         }
         ENDCG
     }
     
     Fallback "VertexLit"
 }


PageUnlit.shader:

 Shader "Livre/Page Unlit"
 {
     Properties 
     {
         _Color ("Main Color", Color) = (1,1,1,1)
         _MainTex ("Base (RGB)", 2D) = "white" {}
     }
     SubShader 
     {
         Tags { "RenderType"="Opaque" }
         Lighting Off
         LOD 200
 
         CGPROGRAM
         #pragma surface surf Lambert
 
         sampler2D _MainTex;
         fixed4 _Color;
 
         struct Input {
             float2 uv_MainTex;
         };
 
         void surf (Input IN, inout SurfaceOutput o) {
             fixed4 c = tex2D(_MainTex, IN.uv_MainTex) * _Color;
             o.Albedo = c.rgb;
             o.Alpha = c.a;
         }
         ENDCG
     }
 
     Fallback "VertexLit"
 }

So, what I'm looking for is answers to the following:

  1. Can anyone help me understand why page 4 is not getting masked like page 2 is?

  2. Sub-question: Is the 'ZTest' in the Overmask shader affected by the depth of the camera or Z-value in world coordinates? Or another value that I'm not considering?

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 whydoidoit · Nov 20, 2012 at 01:35 PM 0
Share

Ok I'm not quite getting it - there's a camera for every page, those cameras are rendering to textures?

Not sure why you need more than 4, I would have thought that when page 3/4 become visible you swap them with 1/2 if you are moving forwards or swap 1/2 with 3/4 when you are moving backwards.

It appears that there are only ever 4 pages involved in the transition...

avatar image PetterDK · Nov 20, 2012 at 02:02 PM 0
Share

No, the cameras are not rendering to textures, but ins$$anonymous$$d created at runtime at the same position and rotation as the main camera and all cameras are active all the time.

What is actually drawn and showed to the user is controlled by the camera depth, masks and stencils as described in the post. I realize this is a complex question, so it's hard to get all information in one go..

As for your suggestion of going with 4 pages only - it is possible. It would just require the swap to be done at the exact moment the page turn is being initiated. That might cause some unwanted delay..

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

11 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

Related Questions

Is it possible to use a movie texture as a normal map, or as a mask to hide a texture in a shader? 1 Answer

Shaders: How to ztest against specific layers? 1 Answer

Mask Shader and Shadow 2 Answers

Shader that renders fragment behind 0 Answers

Make stencil shader target materials with same int 'ID' ? 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