Skip to main content

On Sale: GamesAssetsToolsTabletopComics
Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines

Found an answer, for anyone else looking:

float3 lightDir = normalize(_WorldSpaceLightPos0.xyz);

The final code looks like this (Like I say I'm really new to shader programming so this may not be the 'right' way to do things but it does work)

In CustomIncludes.cginc

float4 applySpecular(in float3 n, in float4 col, float3 lightDir, float4 lightCol, float3 ray, float specularHighlight, float specularIntensity) {
  float3 reflected = ray.xyz - 2.0 * dot(ray.xyz, n) * n;   float specular = max(dot(reflected, lightDir), 0.0);
  specular = pow(specular, specularHighlight);
  col += specular * lightCol * specularIntensity;
  return col;
}

in Assets/snippets/materials/specular.asset

float3 lightDir = normalize(_WorldSpaceLightPos0.xyz);
$color = applySpecular(normal, $color, lightDir, $lightCol, rayDir, $specularHighlight, $specularIntensity);
           
return $color;