lygia
/lighting
/raymarch
/shading
)Material Constructor. Designed to integrate with GlslViewer's defines https://github.com/patriciogonzalezvivo/glslViewer/wiki/GlslViewer-DEFINES#material-defines
Dependencies:
lygia
/lighting
/raymarch
/normal
.glsl
lygia
/lighting
/raymarch
/cast
.glsl
lygia
/lighting
/raymarch
/ao
.glsl
lygia
/lighting
/raymarch
/softShadow
.glsl
lygia
/lighting
/shadingData
/new
.glsl
lygia
/math
/saturate
.glsl
Use:
void raymarchMaterial(in <vec3> ro, in <vec3> rd, out material _mat)
material raymarchMaterial(in <vec3> ro, in <vec3> rd)
#ifndef LIGHT_POSITION
#define LIGHT_POSITION vec3(0.0, 10.0, -50.0)
#endif
#ifndef LIGHT_COLOR
#define LIGHT_COLOR vec3(1.0, 1.0, 1.0)
#endif
#ifndef RAYMARCH_AMBIENT
#define RAYMARCH_AMBIENT vec3(1.0, 1.0, 1.0)
#endif
#ifndef RAYMARCH_SHADING_FNC
#define RAYMARCH_SHADING_FNC raymarchDefaultShading
#endif
#ifndef FNC_RAYMARCH_DEFAULTSHADING
#define FNC_RAYMARCH_DEFAULTSHADING
vec4 raymarchDefaultShading(Material m, ShadingData shadingData) {
// This are here to be access by RAYMARCH_AMBIENT
vec3 worldNormal = m.normal;
vec3 worldPosition = m.position;
#if defined(LIGHT_DIRECTION)
vec3 lig = normalize(LIGHT_DIRECTION);
#else
vec3 lig = normalize(LIGHT_POSITION - m.position);
#endif
vec3 ref = reflect(-shadingData.V, m.normal);
float occ = raymarchAO(m.position, m.normal);
vec3 hal = normalize(lig + shadingData.V);
float amb = saturate(0.5 + 0.5 * m.normal.y);
float dif = saturate(dot(m.normal, lig));
float bac = saturate(dot(m.normal, normalize(vec3(-lig.x, 0.0, -lig.z)))) * saturate(1.0 - m.position.y);
float dom = smoothstep( -0.1, 0.1, ref.y );
float fre = pow(saturate(1.0 + dot(m.normal, -shadingData.V)), 2.0);
dif *= raymarchSoftShadow(m.position, lig);
dom *= raymarchSoftShadow(m.position, ref);
vec3 env = RAYMARCH_AMBIENT;
vec3 shade = vec3(0.0, 0.0, 0.0);
shade += 1.30 * dif * LIGHT_COLOR;
shade += 0.40 * amb * occ * env;
shade += 0.50 * dom * occ * env;
shade += 0.50 * bac * occ * 0.25;
shade += 0.25 * fre * occ;
return vec4(m.albedo.rgb * shade, m.albedo.a);
}
#endif
Dependencies:
lygia
/lighting
/raymarch
/normal
.glsl
lygia
/lighting
/raymarch
/cast
.glsl
lygia
/lighting
/raymarch
/ao
.glsl
lygia
/lighting
/raymarch
/softShadow
.glsl
lygia
/lighting
/shadingData
/new
.glsl
Use:
void raymarchMaterial(in <float3> ro, in <float3> rd, out material _mat)
material raymarchMaterial(in <float3> ro, in <float3> rd)
#ifndef LIGHT_POSITION
#define LIGHT_POSITION float3(0.0, 10.0, -50.0)
#endif
#ifndef LIGHT_COLOR
#define LIGHT_COLOR float3(1.0, 1.0, 1.0)
#endif
#ifndef RAYMARCH_AMBIENT
#define RAYMARCH_AMBIENT float3(1.0, 1.0, 1.0)
#endif
#ifndef RAYMARCH_SHADING_FNC
#define RAYMARCH_SHADING_FNC raymarchDefaultShading
#endif
#ifndef FNC_RAYMARCH_DEFAULTSHADING
#define FNC_RAYMARCH_DEFAULTSHADING
float4 raymarchDefaultShading(Material m, ShadingData shadingData) {
// This are here to be access by RAYMARCH_AMBIENT
float3 worldNormal = m.normal;
float3 worldPosition = m.position;
#if defined(LIGHT_DIRECTION)
float3 lig = normalize(LIGHT_DIRECTION);
#else
float3 lig = normalize(LIGHT_POSITION - m.position);
#endif
float3 ref = reflect(-shadingData.V, m.normal);
float occ = raymarchAO(m.position, m.normal);
float3 hal = normalize(lig + shadingData.V);
float amb = saturate(0.5 + 0.5 * m.normal.y);
float dif = saturate(dot(m.normal, lig));
float bac = saturate(dot(m.normal, normalize(float3(-lig.x, 0.0, -lig.z)))) * saturate(1.0 - m.position.y);
float dom = smoothstep( -0.1, 0.1, ref.y );
float fre = pow(saturate(1.0 + dot(m.normal, -shadingData.V)), 2.0);
dif *= raymarchSoftShadow(m.position, lig);
dom *= raymarchSoftShadow(m.position, ref);
float3 env = RAYMARCH_AMBIENT;
float3 shade = float3(0.0, 0.0, 0.0);
shade += 1.30 * dif * LIGHT_COLOR;
shade += 0.40 * amb * occ * env;
shade += 0.50 * dom * occ * env;
shade += 0.50 * bac * occ * 0.25;
shade += 0.25 * fre * occ;
return float4(m.albedo.rgb * shade, m.albedo.a);
}
#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.
Sign up for the news letter bellow, joing the LYGIA's channel on Discord or follow the Github repository