- Home /
Making a shader for an inside out sphere unlit?
I found a code on the forum that allows for a texture on the inside of a sphere, which is perfect for me. Though, I need it to be unlit, have a Color field, along with transparent (fade) to work, but have very little knowledge on working with shaders. Any good recommendations on where to learn more about shaders? Here's the code:
Shader "Flip Normals" {
Properties {
_MainTex ("Base (RGB)", 2D) = "white" {}
}
SubShader {
Tags { "RenderType" = "Opaque" }
Cull Front
CGPROGRAM
#pragma surface surf Lambert vertex:vert
sampler2D _MainTex;
struct Input {
float2 uv_MainTex;
float4 color : COLOR;
};
void vert(inout appdata_full v)
{
v.normal.xyz = v.normal * -1;
}
void surf (Input IN, inout SurfaceOutput o) {
fixed3 result = tex2D(_MainTex, IN.uv_MainTex);
o.Albedo = result.rgb;
o.Alpha = 1;
}
ENDCG
}
Fallback "Diffuse"
}
All help is greatly appreciated! Thanks!
Answer by Bunny83 · Mar 15, 2016 at 03:28 AM
You can turn any shader in an "inside shader" by simply adding this line:
Cull Front
and by inverting the normal vector. Since you want an unlit shader you don't need a normal vector at all.
If the shader has already this line:
Cull Back
then it has to be changed to the first one. By default most shaders cull (remove / ignore) the back faces of a mesh since a closed mesh usually isn't viewed from the inside. You can also use Cull Off
which will render both sides.
See the documentation for more details.
I quickly created a new unlit shader in Unity and made that changes. I also added alpha blending and a color property.
Answer by ttesla · Nov 25, 2018 at 05:35 PM
Unlit shader with "Cull Front":
Shader "Unlit/UnlitCullFront"
{
Properties
{
_MainTex ("Texture", 2D) = "white" {}
}
SubShader
{
Tags { "RenderType"="Opaque" }
LOD 100
Cull Front // Cull Off - Cull Back
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};
struct v2f
{
float2 uv : TEXCOORD0;
float4 vertex : SV_POSITION;
};
sampler2D _MainTex;
float4 _MainTex_ST;
v2f vert (appdata v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.uv = TRANSFORM_TEX(v.uv, _MainTex);
o.uv.x = 1.0 - o.uv.x; // For mirroring image to inside of the sphere
return o;
}
fixed4 frag (v2f i) : SV_Target
{
// sample the texture
fixed4 col = tex2D(_MainTex, i.uv);
return col;
}
ENDCG
}
}
}
Answer by MisQQ · May 21, 2019 at 12:31 AM
Hello, Can someone tell me how to cut 1/3 of front ? Because this shader works fine but cut sphere in half.