Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs

ArtUnitFive

1
Posts
1
Topics
A member registered Sep 29, 2019

Recent community posts

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;
(2 edits)

Hello, first off thanks for the toolkit it's great.

Before I found the toolkit I was working on my own raymarcher. I learned a ton from it and got some pretty good results, but the toolkit does (mostly) everything I want to do and is far more performative and easy to use.

That said I had a few effects that I built in my own raymarcher that aren't present in the toolkit which I now want to port over.

Fortunately the workflow you've provided with snippets allows me to do this, but when it comes to unity programming (especially shaders) I am very much at the level of a monkey banging their head against the keyboard, so I'm struggling with a few bits.

In my raymarcher I had a simple specular highlight function that would add gloss based on the position of the scene's light (I could only support one light for my raymarched scene.) The code looks like this:

float3 applySpecular(float3 col, float3 ray, float shadow) {
    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 * shadow * _specularIntensity;
    return col;
}

_lightDir is a

lightObject.transform.forward

of a light object which is passed to my raymarching shader as a float3

I experimented with the transform snippet input type but wasn't able to get a useful result.

So all of this is a long winded way of asking. Do you have any suggestions for how I might get that

lightObject.transform.forward

Into my material snippet or use the resulting float4x4 from the transform input to extract the vector I need?

Thanks.