8000 ColorPicker by patriciogonzalezvivo · Pull Request #229 · patriciogonzalezvivo/lygia · GitHub
[go: up one dir, main page]

Skip to content

Conversation

@patriciogonzalezvivo
Copy link
Owner
@patriciogonzalezvivo patriciogonzalezvivo commented Oct 22, 2024

Adding a flexible colorPicker for debugging

2024-10-22.19-31-14.mp4
2024-10-22.19-32-07.mp4
2024-10-22.19-35-12.mp4
2024-10-22.19-38-16.mp4

Can be tested with:

#ifdef GL_ES
precision mediump float;
#endif

uniform sampler2D   u_scene;

uniform mat4        u_viewMatrix;
uniform mat4        u_projectionMatrix;

uniform vec3        u_camera;
uniform vec3        u_light;

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 vec2        u_mouse;
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

#define SURFACE_POSITION    v_position
#define CAMERA_POSITION     u_camera

#define LIGHT_DIRECTION     u_light
#define LIGHT_COORD         v_lightCoord

#define DIGITS_SIZE vec2(.015)
#define PIXEL_SIZE vec2(0.005)
#define PIXEL_KERNEL_SIZE 14

#include "lygia/lighting/material/new.glsl"
#include "lygia/lighting/pbrLittle.glsl"

#include "lygia/space/ratio.glsl"
#include "lygia/draw/matrix.glsl"

#include "lygia/draw/colorPicker.glsl"

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 = ratio(st, u_resolution);
    vec2 mouse = u_mouse * pixel;
    
    #if defined(POSTPROCESSING)

    color = texture2D(u_scene, st);

    vec4 debug = vec4(0.0);
    debug += colorPicker(u_scene, mouse, u_resolution, uv - ratio(mouse, u_resolution));
    color = mix(color, debug, debug.a);

    #else

    // Draw the scene
    Material material = materialNew();
    color = pbrLittle(material);
    color = linear2gamma(color);

    #endif

    gl_FragColor = color;
}

@patriciogonzalezvivo patriciogonzalezvivo changed the title Adding a colorPicker ColorPicker Oct 22, 2024
Copy link
Collaborator
@shadielhajj shadielhajj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very cool!

@patriciogonzalezvivo patriciogonzalezvivo merged commit c618076 into main Oct 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

0