Is it possible to use shader graph to make a skybox texture for a VR camera? My attempt works in scene view and game view until I hit play, the game view basically removes the skybox and renders nothing for the skybox. See the images below. Any help would be appreciated!
It should work I would think. The best bet would be to report a bug via Help - > Report a bug
and include a sample project that demonstrates the issue. If you do submit a bug reply here with the issue # so we can take a look at it quicker.
have the same problem. i put a scene together for bugReport , but then found online:
issue #1328062 and probably related #1299691
I found a solution to this for anyone still struggling with it. Export the URP shader to code, and add Zclip False where the other shader render options are. This solved the problem for me.
I found the solution here: HLSL (or ShaderGraph) Skybox Shader with Single Pass Instancing
@TheBlatantOne
Thank you very much! Your solution works.
it’s not as convenient as doing it through shadergraph - leaves some work for the unity team
It seems shader graph has updated itself to now have a few other blockers. Just changing one line in the generated code didn’t work. So I lost interest and just wrote my shader from code.
If you want a super basic code shader that works with URP skyboxes, here’s a sample to use as a starting point:
Shader "Skybox/Minimal"
{
Properties
{
_TopOTheWorld("TopOTheWorld", Color) = (0.3, 0.6, 1, 1)
_Bottom("Bottom", Color) = (0.3,0.3,0.3, 1)
}
SubShader
{
Tags { "Queue"="Background" "RenderType"="Background" "PreviewType"="Skybox" }
Cull Off ZWrite Off
Pass {
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
uniform half3 _TopOTheWorld;
uniform half3 _Bottom;
struct appdata_t
{
float4 vertex : POSITION;
UNITY_VERTEX_INPUT_INSTANCE_ID
};
struct v2f
{
float4 pos : SV_POSITION;
float3 posWS : TEXCOORD0;
};
v2f vert (appdata_t v)
{
v2f OUT;
UNITY_SETUP_INSTANCE_ID(v);
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(OUT);
OUT.pos = UnityObjectToClipPos(v.vertex);
OUT.posWS = mul((float3x3)unity_ObjectToWorld, v.vertex.xyz);
return OUT;
}
half4 frag (v2f IN) : SV_Target
{
float3 normPos = normalize(IN.posWS);
float val = smoothstep(-0.1, 0.2, normPos.y);
half3 col = lerp(_Bottom, _TopOTheWorld, val);
return half4(col,1.0);
}
ENDCG
}
}
}
I try the shader that @gamedevbill post. But have a error when building.
Error building Player: Shader error in 'Skybox/Minimal': invalid subscript 'stereoTargetEyeIndex' at line ## (on gles3)
Just insert the macros that in Unity single-pass custom shader document
Here is the fixed shader:
Shader "Skybox/GradientSkybox"
{
Properties
{
_TopOTheWorld("TopOTheWorld", Color) = (0.3, 0.6, 1, 1)
_Bottom("Bottom", Color) = (0.3,0.3,0.3, 1)
}
SubShader
{
Tags { "Queue"="Background" "RenderType"="Background" "PreviewType"="Skybox" }
Cull Off
ZWrite Off
Pass {
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
uniform half3 _TopOTheWorld;
uniform half3 _Bottom;
struct appdata_t
{
float4 vertex : POSITION;
// https://docs.unity3d.com/2021.3/Documentation/Manual/SinglePassInstancing.html
UNITY_VERTEX_INPUT_INSTANCE_ID
};
struct v2f
{
float4 pos : SV_POSITION;
float3 posWS : TEXCOORD0;
// https://docs.unity3d.com/2021.3/Documentation/Manual/SinglePassInstancing.html
UNITY_VERTEX_OUTPUT_STEREO
};
v2f vert (appdata_t v)
{
v2f OUT;
// https://docs.unity3d.com/2021.3/Documentation/Manual/SinglePassInstancing.html
UNITY_SETUP_INSTANCE_ID(v);
UNITY_INITIALIZE_OUTPUT(v2f, OUT);
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(OUT);
OUT.pos = UnityObjectToClipPos(v.vertex);
OUT.posWS = mul((float3x3)unity_ObjectToWorld, v.vertex.xyz);
return OUT;
}
half4 frag (v2f IN) : SV_Target
{
float3 normPos = normalize(IN.posWS);
float val = smoothstep(-0.1, 0.2, normPos.y);
half3 col = lerp(_Bottom, _TopOTheWorld, val);
return half4(col,1.0);
}
ENDCG
}
}
}