Hi guys, I need a shader that doesn’t get any light from the scene like a texture
Please help thanks
I’ll have one posted in a min, if I can get home on time
Thanks, then I’m waiting
Sorry I completely forgot, Pixel/Vertex ok? Or does it have to be surface shader… Here is a pixel/vertex one
Shader "Basic/FlatColor"
{
Properties
{
_MainTex("Base (RGB)", 2D) = "white" {}
_Color ("Color", Color) = (0.5,0.5,0.5,1)
_ColorInt ("Color Intensity", Range(0.5, 2.0)) = 1.5
}
SubShader
{
Pass
{
CGPROGRAM
//pragmas go here!
#pragma vertex vert
#pragma fragment frag
//user defined variables anyone?
uniform float4 _Color;
uniform float _ColorInt;
uniform sampler2D _MainTex;
uniform float4 _MainTex_ST;
//base Input structs - these are how functions communicate
//Input struct - Putting info that will be fed to the greddy shaders!
struct vertexInput
{
float4 vertex : POSITION; //Accessing the position of the objects vertices
float4 texcoord : TEXCOORD0; //Can be used to assign to variables
};
//Output struct - What we output from the vertex function into our shaders below
struct vertexOutput
{
float4 pos : SV_POSITION; //We need now to take the position and change it into something
float4 tex : TEXCOORD0; //Unity3D can understand
};
//vertex shader
vertexOutput vert(vertexInput r0)
{
vertexOutput c0;
c0.pos = mul(UNITY_MATRIX_MVP, r0.vertex);
c0.tex = r0.texcoord;
return c0;
}
//pixel shader ..It's over 9,000!
float4 frag(vertexOutput s0) : COLOR
{
float4 tex = tex2D(_MainTex, s0.tex.xy * _MainTex_ST.xy + _MainTex_ST.zw);
return _Color * _ColorInt * tex;
}
ENDCG
}
}
Fallback "Diffuse"
}
Do you accidentally have the surface shader for this.?
I made a nice strumpy shader that’s only emmisive, but with 4.x allowing shadows on mobile, I’m looking into getting a surface shader to render the shadows without doing any lighting calculations, only the output from the strumpy emmisive code…
Having an unlit surface shader code would help me get to grips with shaderlab, (not complete noob, but not a hardcore coder either)
or if you know how to get just the realtime shadowpass/projection, without any lighting calculations, that would be even more awesome…
cheers
Surface shaders are designed to automate the lighting system.
If you don’t need lighting, there’s no need to use a surface shader.
I figured out that, but then I can’t get the realtime shadows to run over the emmisive shader… So my thought was to use a surface shader to trick that to becoming the output of the emmisive code, So the end effect is a shader with no lighting but realtime shadows.
Sounds logical or am I completely of track here I’ve tried the fallback= VertexLit trick mentioned in other posts. but that does nothing it seems…
How are you getting the shadow values?
Haven’t figured that out yet, seems if you use a surface shader that’s handled when its compiled. I’m guessing here by the way. Seems odd no-one made a shadowcaster shader that doesn’t light your scene. so perhaps its not possible. For mobile it would be ideal, have a vertex colored object that still receives realtime shadows from selected caster objects.
here’s what i’m working on, just to show i’m not a complete noob (just a bit sometimes)
Well, here’s one that will do vertex colour times light attenuation. It will only work with one directional light, anything else and you’ll need to add in an extra Pass that’s additive and set to ForwardAdd.
Shader "Debug/VertexColourWithAtten" {
Properties {
// While these two values do nothing for your shader, the fallback shader "VertexLit" requires them for your mesh to cast/recieve shadows.
_Color ("Main Color", Color) = (1.0, 1.0, 1.0, 1.0)
_MainTex ("Color (RGBA)", 2D) = "white" {}
}
SubShader {
Tags {"Queue" = "Geometry" "RenderType" = "Opaque" "LightMode" = "Always" "LightMode" = "ForwardBase"}
Pass {
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma multi_compile_fwdbase
#pragma fragmentoption ARB_precision_hint_fastest
#include "UnityCG.cginc"
#include "AutoLight.cginc"
// If you really want separate shadow and falloff values, uncomment the commented out lines below - the ones starting with //
// As Unity Free only supports shadows from one directional light anyway, there's no real need as directional lights have no falloff.
//#include "CustomLight.cginc"
struct appdata {
float4 vertex : POSITION;
fixed4 color : COLOR;
};
struct v2f
{
float4 pos : SV_POSITION;
float4 color : TEXCOORD0;
LIGHTING_COORDS(1, 2) // This tells it to put the vertex attributes required for lighting into TEXCOORD1 and TEXCOORD2.
};
v2f vert (appdata v)
{
v2f o;
o.pos = mul( UNITY_MATRIX_MVP, v.vertex);
o.color = v.color;
TRANSFER_VERTEX_TO_FRAGMENT(o) // This sets up the vertex attributes required for lighting and passes them through to the fragment shader.
return o;
}
fixed4 frag(v2f i) : COLOR
{
fixed atten = LIGHT_ATTENUATION(i); // This gets the shadow and attenuation values combined.
//fixed falloff = LIGHT_FALLOFF(i); // This is a custom one to get just the attenuation value. Requires CustomLight.cginc to be included.
//fixed shadow = SHADOW_ATTENUATION(i); // This is gets just the shadow value - it's basically a fixed precision float where 1 is in light and 0 is in shadow.
fixed4 c = i.color;
c.rgb *= atten;
return c;
}
ENDCG
}
}
FallBack "VertexLit"
}
If you want the custom stuff in here - the separate falloff values - you’ll need to include this file in the same directory as the above shader. The file must be named CustomLight.cginc.
#ifndef CUSTOMLIGHT_INCLUDED
#define CUSTOMLIGHT_INCLUDED
// ------------ Light helpers --------
#ifdef POINT
#define LIGHT_FALLOFF(a) (tex2D(_LightTexture0, dot(a._LightCoord,a._LightCoord).rr).UNITY_ATTEN_CHANNEL)
#endif
#ifdef SPOT
#define LIGHT_FALLOFF(a) ((a._LightCoord.z > 0) * UnitySpotCookie(a._LightCoord) * UnitySpotAttenuate(a._LightCoord.xyz))
#endif
#ifdef DIRECTIONAL
#define LIGHT_FALLOFF(a) 1.0
#endif
#ifdef POINT_COOKIE
#define LIGHT_FALLOFF(a) (tex2D(_LightTextureB0, dot(a._LightCoord,a._LightCoord).rr).UNITY_ATTEN_CHANNEL * texCUBE(_LightTexture0, a._LightCoord).w)
#endif
#ifdef DIRECTIONAL_COOKIE
#define LIGHT_FALLOFF(a) (tex2D(_LightTexture0, a._LightCoord).w)
#endif
#endif
I’m gonna give this a try, thanks
It worked…
instead of adding the strumpy output as an additional pass. I’ve added your pass to the strumpy shader, set it a proper blendmode. removed the VC color, so its just straight shadows on white. and voila… I’m sure it would be a little more optimized if i where to shoehorn everything in one pass. But on the whole the performance drop on my Note II seems on par with what it was before… so WOOT and thanks…
I’m guestimating, perfomance will drop with more and more units and casters in the scene. But there’s so much bandwith left i’m hoping at least on current gen devices it’ll be a great addition…
cheers
For any future users wanting to add a clean shadow pass to their strumpy shader, here’s the adjusted farfarer code (many thanks and kudos)
Just add it after the regular strumpy shader code, but before the fallback as a second pass.(after the endcg of the strumpy code, in the uncompiled shader (select shader in project and click open).
Pass {
Blend DstColor Zero
Fog{ Mode Off
}
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma multi_compile_fwdbase
#pragma fragmentoption ARB_precision_hint_fastest
#include "UnityCG.cginc"
#include "AutoLight.cginc"
// If you really want separate shadow and falloff values, uncomment the commented out lines below - the ones starting with //
// As Unity Free only supports shadows from one directional light anyway, there's no real need as directional lights have no falloff.
//#include "CustomLight.cginc"
struct appdata {
float4 vertex : POSITION;
fixed4 color : COLOR;
};
struct v2f
{
float4 pos : SV_POSITION;
float4 color : TEXCOORD0;
LIGHTING_COORDS(1, 2) // This tells it to put the vertex attributes required for lighting into TEXCOORD1 and TEXCOORD2.
};
v2f vert (appdata v)
{
v2f o;
o.pos = mul( UNITY_MATRIX_MVP, v.vertex);
o.color = 1;
TRANSFER_VERTEX_TO_FRAGMENT(o) // This sets up the vertex attributes required for lighting and passes them through to the fragment shader.
return o;
}
fixed4 frag(v2f i) : COLOR
{
fixed atten = LIGHT_ATTENUATION(i); // This gets the shadow and attenuation values combined.
//fixed falloff = LIGHT_FALLOFF(i); // This is a custom one to get just the attenuation value. Requires CustomLight.cginc to be included.
//fixed shadow = SHADOW_ATTENUATION(i); // This is gets just the shadow value - it's basically a fixed precision float where 1 is in light and 0 is in shadow.
fixed4 c = i.color;
c.rgb *= atten;
return c;
}
ENDCG
}