From f2862f1e80e29e38516736e468a5606ce253cf94 Mon Sep 17 00:00:00 2001 From: Patricio Gonzalez Vivo Date: Sat, 26 Nov 2022 16:51:15 -0500 Subject: [PATCH] working on iridescence --- Makefile | 10 +++ color_iridescence.frag | 26 ++++++++ lighting_pbr.frag | 15 ++--- lighting_pbrIridescence.frag | 116 +++++++++++++++++++++++++++++++++++ lighting_ssr.frag | 6 +- lygia | 2 +- math_functions.frag | 34 ++++++++++ 7 files changed, 195 insertions(+), 14 deletions(-) create mode 100644 color_iridescence.frag create mode 100644 lighting_pbrIridescence.frag create mode 100644 math_functions.frag diff --git a/Makefile b/Makefile index 2e5ebe9..f42bbc3 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,8 @@ # DRAW +math_functions: + glslViewer math_functions.frag -l + animation_easing: glslViewer animation_easing.frag -l @@ -164,6 +167,13 @@ lighting_pbrClearCoat: lighting_pbrClearCoat_cubemap: glslViewer assets/dragon.obj lighting_pbrClearCoat.frag -e camera_position,-1.43923,0.891203,1.98093 --msaa -C assets/Arches_E_PineTree_3k.hdr -e dynamic_shadows,on -l +lighting_pbrIridescence: + glslViewer assets/dragon.obj lighting_pbrIridescence.frag -e camera_position,-1.43923,0.891203,1.98093 --msaa -l + +lighting_pbrIridescence_cubemap: + glslViewer assets/dragon.obj lighting_pbrIridescence.frag -e camera_position,-1.43923,0.891203,1.98093 --msaa -C assets/Arches_E_PineTree_3k.hdr -e dynamic_shadows,on -l + + lighting_pbrGlass: glslViewer assets/dragon.obj lighting_pbrGlass.frag -e camera_position,-1.43923,0.891203,1.98093 --msaa -l diff --git a/color_iridescence.frag b/color_iridescence.frag new file mode 100644 index 0000000..a250b0d --- /dev/null +++ b/color_iridescence.frag @@ -0,0 +1,26 @@ + +#ifdef GL_ES +precision mediump float; +#endif + +uniform vec2 u_resolution; +uniform vec2 u_mouse; +uniform float u_time; + +varying vec2 v_texcoord; + +#include "lygia/math/const.glsl" +#include "lygia/color/space.glsl" +#include "lygia/lighting/iridescence.glsl" + +void main(void) { + vec4 color = vec4(vec3(0.0), 1.0); + vec2 pixel = 1.0/u_resolution.xy; + vec2 st = gl_FragCoord.xy * pixel; + vec2 uv = v_texcoord; + + color.rgb = iridescence( cos(uv.x*HALF_PI) ,1.0-uv.y); + color = linear2gamma(color); + + gl_FragColor = color; +} diff --git a/lighting_pbr.frag b/lighting_pbr.frag index 0dec307..38e68d4 100644 --- a/lighting_pbr.frag +++ b/lighting_pbr.frag @@ -56,10 +56,10 @@ varying mat3 v_tangentToWorld; #define LIGHT_INTENSITY u_lightIntensity #define LIGHT_COORD v_lightCoord -#include "lygia/lighting/atmosphere.glsl" -#ifndef SCENE_CUBEMAP -#define ENVMAP_FNC(NORM, ROUGHNESS, METALLIC) atmosphere(NORM, normalize(u_light)) -#endif +// #include "lygia/lighting/atmosphere.glsl" +// #ifndef SCENE_CUBEMAP +// #define ENVMAP_FNC(NORM, ROUGHNESS, METALLIC) atmosphere(NORM, normalize(u_light)) +// #endif #include "lygia/color/space/linear2gamma.glsl" #include "lygia/lighting/pbr.glsl" #include "lygia/lighting/material/new.glsl" @@ -79,13 +79,10 @@ void main(void) { #endif Material material = materialNew(); - // material.metallic = 0.0; - // material.roughness = 0.1; - #if defined(FLOOR) && defined(MODEL_VERTEX_TEXCOORD) - material.albedo.rgb = vec3(0.5) + checkBoard(v_texcoord, vec2(8.0)) * 0.5; + material.albedo.rgb = vec3(0.5) + checkBoard(uv, vec2(8.0)) * 0.5; #else - // material.roughness = 0.08; + // material.roughness = 0.00; // material.metallic = 0.99; #endif diff --git a/lighting_pbrIridescence.frag b/lighting_pbrIridescence.frag new file mode 100644 index 0000000..5b2fe40 --- /dev/null +++ b/lighting_pbrIridescence.frag @@ -0,0 +1,116 @@ +// Copyright Patricio Gonzalez Vivo, 2021 - http://patriciogonzalezvivo.com/ + +#ifdef GL_ES +precision mediump float; +#endif + +uniform sampler2D u_scene; +uniform sampler2D u_sceneDepth; + +uniform mat4 u_projectionMatrix; + +uniform vec3 u_camera; +uniform float u_cameraNearClip; +uniform float u_cameraFarClip; + +uniform vec3 u_light; +uniform vec3 u_lightColor; +uniform float u_lightFalloff; +uniform float u_lightIntensity; + +uniform float u_iblLuminance; + +uniform samplerCube u_cubeMap; +uniform vec3 u_SH[9]; + +#ifdef LIGHT_SHADOWMAP +uniform sampler2D u_lightShadowMap; +uniform mat4 u_lightMatrix; +varying vec4 v_lightCoord; +#endif + +uniform vec2 u_resolution; +uniform float u_time; + +varying vec4 v_position; +varying vec4 v_color; +varying vec3 v_normal; + +#ifdef MODEL_VERTEX_TEXCOORD +varying vec2 v_texcoord; +#endif + +#ifdef MODEL_VERTEX_TANGENT +varying vec4 v_tangent; +varying mat3 v_tangentToWorld; +#endif + +#define SURFACE_POSITION v_position +#define CAMERA_POSITION u_camera +#define IBL_LUMINANCE u_iblLuminance + +// #define LIGHT_POSITION u_light +#define LIGHT_DIRECTION u_light +#define LIGHT_COLOR u_lightColor +#define LIGHT_FALLOFF u_lightFalloff +#define LIGHT_INTENSITY u_lightIntensity +#define LIGHT_COORD v_lightCoord + +// #include "lygia/lighting/atmosphere.glsl" +// #ifndef SCENE_CUBEMAP +// #define ENVMAP_FNC(NORM, ROUGHNESS, METALLIC) atmosphere(NORM, normalize(u_light)) +// #endif +#include "lygia/math/bump.glsl" +#include "lygia/color/space/linear2gamma.glsl" +#include "lygia/color/space/gamma2linear.glsl" + +#include "lygia/color/palette/hue.glsl" +#include "lygia/color/palette/chroma.glsl" +#include "lygia/color/palette/spectrum.glsl" + +#include "lygia/lighting/pbrClearCoat.glsl" +#include "lygia/lighting/pbr.glsl" +#include "lygia/lighting/pbrGlass.glsl" +#include "lygia/lighting/wavelength.glsl" +#include "lygia/lighting/iridescence.glsl" +#include "lygia/lighting/material/new.glsl" + +float checkBoard(vec2 uv, vec2 _scale) { + uv = floor(fract(uv * _scale) * 2.0); + return min(1.0, uv.x + uv.y) - (uv.x * uv.y); +} + +void main(void) { + vec4 color = vec4(0.0, 0.0, 0.0, 1.0); + vec2 pixel = 1.0/u_resolution; + vec2 st = gl_FragCoord.xy * pixel; + vec2 uv = st; + #if defined(MODEL_VERTEX_TEXCOORD) + uv = v_texcoord; + #endif + + Material mat = materialNew(); + #if defined(FLOOR) && defined(MODEL_VERTEX_TEXCOORD) + mat.albedo.rgb = vec3(0.5) + checkBoard(uv, vec2(8.0)) * 0.5; + #endif + +#if defined(MODEL_NAME_SUZANNE1) + mat.clearCoat = 2.0; + color = pbrClearCoat(mat); +#elif defined(MODEL_NAME_SUZANNE3) + // mat.roughness = 0.1; + color = pbrGlass(mat); +#else + color = pbr(mat); +#endif + + vec3 L = normalize(LIGHT_DIRECTION); + vec3 V = normalize(CAMERA_POSITION - (SURFACE_POSITION).xyz); + vec3 N = normalize(mat.normal); + color.rgb += iridescence( abs(dot(N, V)), 1.0); + color.rgb += iridescence(V, N, L, 270.0); + + color = linear2gamma(color); + + gl_FragColor = color; +} diff --git a/lighting_ssr.frag b/lighting_ssr.frag index f5657b4..08c6862 100644 --- a/lighting_ssr.frag +++ b/lighting_ssr.frag @@ -59,7 +59,6 @@ varying mat3 v_tangentToWorld; #define CAMERA_POSITION u_camera #define IBL_LUMINANCE u_iblLuminance - #define LIGHT_POSITION u_light #define LIGHT_COLOR u_lightColor #define LIGHT_FALLOFF u_lightFalloff @@ -103,9 +102,8 @@ void main(void) { #endif Material material = materialNew(); - - material.metallic = 0.0; - material.roughness = 0.05; + // material.metallic = 0.0; + // material.roughness = 0.05; #if defined(FLOOR) && defined(MODEL_VERTEX_TEXCOORD) material.albedo.rgb = vec3(0.5) + checkBoard(v_texcoord, vec2(8.0)) * 0.5; diff --git a/lygia b/lygia index 5e643d1..8c0b694 160000 --- a/lygia +++ b/lygia @@ -1 +1 @@ -Subproject commit 5e643d15146a55163b825ed2787ed0e37f8cee71 +Subproject commit 8c0b69445670ccbf1447238f81d40756364cc606 diff --git a/math_functions.frag b/math_functions.frag new file mode 100644 index 0000000..80b206c --- /dev/null +++ b/math_functions.frag @@ -0,0 +1,34 @@ + +#ifdef GL_ES +precision mediump float; +#endif + +uniform vec2 u_resolution; +uniform vec2 u_mouse; +uniform float u_time; + +varying vec2 v_texcoord; + +#include "lygia/draw/stroke.glsl" + +#include "lygia/math/gain.glsl" +#include "lygia/math/bump.glsl" +#include "lygia/math/saturate.glsl" +#include "lygia/math/parabola.glsl" +#include "lygia/math/gaussian.glsl" + +void main(void) { + vec4 color = vec4(vec3(0.0), 1.0); + vec2 pixel = 1.0/u_resolution.xy; + vec2 st = gl_FragCoord.xy * pixel; + vec2 uv = v_texcoord; + + float f = st.x; + f = bump( (f - 0.5) * 2.0, 0.0); + // f = gain(f, 0.7); + // f = parabola(f, 0.99); + // f = gaussian(f, 0.9); + color += stroke(st.y, f, pixel.y * 2.0); + + gl_FragColor = color; +}