lygia
/lighting
/material
/normal
)Get material normal property from GlslViewer's defines https://github.com/patriciogonzalezvivo/glslViewer/wiki/GlslViewer-DEFINES#material-defines
Dependencies:
Use:
vec4 materialNormal()
#ifndef FNC_MATERIAL_NORMAL
#define FNC_MATERIAL_NORMAL
#ifdef MATERIAL_NORMALMAP
uniform SAMPLER_TYPE MATERIAL_NORMALMAP;
#endif
#ifdef MATERIAL_BUMPMAP_NORMALMAP
uniform SAMPLER_TYPE MATERIAL_BUMPMAP_NORMALMAP;
#endif
vec3 materialNormal() {
vec3 normal = vec3(0.0, 0.0, 1.0);
#ifdef MODEL_VERTEX_NORMAL
normal = v_normal;
#if defined(MODEL_VERTEX_TANGENT) && defined(MODEL_VERTEX_TEXCOORD) && defined(MATERIAL_NORMALMAP)
vec2 uv = v_texcoord.xy;
#if defined(MATERIAL_NORMALMAP_OFFSET)
uv += (MATERIAL_NORMALMAP_OFFSET).xy;
#endif
#if defined(MATERIAL_NORMALMAP_SCALE)
uv *= (MATERIAL_NORMALMAP_SCALE).xy;
#endif
normal = SAMPLER_FNC(MATERIAL_NORMALMAP, uv).xyz;
normal = v_tangentToWorld * (normal * 2.0 - 1.0);
#elif defined(MODEL_VERTEX_TANGENT) && defined(MODEL_VERTEX_TEXCOORD) && defined(MATERIAL_BUMPMAP_NORMALMAP)
vec2 uv = v_texcoord.xy;
#if defined(MATERIAL_BUMPMAP_OFFSET)
uv += (MATERIAL_BUMPMAP_OFFSET).xy;
#endif
#if defined(MATERIAL_BUMPMAP_SCALE)
uv *= (MATERIAL_BUMPMAP_SCALE).xy;
#endif
normal = v_tangentToWorld * ( SAMPLER_FNC(MATERIAL_BUMPMAP_NORMALMAP, uv).xyz * 2.0 - 1.0) ;
#endif
#endif
return normal;
}
#endif
Dependencies:
Use:
float4 materialNormal()
#ifndef FNC_MATERIAL_NORMAL
#define FNC_MATERIAL_NORMAL
#ifdef MATERIAL_NORMALMAP
uniform SAMPLER_TYPE MATERIAL_NORMALMAP;
#endif
#ifdef MATERIAL_BUMPMAP_NORMALMAP
uniform SAMPLER_TYPE MATERIAL_BUMPMAP_NORMALMAP;
#endif
float3 materialNormal() {
float3 normal = float3(0.0, 0.0, 1.0);
#ifdef MODEL_VERTEX_NORMAL
normal = v_normal;
#if defined(MODEL_VERTEX_TANGENT) && defined(MODEL_VERTEX_TEXCOORD) && defined(MATERIAL_NORMALMAP)
float2 uv = v_texcoord.xy;
#if defined(MATERIAL_NORMALMAP_OFFSET)
uv += (MATERIAL_NORMALMAP_OFFSET).xy;
#endif
#if defined(MATERIAL_NORMALMAP_SCALE)
uv *= (MATERIAL_NORMALMAP_SCALE).xy;
#endif
normal = SAMPLER_FNC(MATERIAL_NORMALMAP, uv).xyz;
normal = v_tangentToWorld * (normal * 2.0 - 1.0);
#elif defined(MODEL_VERTEX_TANGENT) && defined(MODEL_VERTEX_TEXCOORD) && defined(MATERIAL_BUMPMAP_NORMALMAP)
float2 uv = v_texcoord.xy;
#if defined(MATERIAL_BUMPMAP_OFFSET)
uv += (MATERIAL_BUMPMAP_OFFSET).xy;
#endif
#if defined(MATERIAL_BUMPMAP_SCALE)
uv *= (MATERIAL_BUMPMAP_SCALE).xy;
#endif
normal = v_tangentToWorld * ( SAMPLER_FNC(MATERIAL_BUMPMAP_NORMALMAP, uv).xyz * 2.0 - 1.0) ;
#endif
#endif
return normal;
}
#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