Josh Posted March 7, 2023 Share Posted March 7, 2023 Does anyone have code for a highpass filter? It would be a nice feature to neutralize lighting: Quote 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 More sharing options...
havenphillip Posted March 7, 2023 Share Posted March 7, 2023 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 } 1 Quote Link to comment Share on other sites More sharing options...
reepblue Posted March 7, 2023 Share Posted March 7, 2023 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! Quote Cyclone - Ultra Game System - Component Preprocessor - Tex2TGA - Darkness Awaits Template (Leadwerks) If you like my work, consider supporting me on Patreon! Link to comment Share on other sites More sharing options...
Josh Posted March 7, 2023 Author Share Posted March 7, 2023 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. Quote 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 More sharing options...
havenphillip Posted March 7, 2023 Share Posted March 7, 2023 28 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! Yeah totally dude it's from muh blog. 1 Quote Link to comment Share on other sites More sharing options...
reepblue Posted March 7, 2023 Share Posted March 7, 2023 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. Quote Cyclone - Ultra Game System - Component Preprocessor - Tex2TGA - Darkness Awaits Template (Leadwerks) If you like my work, consider supporting me on Patreon! Link to comment Share on other sites More sharing options...
havenphillip Posted March 7, 2023 Share Posted March 7, 2023 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: 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.