Hi all,
I’m trying to use posto processing with Single-Pass Stereo Rendering on GearVR and DayDream.
Now using Windows 10 + Unity 2017.2. My mobile device is a Samsung S6.
My post effect consists of two steps:
- RenderWithShader renders the scene with my very-simple shader that draws everything is visible with White color
- Blit operations to perform more complex operations.
Now I’m trying to make work the RenderWithShader operation. First of all: is it allowed to use RenderWithShader with single pass stereo rendering, or is there any issue related to its usage? Here it’s the script code I use:
RenderTexture tempRT1 = new RenderTexture( width, height, depth, format );
[...]
MyCamera.targetTexture = tempRT1;
MyCamera.RenderWithShader( drawSimpleShader, "" );
Graphics.Blit( tempRT1, destination );
I added to my shader all the additional instruction described in Unity - Manual: Single-pass stereo rendering for Android . Here it is the code (anything wrong?):
// Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)'
Shader "ShaderTest/DrawSimple SPSR"
{
Properties {
_MainTex ("Base (RGB)", 2D) = "" {}
}
CGINCLUDE
#include "UnityCG.cginc"
// FOR SINGLE PASS STEREO RENDERING
//sampler2D _MainTex;
UNITY_DECLARE_SCREENSPACE_TEXTURE(_MainTex);
half4 _MainTex_ST;
struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};
struct v2f {
float2 uv : TEXCOORD0;
float4 vertex : SV_POSITION;
UNITY_VERTEX_OUTPUT_STEREO
};
v2f vert( appdata v )
{
v2f o;
// FOR SINGLE PASS STEREO RENDERING
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
o.vertex = UnityObjectToClipPos(v.vertex);
o.uv = TRANSFORM_TEX(v.uv, _MainTex); // v.texcoord.xy;
return o;
}
fixed4 frag(v2f i) : SV_Target
{
// return 1-tex2D(_MainTex, i.uv);
// FOR SINGLE PASS STEREO RENDERING
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(i);
half4 col = tex2D(_MainTex, i.uv);
half val = col.r + col.g + col.b;
return (val > 0) ? 1 : 0;
}
ENDCG
Subshader
{
Pass
{
ZTest Always Cull Off ZWrite Off
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
ENDCG
}
}
}
When I try to play it in my GearVR, I can see only a dark screen with a lighter blinking screen in the upper right corner of my FOV. I expect to see a full-white moving cube, but it is not visible at all.
Any project/graphics/camera/anything-else setting missing or wrong?
Please help.
Thanks