Jump to content

Highpass filter?


Josh
 Share

Recommended Posts

I did a high-pass filter:

 

 

VERTEX:

 

#version 400

uniform mat4 projectionmatrix;
uniform mat4 drawmatrix;
uniform vec2 offset;
uniform vec2 position[4];

in vec3 vertex_position;

void main(void)
{
    gl_Position = projectionmatrix * (drawmatrix * vec4(position[gl_VertexID]+offset, 0.0, 1.0));
}

 

FRAGMENT:

 

 

//from https://learnopengl.com/Advanced-OpenGL/Framebuffers

#version 400

//Variables
float pass_mix = 0.5;
float spread = 1000.0;
float brightness = 1.3;

//Uniforms
uniform sampler2D texture1;
uniform bool isbackbuffer;
uniform vec2 buffersize;

//Outputs
out vec4 fragData0;

float offset = 1.0 / spread;  

vec3 blendMultiply(vec3 base, vec3 blend) {
    return base*blend;
}

vec3 blendMultiply(vec3 base, vec3 blend, float opacity) {
    return (blendMultiply(base, blend) * opacity + base * (1.0 - opacity));
}

void main(void)
{
    vec2 coord = vec2(gl_FragCoord.xy/buffersize);
    if (isbackbuffer) coord.y = 1.0 - coord.y;
    
    vec4 outcol = texture(texture1,coord);

    vec2 offsets[9] = vec2[](
        vec2(-offset,  offset), // top-left
        vec2( 0.0f,    offset), // top-center
        vec2( offset,  offset), // top-right
        vec2(-offset,  0.0f),   // center-left
        vec2( 0.0f,    0.0f),   // center-center
        vec2( offset,  0.0f),   // center-right
        vec2(-offset, -offset), // bottom-left
        vec2( 0.0f,   -offset), // bottom-center
        vec2( offset, -offset)  // bottom-right    
    );
    
    //Blur
    float kernel[9] = float[](
        1.0 / 16, 2.0 / 16, 1.0 / 16,
        2.0 / 16, 4.0 / 16, 2.0 / 16,
        1.0 / 16, 2.0 / 16, 1.0 / 16  
    );
    
    vec3 sampleTex[9];
    for(int i = 0; i < 9; i++)
    {
        sampleTex[i] = vec3(texture(texture1, coord + offsets[i]));
    }
    vec3 col = vec3(0.0);
    for(int i = 0; i < 9; i++)
        col += sampleTex[i] * kernel[i];
        
    //High Pass
    vec3 high_pass = 0.5 - 8.0 * (col - outcol.xyz);

    //Output
    fragData0.xyz = blendMultiply(outcol.xyz,high_pass,0.5);
    //fragData0 = vec4(high_pass,1); //pure high pass
}

 

 

 

  • Like 1
Link to comment
Share on other sites

5 minutes ago, reepblue said:

Oh cool, so this makes it so the room isn't lit by multiple point lights?

Also Phil, is that a post process shader that'll work in Leadwerks? I'm eager to try it out! 

I am talking more about image processing. It can remove the lighting from some photographs and gives you a look that is closer to the true color of a surface. I think it is done by first applying a Guassian blur and then some other operation.

My job is to make tools you love, with the features you want, and performance you can't live without.

Link to comment
Share on other sites

9 minutes ago, Josh said:

I am talking more about image processing. It can remove the lighting from some photographs and gives you a look that is closer to the true color of a surface. I think it is done by first applying a Guassian blur and then some other operation.

Ahh ok. It's just that the black splotches went away from what look like are from gaps made by the point light radius values. 

Cyclone - Ultra Game System - Component PreprocessorTex2TGA - Darkness Awaits Template (Leadwerks)

If you like my work, consider supporting me on Patreon!

Link to comment
Share on other sites

7 minutes ago, Josh said:

I am talking more about image processing. It can remove the lighting from some photographs and gives you a look that is closer to the true color of a surface. I think it is done by first applying a Guassian blur and then some other operation.

Yeah it uses kernels to blur the image then subtracts the standard image from it which gives a grey, and the difference due to the blur sharpens it up. That's what high pass is in GIMP. I don't know how it would be used for lights. Looks like this:
highpass.thumb.jpg.9a043791d7699dcdb9ed8c0ac74a6599.jpg

  • Like 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...