gamecreator Posted November 8, 2019 Share Posted November 8, 2019 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. 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.) 1 Quote Link to comment Share on other sites More sharing options...
havenphillip Posted December 21, 2019 Share Posted December 21, 2019 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); }*/ 1 Quote Link to comment Share on other sites More sharing options...
gamecreator Posted December 23, 2019 Author Share Posted December 23, 2019 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. Quote Link to comment Share on other sites More sharing options...
havenphillip Posted December 23, 2019 Share Posted December 23, 2019 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)); } Quote Link to comment Share on other sites More sharing options...
gamecreator Posted December 23, 2019 Author Share Posted December 23, 2019 Thank you. I'll try it in a bit. Are you on default or beta? Quote Link to comment Share on other sites More sharing options...
havenphillip Posted December 23, 2019 Share Posted December 23, 2019 I don't know. How would I check that? I tried it with that other script. It got too complicated and I gave up. I couldn't manage to isolate the skybox. Quote Link to comment Share on other sites More sharing options...
gamecreator Posted December 23, 2019 Author Share Posted December 23, 2019 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. Quote Link to comment Share on other sites More sharing options...
Yue Posted December 23, 2019 Share Posted December 23, 2019 I'm going to distort this question a bit. Is it possible to modify the ground shader so that it casts shadows? Quote Link to comment Share on other sites More sharing options...
havenphillip Posted December 23, 2019 Share Posted December 23, 2019 Mine says "NONE - opt out of all beta programs." I do have that shader, too. Quote Link to comment Share on other sites More sharing options...
havenphillip Posted December 23, 2019 Share Posted December 23, 2019 31 minutes ago, ?Yue? said: I'm going to distort this question a bit. Is it possible to modify the ground shader so that it casts shadows? What do you mean? You're not getting any shadows? Which ground shader? Quote Link to comment Share on other sites More sharing options...
Yue Posted December 24, 2019 Share Posted December 24, 2019 It's just that the terrain doesn't produce shadows. Inside the shaders I see some that say terrain. I'd expect the hill to cast a shadow over the same terrain. Quote Link to comment Share on other sites More sharing options...
havenphillip Posted December 24, 2019 Share Posted December 24, 2019 1 hour ago, ?Yue? said: It's just that the terrain doesn't produce shadows. That's weird. I never noticed that. This is probably way beyond me. I don't know the terrain shaders at all. I think casting shadows has to do with materials, and you can't put materials on the terrain. 1 Quote Link to comment Share on other sites More sharing options...
Yue Posted December 24, 2019 Share Posted December 24, 2019 It's quite strange why this doesn't happen, you see strange effects when I want to simulate a sunrise, and I've never been able to understand why Leadwerks doesn't do this. 1 Quote Link to comment Share on other sites More sharing options...
havenphillip Posted December 24, 2019 Share Posted December 24, 2019 Yeah I agree. I give Josh the benefit of the doubt, though. There's only so much one guy can do. If the demand for it was high enough I'm sure he'd put that in. There has to be a solution out there somewhere. We just got to find it ourselves. 1 Quote Link to comment Share on other sites More sharing options...
gamecreator Posted December 24, 2019 Author Share Posted December 24, 2019 2 hours ago, havenphillip said: Mine says "NONE - opt out of all beta programs." I do have that shader, too. I only have one in the Utility folder. I'm guessing you downloaded another somewhere. Would you mind attaching the files to a post? Quote Link to comment Share on other sites More sharing options...
havenphillip Posted December 24, 2019 Share Posted December 24, 2019 Yeah this should be everything involved. bloom.zip 1 Quote Link to comment Share on other sites More sharing options...
gamecreator Posted December 24, 2019 Author Share Posted December 24, 2019 Here are the three versions (no bloom, default bloom, your bloom). Your bloom definitely does a much better job of not affecting the background (though it still alters it a bit). Thanks much for sharing this. 2 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.