Hey guys, I’ve been messing around with glsl bloom and greyscale.
I’m able to get both to work. I can toggle them on which is great.
I want to fade in the greyscale, though, not just toggle it on. I’ve tried for a while today to do SetShaderParameter but it’s just not working.
My use case is fading this in (from full color to full monochrome) and back out in-game.
Below is my xml which is bloom, an unused pixellation effect, and greyscale mashed together. Like I said, it works fine toggling on and off the Grey tag via:
effectRenderPath:SetEnabled("Grey", true)
But this requires the values (swapping rgb for intensity) to be preset in the GreyScale.glsl file. I need to change those values during gameplay.
BloomGreyScale.xml
<renderpath>
<rendertarget name="buffer" sizedivisor="1 1" filter="false"/>
<command type="clear" color="fog" depth="1.0" stencil="0" output="buffer"/>
<command type="scenepass" pass="base" vertexlights="true" metadata="base" output="buffer" />
<command type="forwardlights" pass="light" output="buffer" />
<command type="scenepass" pass="postopaque" output="buffer" />
<command type="scenepass" pass="alpha" vertexlights="true" sort="backtofront" metadata="alpha" output="buffer" />
<command type="scenepass" pass="postalpha" sort="backtofront" output="buffer" />
<command type="quad" tag="Grey" vs="CopyFramebuffer" ps="GreyScale" output="viewport">
<parameter name="Greyness" value="1 1 1" />
<texture unit="diffuse" name="buffer" />
</command>
<rendertarget name="blurv" tag="Bloom" sizedivisor="6 6" format="rgb" filter="true" />
<rendertarget name="blurh" tag="Bloom" sizedivisor="6 6" format="rgb" filter="true" />
<command type="quad" tag="Bloom" vs="Bloom" ps="Bloom" psdefines="BRIGHT" output="blurv">
<parameter name="BloomThreshold" value="0.3" />
<texture unit="diffuse" name="viewport" />
</command>
<command type="quad" tag="Bloom" vs="Bloom" ps="Bloom" psdefines="BLURH" output="blurh">
<texture unit="diffuse" name="blurv" />
</command>
<command type="quad" tag="Bloom" vs="Bloom" ps="Bloom" psdefines="BLURV" output="blurv">
<texture unit="diffuse" name="blurh" />
</command>
<command type="quad" tag="Bloom" vs="Bloom" ps="Bloom" psdefines="COMBINE" output="viewport">
<parameter name="BloomMix" value="1 .5" />
<texture unit="diffuse" name="viewport" />
<texture unit="normal" name="blurv" />
</command>
</renderpath>
I tried modifying the CoreData/Shaders/GreyScale file:
#include "Uniforms.glsl"
#include "Samplers.glsl"
#include "Transform.glsl"
#include "ScreenPos.glsl"
#include "Lighting.glsl"
varying vec2 vScreenPos;
uniform vec3 cGreyness;
void VS()
{
mat4 modelMatrix = iModelMatrix;
vec3 worldPos = GetWorldPos(modelMatrix);
gl_Position = GetClipPos(worldPos);
vScreenPos = GetScreenPosPreDiv(gl_Position);
}
void PS()
{
vec3 rgb = texture2D(sDiffMap, vScreenPos).rgb;
float intensity = GetIntensity(rgb)-cGreyness.x;
gl_FragColor = vec4(vec3(cGreyness), 1.0);
}
Now, I know the above won’t actually make the intended monochrome effect, it’ll be a flat color on the whole screen. I can do the math (blending the rgb and intensity values together with the ‘greyness’ variable) later. I just need to make sure I can send ‘greyness’ in the first place.
And in game I’ve tried variations of:
effectRenderPath:SetShaderParameter("Greyness",Vector3(1,1,1))
But no matter what I try, floats or vectors, I can’t seem to actually pass the value to the shader. If I set the value in the shader file manually it works, but to blend the monochrome I need to obviously set it live.
If I set cGreyness vec3 in GreyScale.glsl to Vec3(1,1,1) it’ll be flat white, as it should. 0,0,0 would be flat black. However I get a blackscreen no matter what I do with the SetShaderParameter.
Any ideas what it might be?