Open elvisish opened 4 years ago
Just saw your message ^^.
Well the shader actually already has an x-offset of "0.5" hardcoded in this line:
float2 uv = float2(0.5+atan2(dir.z, dir.x)/(2*UNITY_PI), _StretchDown+dir.y*(1-_StretchDown));
Note that the value for "U" (the x component in our "uv") goes from 0 to 1 however since we expect our texture to be tilable we can happily go beyond those limits. If you want to add an additional offset. just replace the "0.5" with a variable. Keep in mind that a value of 0 and a value of 1 are essentially the same and corresponds to 0° or 360°. To avoid floating point issues of course the value should be kept between 0 and 1.
About that warning you get I can only say that I have never used the shader for the default skybox but only applied it to custom sky brush meshes. According to this question this warning is only a matter of "tagging" the shader as a skybox shader. Though as mentioned I have never tried this.
Thanks for getting back! I also added the line you suggested uv.x *= 4;
to get the right sort of tiling (I changed it to 3) which probably should also be a variable rather than hard-coded:
` Shader "FX/DoomSky"
{
Properties
{
_MainTex ("Texture", 2D) = "white" {}
_StretchDown ("Stretch", Range(0, 0.5)) = 0
}
SubShader
{
Tags { "RenderType"="Opaque" }
Cull off ZWrite On ZTest Lequal
LOD 100
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
struct appdata
{
float4 vertex : POSITION;
};
struct v2f
{
float3 worldView : TEXCOORD1;
float4 vertex : SV_POSITION;
};
v2f vert (appdata v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.worldView = -WorldSpaceViewDir (v.vertex);
return o;
}
sampler2D _MainTex;
float _StretchDown;
fixed4 frag (v2f i) : SV_Target
{
float3 dir = normalize(i.worldView);
float2 uv = float2(0.5+atan2(dir.z, dir.x)/(2*UNITY_PI), _StretchDown+dir.y*(1-_StretchDown));
uv.x*=3;
fixed4 col = tex2D(_MainTex, uv);
return col;
}
ENDCG
}
}
}`
I need to actually learn a bit more about using variables in shaders, my knowledge is truly awful to be honest!
A couple of years ago, you posted your DoomSky shader on Unity Answers (https://answers.unity.com/questions/1500175/doom-style-billardsprite-skybox-without-perspectiv.html), and I always use it as my default skybox shader, since it has very little cylindrical distortion. I've been trying to figure out how to add a rotation offset to it (like the built-in panoramic shader has) but I've not been able to figure out how exactly. Would it require much reworking to add?
One other question I have, I get an error in Unity "Shader for this material does not support skybox rendering" but it works fine, I just don't know if it matters that I get this error or not.
Thanks again for the amazing shader, it's my go-to every time for skyboxes!