LYGIA Shader Library

gooch (lygia/v1.1.4/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 normal, const in vec3 light, const in vec3 view, const in float roughness, const in float shadow) {
    vec3 warm = GOOCH_WARM + albedo.rgb * 0.6;
    vec3 cold = GOOCH_COLD + albedo.rgb * 0.1;

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

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

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


vec4 gooch(const in vec4 albedo, const in vec3 normal, const in vec3 light, const in vec3 view, const in float roughness) {
    return gooch(albedo, normal, light, view, roughness, 1.0);
}

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

#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

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