Forum Discussion
Infinite
13 years agoHonored Guest
Custom shaders work in Editor but no always on the Rift?
Hi,
I wonder if anyone can help. I was trying to find a way to overcome the last gen limitation of 4096x4096 texture resolution in Unity and found some code on line for a shader to split up into 4 parts to load in 4x 4096x4096 textures to display 1x 8192x8192 texture resolution. I know some will say why?! that's crazy who needs 8k texture etc but in this case I do.
Code from here - http://www.41post.com/4416/programming/unity3d-using-textures-larger-than-4096x4096
I have the shader working great in the editor and whilst going into Game mode. I can see the giant leap in texture resolution quality but yet again when I build and run on the Rift, the shader breaks. I've that this can happen with allot of custom shaders and I'm not sure why.



I've also had this happen when testing the MattShadow shader from Kragh http://forum.unity3d.com/threads/14438-Matte-Shadow. Fine in Editor and Game but dosn't display correctly on the Rift.
Can anyone help on this?
Thanks,
Lee
I wonder if anyone can help. I was trying to find a way to overcome the last gen limitation of 4096x4096 texture resolution in Unity and found some code on line for a shader to split up into 4 parts to load in 4x 4096x4096 textures to display 1x 8192x8192 texture resolution. I know some will say why?! that's crazy who needs 8k texture etc but in this case I do.
Shader "Custom/4-Part Texture" {
Properties {
_MainTex0 ("Base (RGB)", 2D) = "white" {}
//Added three more textures slots, one for each image
_MainTex1 ("Base (RGB)", 2D) = "white" {}
_MainTex2 ("Base (RGB)", 2D) = "white" {}
_MainTex3 ("Base (RGB)", 2D) = "white" {}
}
SubShader {
Tags { "RenderType"="Opaque" "LightMode" = "Vertex"}
LOD 200
CGPROGRAM
#pragma surface surf Lambert
sampler2D _MainTex0;
//Added three more 2D samplers, one for each additional texture
sampler2D _MainTex1;
sampler2D _MainTex2;
sampler2D _MainTex3;
struct Input {
float2 uv_MainTex0;
};
//this variable stores the current texture coordinates multiplied by 2
float2 dbl_uv_MainTex0;
void surf (Input IN, inout SurfaceOutput o) {
//multiply the current vertex texture coordinate by two
dbl_uv_MainTex0 = IN.uv_MainTex0*2;
//add an offset to the texture coordinates for each of the input textures
half4 c0 = tex2D (_MainTex0, dbl_uv_MainTex0 - float2(0.0, 1.0));
half4 c1 = tex2D (_MainTex1, dbl_uv_MainTex0 - float2(1.0, 1.0));
half4 c2 = tex2D (_MainTex2, dbl_uv_MainTex0);
half4 c3 = tex2D (_MainTex3, dbl_uv_MainTex0 - float2(1.0, 0.0));
//this if statement assures that the input textures won't overlap
if(IN.uv_MainTex0.x >= 0.5)
{
if(IN.uv_MainTex0.y <= 0.5)
{
c0.rgb = c1.rgb = c2.rgb = 0;
}
else
{
c0.rgb = c2.rgb = c3.rgb = 0;
}
}
else
{
if(IN.uv_MainTex0.y <= 0.5)
{
c0.rgb = c1.rgb = c3.rgb = 0;
}
else
{
c1.rgb = c2.rgb = c3.rgb = 0;
}
}
//sum the colors and the alpha, passing them to the Output Surface 'o'
o.Albedo = c0.rgb + c1.rgb + c2.rgb + c3.rgb;
o.Alpha = c0.a + c1.a + c2.a + c3.a ;
}
ENDCG
}
FallBack "Diffuse"
} Code from here - http://www.41post.com/4416/programming/unity3d-using-textures-larger-than-4096x4096
I have the shader working great in the editor and whilst going into Game mode. I can see the giant leap in texture resolution quality but yet again when I build and run on the Rift, the shader breaks. I've that this can happen with allot of custom shaders and I'm not sure why.



I've also had this happen when testing the MattShadow shader from Kragh http://forum.unity3d.com/threads/14438-Matte-Shadow. Fine in Editor and Game but dosn't display correctly on the Rift.
Can anyone help on this?
Thanks,
Lee
3 Replies
Replies have been turned off for this discussion
- drashHeroic ExplorerI think there's something off with that shader you're using. I get the same behavior, kinda sorta works in Editor (Rift view or not), but doesn't work in a build. Was thinking DirectX or shader model issue, but then I tried out the optimized version that was posted in the comments of your first link (and cleaned up the formatting a little), and this one works great for me without having to anything else special:
Shader "Custom/4-Part Diffuse"
{
Properties
{
_MainTex0 ("UpperLeft (RGB)", 2D) = "white" {}
_MainTex1 ("UpperRight (RGB)", 2D) = "white" {}
_MainTex2 ("LowerLeft (RGB)", 2D) = "white" {}
_MainTex3 ("LowerRight (RGB)", 2D) = "white" {}
}
SubShader
{
Tags { "RenderType"="Opaque" }
LOD 200
CGPROGRAM
#pragma surface surf Lambert
sampler2D _MainTex0;
sampler2D _MainTex1;
sampler2D _MainTex2;
sampler2D _MainTex3;
struct Input {
float2 uv_MainTex0;
};
float2 dbl_uv_MainTex0;
void surf (Input IN, inout SurfaceOutput o)
{
dbl_uv_MainTex0 = IN.uv_MainTex0*2;
half4 c;
if(IN.uv_MainTex0.x >= 0.5)
{
if(IN.uv_MainTex0.y <= 0.5)
{
c = tex2D (_MainTex3, dbl_uv_MainTex0 - float2(1.0, 0.0));
}
else
{
c = tex2D (_MainTex1, dbl_uv_MainTex0 - float2(1.0, 1.0));
}
}
else
{
if(IN.uv_MainTex0.y <= 0.5)
{
c = tex2D (_MainTex2, dbl_uv_MainTex0);
}
else
{
c = tex2D (_MainTex0, dbl_uv_MainTex0 - float2(0.0, 1.0));
}
}
o.Albedo = c.rgb;
o.Alpha = c.a ;
}
ENDCG
}
FallBack "Diffuse"
}
Hope this helps! Not sure how you're going to integrate this into the Marmoset shaders but hopefully not too much of a stretch. - InfiniteHonored Guest
"drash" wrote:
I think there's something off with that shader you're using. I get the same behavior, kinda sorta works in Editor (Rift view or not), but doesn't work in a build. Was thinking DirectX or shader model issue, but then I tried out the optimized version that was posted in the comments of your first link (and cleaned up the formatting a little), and this one works great for me without having to anything else special:
Hope this helps! Not sure how you're going to integrate this into the Marmoset shaders but hopefully not too much of a stretch.
Nice one drash! very cool. Thanks I will give that a go. I was planning to use this shader just for viewing flat shaded scans. Ideally this shader needs to be flat lit or 100% self illuminated, no lighting.
Being able to merge somehow with Marmoset shader would be very cool indeed. For all 3 slots, Colour, Normals and Specular. No idea how to do that though.
The other option is to split the mesh into 4 parts, with 4 UV's but that's a pain to do in comparison to this technique. - InfiniteHonored GuestIt seems this ""LightMode" = "Vertex"" was causing the error. Drash, do you know if it's possible to convert the shader to be self illuminated.
I'm also wondering if anyone else has notice that the shadows are different for each eye? when using Directional Lights. One shadow is darker on one eye than the other.
Quick Links
- Horizon Developer Support
- Quest User Forums
- Troubleshooting Forum for problems with a game or app
- Quest Support for problems with your device
Other Meta Support
Related Content
- 10 months ago
- 7 months ago
- 10 months ago
- 10 months ago