LYGIA Shader Library

gooch (lygia/lighting/gooch)

render with a gooch stylistic shading model

Dependencies:

Use:

<vec4> gooch(<vec4> albedo, <vec3> normal, <vec3> light, <vec3> view, <float> roughness)

Check it on Github







#ifndef SURFACE_POSITION
#define SURFACE_POSITION v_position
#endif

#ifndef CAMERA_POSITION
#define CAMERA_POSITION vec3(0.0, 0.0, -10.0);
#endif

#ifndef LIGHT_POSITION
#define LIGHT_POSITION vec3(0.0, 10.0, -50.0)
#endif

#ifndef GOOCH_WARM 
#define GOOCH_WARM vec3(0.25, 0.15, 0.0)
#endif 

#ifndef GOOCH_COLD 
#define GOOCH_COLD vec3(0.0, 0.0, 0.2)
#endif 

#ifndef GOOCH_SPECULAR
#define GOOCH_SPECULAR vec3(1.0, 1.0, 1.0)
#endif 

#ifndef FNC_GOOCH
#define FNC_GOOCH
vec4 gooch(const in vec4 _albedo, const in vec3 _N, const in vec3 _L, const in vec3 _V, const in float _roughness, const in float _Li) {
    vec3 warm = GOOCH_WARM + _albedo.rgb * 0.6;
    vec3 cold = GOOCH_COLD + _albedo.rgb * 0.1;

    vec3 l = normalize(_L);
    vec3 n = normalize(_N);
    vec3 v = normalize(_V);

    // Lambert Diffuse
    float diff = diffuse(l, n, v, _roughness) * _Li;
    // Phong Specular
    float spec = specular(l, n, v, _roughness) * _Li;

    return vec4(mix(mix(cold, warm, diff), GOOCH_SPECULAR, spec), _albedo.a);
}


vec4 gooch(const in vec4 _albedo, const in vec3 _N, const in vec3 _L, const in vec3 _V, const in float _roughness) {
    return gooch(_albedo, _N, _L, _V, _roughness, 1.0);
}

vec4 gooch(const in Material _M, const in LightDirectional _L) {
    vec3 V = normalize(CAMERA_POSITION - _M.position);
    return gooch(_M.albedo, _M.normal, _L.direction, V, _M.roughness, _L.intensity * _L.shadow);
}

vec4 gooch(const in Material _M, const in LightPoint _L) {
    vec3 V = normalize(CAMERA_POSITION - _M.position);
    return gooch(_M.albedo, _M.normal, _L.direction, V, _M.roughness, _L.intensity * _L.shadow);
}

vec4 gooch(const in Material _M) {
    #if defined(LIGHT_DIRECTION)
    LightDirectional L = LightDirectionalNew();
    #elif defined(LIGHT_POSITION)
    LightPoint L = LightPointNew();
    #endif

    return gooch(_M, L);
}

#endif

Dependencies:

Use:

<float4> gooch(<float4> albedo, <float3> normal, <float3> light, <float3> view, <float> roughness)

Check it on Github





#ifndef CAMERA_POSITION
#if defined(UNITY_COMPILER_HLSL)
#define CAMERA_POSITION _WorldSpaceCameraPos
#else
#define CAMERA_POSITION float3(0.0, 0.0, -10.0)
#endif
#endif

#ifndef LIGHT_POSITION
#if defined(UNITY_COMPILER_HLSL)
#define LIGHT_POSITION _WorldSpaceLightPos0.xyz
#else
#define LIGHT_POSITION  float3(0.0, 10.0, -50.0)
#endif
#endif



#ifndef GOOCH_WARM 
#define GOOCH_WARM float3(0.25, 0.15, 0.0)
#endif 

#ifndef GOOCH_COLD 
#define GOOCH_COLD float3(0.0, 0.0, 0.2)
#endif 

#ifndef GOOCH_SPECULAR
#if defined(UNITY_COMPILER_HLSL)
#define GOOCH_SPECULAR     _LightColor0.rgb
#else
#define GOOCH_SPECULAR     float3(1.0, 1.0, 1.0)
#endif
#endif

#ifndef FNC_GOOCH
#define FNC_GOOCH
float4 gooch(float4 albedo, float3 normal, float3 light, float3 view, float roughness, float shadow) {
    float3 warm = GOOCH_WARM + albedo.rgb * 0.6;
    float3 cold = GOOCH_COLD + albedo.rgb * 0.1;

    float3 l = normalize(light);
    float3 n = normalize(normal);
    float3 v = normalize(view);

    // Lambert Diffuse
    float diff = diffuse(l, n, v, roughness) * shadow;
    // Phong Specular
    float spec = specular(l, n, v, roughness) * shadow;

    return float4(lerp(lerp(cold, warm, diff), GOOCH_SPECULAR, spec), albedo.a);
}

float4 gooch(float4 albedo, float3 normal, float3 light, float3 view, float roughness) {
    return gooch(albedo, normal, light, view, roughness, 1.0);
}

float4 gooch(Material material) {
    #ifdef LIGHT_DIRECTION
    return gooch(material.albedo, material.normal, LIGHT_DIRECTION, (CAMERA_POSITION - material.position), material.roughness, material.shadow);
    #else
    return gooch(material.albedo, material.normal, (LIGHT_POSITION - material.position), (CAMERA_POSITION - material.position), material.roughness, material.shadow);
    #endif
}

#endif

License

LYGIA is dual-licensed under the Prosperity License and the Patron License for sponsors and contributors.

Sponsors and contributors are automatically added to the Patron License and they can ignore the any non-commercial rule of the Prosperity Licensed software (please take a look to the exception).

It's also possible to get a permanent comercial license hook to a single and specific version of LYGIA.

Get the latest news and releases

Sign up for the news letter bellow, joing the LYGIA's channel on Discord or follow the Github repository