hi all
I’m digging in this since this morning, and cannot figure what is the problem:
Here’s my shader :
Shader "Unlit/ambient_shado_nitghlights"
{
Properties
{
_MainTex ("Texture", 2D) = "white" {}
_LightTex ("Texture", 2D) = "black" {}
_LightStrength("Lightmap strength",Float) = 1
_Ambient_factor("Ambient dif. fact.", Float) = 1
light_on_level("lights ON level", Range(0,1)) = 0.5
}
SubShader
{
Tags {"Queue"="Geometry" "RenderType"="Opaque" }
LOD 100
Pass
{
Tags {"LightMode"="ForwardBase"}
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
// make fog & shadows work
#pragma multi_compile_fwdbase nolightmap nodirlightmap nodynlightmap novertexlight multi_compile_fog
#include "UnityCG.cginc"
#include "AutoLight.cginc"
struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};
struct v2f
{
float2 uv : TEXCOORD0;
SHADOW_COORDS(1) // put shadows data into TEXCOORD1
UNITY_FOG_COORDS(1)
float4 pos : SV_POSITION;
};
sampler2D _MainTex;
sampler2D _LightTex;
float4 _MainTex_ST;
half _Ambient_factor;
half _LightStrength;
half light_on_level;
v2f vert (appdata v)
{
v2f o;
o.pos = UnityObjectToClipPos(v.vertex);
o.uv = TRANSFORM_TEX(v.uv, _MainTex);
TRANSFER_SHADOW(o);
UNITY_TRANSFER_FOG(o,o.pos);
return o;
}
//***************************************
//
// les calculs d'un éclairage Ambient
//
//***************************************
inline half4 AmbientLight(half4 color,half4 shad)
{
half4 c;
c.rgb = (UNITY_LIGHTMODEL_AMBIENT.rgb*color.rgb*shad);
return c;
}
//========================================================================
fixed4 frag (v2f i) : SV_Target
{
// sample the texture
fixed4 c = tex2D(_MainTex, i.uv);
fixed4 nite_lights = tex2D(_LightTex, i.uv)*tex2D(_LightTex, i.uv);
// compute shadow attenuation (1.0 = fully lit, 0.0 = fully shadowed)
fixed shadow = SHADOW_ATTENUATION(i)/2+0.5;
fixed ON_OFF = (UNITY_LIGHTMODEL_AMBIENT.g > light_on_level)?0:1;
half4 col = AmbientLight(c,shadow)*_Ambient_factor+c*(nite_lights * _LightStrength)*ON_OFF;
col.a = 1;
// apply fog
UNITY_APPLY_FOG(i.fogCoord, 1);//col);
return col;
}
ENDCG
}
// shadow casting support
UsePass "Legacy Shaders/VertexLit/SHADOWCASTER"
}
}
And here’s the result:
It’s just perfectly what i need but the for don’t apply…
Anyone could please tell me what i’m doing wrong ?
Thanks in advance and happy unitying !