Jump to content

Have Bloom Not Affect Skybox


gamecreator
 Share

Recommended Posts

Is there a way to have the bloom shader only affect the scene, not the skybox?  I like the effect it has on my scene but it washes out a lot of details in the background.

bloom_nobloom.thumb.png.dfed240dddadeca3a088a6c0906017e9.png

Left is no bloom, right is bloom.  (This is with a second directional light in the scene, by the way, out of necessity.  And I know the skybox is crappy quality.  It's the best I could find for a desert for now.)

  • Like 1
Link to comment
Share on other sites

  • 1 month later...

Did you ever solve this? I came up with one possible solution with a little adjustment to the bloom shader that I believe is the one that comes with Leadwerks. You just have to change the fragment part to this:
 

#version 400

uniform sampler2D texture0;
uniform sampler2D texture1;
uniform sampler2DMS texture2;
uniform bool isbackbuffer;
uniform vec2 buffersize;
uniform float currenttime;
uniform float intensity = 4.0;

out vec4 fragData0;

void main(void)
{
    vec2 coord = vec2(gl_FragCoord.xy/buffersize);
    if (isbackbuffer) coord.y = 1.0 - coord.y;

    ivec2 icoords = ivec2(coord * buffersize);

    vec4 blur0 = texture(texture0,coord);
    vec4 scene = texture(texture1, coord); // rendered scene
    vec4 blur2 = texelFetch(texture2, icoords, 0); //glowmap

    fragData0 = clamp((scene+blur2*(blur0*intensity)),0.0,0.9);
}

/*

//original shader
#version 400

uniform sampler2D texture1;
uniform sampler2D texture2;
uniform bool isbackbuffer;
uniform vec2 buffersize;
uniform float currenttime;
uniform float intensity = 2.0;

out vec4 fragData0;
void main(void)
{
    vec2 icoord = vec2(gl_FragCoord.xy/buffersize);
    if (isbackbuffer) icoord.y = 1.0 - icoord.y;
    
    vec4 scene = texture(texture1, icoord); // rendered scene
    vec4 blur = texture(texture2, icoord); // glowmap
    fragData0 = clamp(scene + (blur*intensity), 0.0, 1.0);
}*/

perspective.jpg

  • Like 1
Link to comment
Share on other sites

Hey, I just saw your post.  May be a silly question but which file are you modifying?  I don't have anything that looks like your original shader.  I thought it might be the bloom.shader file in the Shaders\PostEffects\Utility folder.  It has a section that looks close but different:

Quote

#version 400

//-------------------------------------
//MODIFIABLE UNIFORMS
//-------------------------------------
uniform float cutoff=0.15;//The lower this value, the more blurry the scene will be
uniform float overdrive=1.0;//The higher this value, the brighter the bloom effect will be
//-------------------------------------
//
//-------------------------------------

uniform sampler2D texture0;//Diffuse
uniform sampler2D texture1;//Bloom
uniform bool isbackbuffer;
uniform vec2 buffersize;
uniform float currenttime;

out vec4 fragData0;

void main(void)
{
    vec2 icoord = vec2(gl_FragCoord.xy/buffersize);
    if (isbackbuffer) icoord.y = 1.0 - icoord.y;
    vec4 scene = texture(texture0, icoord); // default
    vec4 blur = (texture(texture1,icoord)-cutoff); // glowmap
    blur.r = max(blur.r,0.0); blur.g = max(blur.g,0.0); blur.b = max(blur.b,0.0);
    float pixelbrightness = scene.r * 0.3 + scene.g * 0.59 + scene.b * 0.11;
    fragData0 = scene + (overdrive * blur * max(0.5, 1.0 - overdrive * pixelbrightness ));
    //fragData0=blur;
}

I tried replacing it anyway with your version but it didn't work for me.

Link to comment
Share on other sites

There's a bloom.lua and a bloom.shader in my post effects folder. I assumed those came with Leadwerks. I don't know where I got them, then.  I'll see if I can make it work with the one you posted. I have that one, too, somehow.

This is the one I'm using:

-----------------------------
-- Simple post effect script
-----------------------------
--Called once at start
function Script:Start()
    --Load this script's shader
    self.shader = Shader:Load("Shaders/PostEffects/bloom.shader")
    self.shader_hblur = Shader:Load("Shaders/PostEffects/hblur.shader")
    self.shader_vblur = Shader:Load("Shaders/PostEffects/vblur.shader")
    self.shader_bright = Shader:Load("Shaders/PostEffects/brightpass.shader")
end

--Called each time the camera is rendered
function Script:Render(camera,context,buffer,depth,diffuse,normals)
    
    --Create downsample buffers if they don't exist
    if self.buffer==nil then
        local w=buffer:GetWidth()
        local h=buffer:GetHeight()
        self.buffer={}
        self.buffer[0]=Buffer:Create(buffer:GetWidth(),buffer:GetHeight(),1,0)
        self.buffer[1]=Buffer:Create(w/2,h/2,1,0)
        self.buffer[2]=Buffer:Create(w/4,h/4,1,0)
        self.buffer[3]=Buffer:Create(buffer:GetWidth(),buffer:GetHeight(),1,0)
    end
    
    --Save for bloom pass
    buffer:Disable()

    --Brightpass
    self.buffer[0]:Enable()
    self.shader_bright:Enable()
    diffuse:Bind(1)
    context:DrawImage(diffuse,0,0,buffer:GetWidth(),buffer:GetHeight())
    self.buffer[0]:Disable()

    --Downsample
    self.buffer[0]:Blit(self.buffer[1],Buffer.Color)
    self.buffer[1]:Blit(self.buffer[2],Buffer.Color)
    self.buffer[2]:Blit(self.buffer[3],Buffer.Color)
    
    --hblur
    self.buffer[0]:Enable()
    self.shader_hblur:Enable()  
    self.buffer[3]:GetColorTexture():Bind(1)
    context:DrawImage(self.buffer[3]:GetColorTexture(),0,0,buffer:GetWidth(),buffer:GetHeight())
    self.buffer[0]:Disable()

    --vblur
    self.buffer[3]:Enable()
    self.shader_vblur:Enable()
    self.buffer[0]:GetColorTexture():Bind(1)
    context:DrawImage(self.buffer[0]:GetColorTexture(),0,0,buffer:GetWidth(),buffer:GetHeight())
    self.buffer[3]:Disable()

    --bloom
    buffer:Enable()
    self.shader:Enable()
    diffuse:Bind(1)
    tex=self.buffer[3]:GetColorTexture()
    tex:Bind(2)
    context:DrawImage(self.buffer[3]:GetColorTexture(),0,0,buffer:GetWidth(),buffer:GetHeight())
end

--Called when the effect is detached or the camera is deleted
function Script:Release()
    if self.shader then
        self.shader:Release()
        self.shader = nil
    end
    if self.shader_vblur then
        self.shader_vblur:Release()
        self.shader_vblur = nil
    end
    if self.shader_hblur then
        self.shader_hblur:Release()
        self.shader_hblur = nil
    end
    if self.shader_bright then
        self.shader_bright:Release()
        self.shader_bright = nil
    end
    --Release buffers
    if self.buffer~=nil then
        self.buffer[0]:Release()
        self.buffer[1]:Release()
        self.buffer[2]:Release()
        self.buffer[3]:Release()
        self.buffer=nil
    end        
end

 

Then the bloom shader is :

//Fragment

 

#version 400

uniform sampler2D texture0;
uniform sampler2D texture1;
uniform sampler2DMS texture2;
uniform bool isbackbuffer;
uniform vec2 buffersize;
uniform float currenttime;
uniform float intensity = 4.0;

out vec4 fragData0;

void main(void)
{
    vec2 coord = vec2(gl_FragCoord.xy/buffersize);
    if (isbackbuffer) coord.y = 1.0 - coord.y;

    ivec2 icoords = ivec2(coord * buffersize);

    vec4 blur0 = texture(texture0,coord);
    vec4 scene = texture(texture1, coord); // rendered scene
    vec4 blur2 = texelFetch(texture2, icoords, 0); //glowmap

    fragData0 = clamp((scene+blur2*(blur0*intensity)),0.0,0.9);
}

//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));
}

 


 


 

Link to comment
Share on other sites

In Steam, if you right-click on Leadwerks, go to Properties and Betas tab, you'll see if you're opted in.  But the one that is generated with release for me is 1,767 bytes and this is the entire thing:

SHADER version 1
@OpenGL2.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));
}
@OpenGLES2.Vertex

@OpenGLES2.Fragment

@OpenGL4.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));
}
@OpenGL4.Fragment
//This shader should not be attached directly to a camera. Instead, use the bloom script effect.
#version 400

//-------------------------------------
//MODIFIABLE UNIFORMS
//-------------------------------------
uniform float cutoff=0.15;//The lower this value, the more blurry the scene will be
uniform float overdrive=1.0;//The higher this value, the brighter the bloom effect will be
//-------------------------------------
//
//-------------------------------------

uniform sampler2D texture0;//Diffuse
uniform sampler2D texture1;//Bloom
uniform bool isbackbuffer;
uniform vec2 buffersize;
uniform float currenttime;

out vec4 fragData0;

void main(void)
{
	vec2 icoord = vec2(gl_FragCoord.xy/buffersize);
	if (isbackbuffer) icoord.y = 1.0 - icoord.y;
	vec4 scene = texture(texture0, icoord); // default
	vec4 blur = (texture(texture1,icoord)-cutoff); // glowmap
	blur.r = max(blur.r,0.0); blur.g = max(blur.g,0.0); blur.b = max(blur.b,0.0);
	float pixelbrightness = scene.r * 0.3 + scene.g * 0.59 + scene.b * 0.11;
	fragData0 = scene + (overdrive * blur * max(0.5, 1.0 - overdrive * pixelbrightness ));
	//fragData0=blur;
}

Try creating a new project and see if Leadwerks creates this for you too in the Utility folder.

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...