- Home /
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:
Can anyone help me understand why page 4 is not getting masked like page 2 is?
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?
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...
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..
Your answer
Follow this Question
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