Skip to content

Commit

Permalink
working on iridescence
Browse files Browse the repository at this point in the history
patriciogonzalezvivo committed Nov 26, 2022
1 parent 655adcb commit f2862f1
Showing 7 changed files with 195 additions and 14 deletions.
10 changes: 10 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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

26 changes: 26 additions & 0 deletions color_iridescence.frag
Original file line number Diff line number Diff line change
@@ -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;
}
15 changes: 6 additions & 9 deletions lighting_pbr.frag
Original file line number Diff line number Diff line change
@@ -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

116 changes: 116 additions & 0 deletions lighting_pbrIridescence.frag
Original file line number Diff line number Diff line change
@@ -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;
}
6 changes: 2 additions & 4 deletions lighting_ssr.frag
Original file line number Diff line number Diff line change
@@ -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;
34 changes: 34 additions & 0 deletions math_functions.frag
Original file line number Diff line number Diff line change
@@ -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;
}

0 comments on commit f2862f1

Please sign in to comment.