- Home /
What- if anything- is wrong with this shader (alpha/reflective/unlit)?
So I just wrote my first shader, and of course by "wrote" I mean hacked together from existing shaders in half an hour on a caffeine high, and to my astonishment it actually did what I was trying to make it do. I can only attribute that to an extreme case of beginner's luck. But I have the feeling it's not at all optimal. Could I do the same thing a better way if I knew what I was doing?
The main thing bugging me is the lightModel (Lambert) in the surface shader. It seems the only options are Lambert and BlinnPhong, but I think the lightingModel ought to be null, because I don't have diffuse or specular lighting going on, only emissive. But I don't know how to do that, or if it would make any difference after saying Lighting Off. Or if anything using the surface shader system is going to be unnecessarily slow compared to writing a proper CGPROGRAM, which I initially tried to figure out from looking the builtin reflective shaders and couldn't quite decipher.
I feel this isn't a great question to be asking here- since it's working now- but at least I'm not asking you to teach me how Unity works and then program my awesome new Slender clone for me, right...?
Here's the shader script in question:
Shader "Reflective/Alpha/Unlit"
{
Properties
{
_Cube ("Cubemap", Cube) = "" { TexGen CubeReflect }
}
Category
{
Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" }
Blend SrcAlpha OneMinusSrcAlpha
Cull Back Lighting Off ZWrite On Fog { Color (0,0,0,0) }
BindChannels
{
Bind "Color", color
Bind "Vertex", vertex
Bind "TexCoord", texcoord
}
SubShader
{
CGPROGRAM
#pragma surface surf Lambert alpha
struct Input {
float3 worldRefl;
};
samplerCUBE _Cube;
void surf (Input IN, inout SurfaceOutput o) {
o.Alpha = texCUBE (_Cube, IN.worldRefl).a;
o.Emission = texCUBE (_Cube, IN.worldRefl).rgb;
}
ENDCG
}
}
}
Answer by Philipp · Feb 25, 2013 at 10:17 AM
You seem to be on track, as far as I can tell.
You can write your own lighting functions for surface shaders and create unlit (or just emissive) shaders that way. These two manual pages should get you started: http://docs.unity3d.com/Documentation/Components/SL-SurfaceShaderLighting.html http://docs.unity3d.com/Documentation/Components/SL-SurfaceShaderLightingExamples.html
Your answer
Follow this Question
Related Questions
how can i modify this shader for transparency? 1 Answer
Unlit Shader with alpha mask 2 Answers
Add reflection to refractive shader 1 Answer
Merging (alpha) Unlit shader with Cutout shader 3 Answers
How do I add transparency to a cg vertex lit shader 2 Answers