Hi. I want to write a shader that works the same as the skyboxshader. Full emission, isn't affected by light or fog. How do I do that? I tried to copy from the skyboxshader but it didn't work at all
This is how I make the "skybox". In fact, the sky is not necessary as a box You could make it as any shape you want. My example is a sphere. The most important part of code are "CULL FRONT", "out float depthEPTH" and "depth = 1". That will make all object looking like always inside the skybox. (fog is enabled in the scene too) Code (csharp): Shader "BlueSky/Skybox" { Properties { color_map ("color_map", 2D) = "white" {} } SubShader { Pass { CULL FRONT CGPROGRAM //-------------- #pragma vertex vertex_shader #pragma fragment fragment_shader struct a2v { float4 vertex : POSITION; float4 texcoord : TEXCOORD0; }; struct v2f { float4 position : POSITION; float4 texcoord : TEXCOORD1; }; v2f vertex_shader(a2v IN) { v2f OUT; OUT.position = mul(glstate.matrix.mvp, IN.vertex); OUT.texcoord = IN.texcoord; return OUT; } void fragment_shader( v2f IN, uniform sampler2D color_map, out float4 col:COLOR, out float depth:DEPTH ) { col.xyz = tex2D(color_map, IN.texcoord.xyz); col.w = 1; depth = 1; } ENDCG //-------------- } } }
Here's a simpler shader, which might be easier to understand if you don't know Cg: Code (csharp): Shader "Skybox" { Properties { _Color ("Main Color", Color) = (1,1,1,1) _MainTex ("Base (RGB)", 2D) = "white" {} } SubShader { Pass { Tags {"Queue" = "1000"} Cull Front ZWrite Off SetTexture [_MainTex] { ConstantColor [_Color] combine texture*constant } } } }