Surface shader: modify the emission with lighting?

Not sure if this is possible, but what I’m trying to do is create a surface shader that uses the lighting model to modify the emissions. The reason to do this is to create a day/night planet shader with lights appearing only on the night side. The lights would be defined in a texture, and would only appear on the ‘dark’ side of the planet (based on light direction).

Within the surf function, I’m setting the emission as so:

o.Emission = tex2D(_Lights,IN.uv_Lights.xy);

I would then like to multiply this by the inverse of the light intensity. However, light information (lightDir) is only available in the lighting model, and changes made to the EditorSurfaceOutput there seem to have no effect (not that I’d expect them to).

Is what I’m trying to do possible? Any suggestions on how to go about it? Thanks for any help.

The full shader is below.

//////////////////////////////////////////////////////////////////////////////

Shader "TestEarthSimple"
{
  Properties 
  {
_MainTex("_MainTex", 2D) = "black" {}
_Lights("_Lights", 2D) = "black" {}

  }

  SubShader 
  {
    Tags
    {
"Queue"="Geometry"
"IgnoreProjector"="False"
"RenderType"="Opaque"

    }

Cull Back
ZWrite On
ZTest LEqual
ColorMask RGBA

    CGPROGRAM
    #pragma surface surf BlinnPhongEditor
    #pragma target 2.0

    sampler2D _MainTex;
    sampler2D _Lights;

      struct EditorSurfaceOutput {
        half3 Albedo;
        half3 Normal;
        half3 Emission;
        half3 Gloss;
        half Specular;
        half Alpha;
        half4 Custom;
      };

      inline half4 LightingBlinnPhongEditor_PrePass (EditorSurfaceOutput s, half4 light)
      {
        half3 spec = light.a * s.Gloss;
        half4 c;
        c.rgb = (s.Albedo * light.rgb + light.rgb * spec);
        c.a = s.Alpha;
        return c;
      }

      inline half4 LightingBlinnPhongEditor (EditorSurfaceOutput s, half3 lightDir, half3 viewDir, half atten)
      {
        half3 h = normalize (lightDir + viewDir);

        half diff = max (0, dot ( lightDir, s.Normal ));

        float nh = max (0, dot (s.Normal, h));
        float spec = pow (nh, s.Specular*128.0);

        half4 res;
        res.rgb = _LightColor0.rgb * diff;
        res.w = spec * Luminance (_LightColor0.rgb);
        res *= atten * 2.0;

        return LightingBlinnPhongEditor_PrePass( s, res );
      }

      struct Input {
        float2 uv_MainTex;
        float2 uv_Lights;

      };

      void surf (Input IN, inout EditorSurfaceOutput o) {
        o.Normal = float3(0.0,0.0,1.0);
        o.Alpha = 1.0;
        o.Gloss = 0.0;
        o.Specular = 0.0;
        o.Custom = 0.0;

        float4 Sampled2D2=tex2D(_MainTex,IN.uv_MainTex.xy);
        float4 Sampled2D1=tex2D(_Lights,IN.uv_Lights.xy);
        o.Albedo = Sampled2D2;
        o.Emission = Sampled2D1;
      }
    ENDCG
  }
  Fallback "Diffuse"
}
  1. don’t write to o.Emission any colors you want to control by lights
  2. write light color to some field (Custom)
  3. replace
s.Albedo * light.rgb

with

lerp(s.Custom, s.Albedo, * light.rgb)

this will make more intensity from ‘Custom’ instead of ‘Albedo’ on dark side

Hey, I’m trying to make a similar shader which will make cutout textures appear in the dark (basically glow-in-the-dark tattoos), however, since I am very new to coding in general, I have no idea how to make it. Your shader seems to work in a similar way but doesn’t use any additional textures which could serve as tattoos in my idea, would you mind helping me/sharing your code with me so we can figure out how it might work?