Hey all! This is my first time trying to implement a shader (from john chapman graphics) in Urho3D. I’ve read as much documentation as I could find on the subject, but the shader will not work (no blatant visual errors, or other indicators at runtime). I am appending my xml file to the cloned renderpath of the primary viewport, and enabling it (so it’s probably me being noob with this post-processing pipeline and the shader too). Any ideas? Thanks a bunch in advance!
LensFlare.xml:
<renderpath>
<command type="quad" tag="LensFlare" vs="LensFlare" ps="LensFlare" output="viewport" blend="add" enabled="true">
<parameter name="Samples" value="8" />
<parameter name="Dispersal" value="0.25" />
<parameter name="HaloWidth" value="1.0" />
<parameter name="Distortion" value="1.0" />
<texture unit="InputTex" name="viewport" />
<texture unit="LensColor" name="Textures/lenscolor.png" />
</command>
</renderpath>
LensFlare.glsl
[code]/*******************************************************************************
Copyright © 2013 John Chapman
Edited for Urho3D by htmlboss (2016)
This software is distributed freely under the terms of the MIT License.
See "license.txt" or "http://copyfree.org/licenses/mit/license.txt".
*******************************************************************************/
//#include “common/def.glsl”
// Urho3D Stuff
#include “Uniforms.glsl”
#include “Samplers.glsl”
#include “Transform.glsl”
#include “ScreenPos.glsl”
layout(binding=0) uniform sampler2D sInputTex;
layout(binding=1) uniform sampler1D sLensColor;
const int MAX_SAMPLES = 64;
uniform int cSamples; // Samples for ghosting generation
uniform float cDispersal; // Ghosting dispersion factor
uniform float cHaloWidth; // Width of Halo
uniform float cDistortion; // Chromatic aberration factor
varying vec2 vScreenPos;
noperspective in vec2 vTexcoord; // 2D screen coords?
layout(location=0) out vec4 fResult; //Final output
/----------------------------------------------------------------------------/
vec4 textureDistorted(
in sampler2D tex,
in vec2 texcoord,
in vec2 direction,
in vec3 distortion
) {
return vec4(
texture(tex, texcoord + direction * distortion.r).r,
texture(tex, texcoord + direction * distortion.g).g,
texture(tex, texcoord + direction * distortion.b).b,
1.0
);
}
/----------------------------------------------------------------------------/
// Not doing anything here…
void VS() {
mat4 modelMatrix = iModelMatrix;
vec3 worldPos = GetWorldPos(modelMatrix);
gl_Position = GetClipPos(worldPos);
vTexcoord = GetQuadTexCoord(gl_Position); // Is this right??
vScreenPos = GetScreenPosPreDiv(gl_Position);
}
void PS() {
vec2 texcoord = -vTexcoord + vec2(1.0); // flip texcoords
vec2 texelSize = 1.0 / vec2(textureSize(sInputTex, 0));
vec2 ghostVec = (vec2(0.5) - texcoord) * cDispersal;
vec2 haloVec = normalize(ghostVec) * cHaloWidth;
vec3 distortion = vec3(-texelSize.x * cDistortion, 0.0, texelSize.x * cDistortion);
// sample ghosts:
vec4 result = vec4(0.0);
for (int i = 0; i < cSamples; ++i) {
vec2 offset = fract(texcoord + ghostVec * float(i));
float weight = length(vec2(0.5) - offset) / length(vec2(0.5));
weight = pow(1.0 - weight, 10.0);
result += textureDistorted(
sInputTex,
offset,
normalize(ghostVec),
distortion
) * weight;
}
result *= texture(sLensColor, length(vec2(0.5) - texcoord) / length(vec2(0.5)));
// sample halo:
float weight = length(vec2(0.5) - fract(texcoord + haloVec)) / length(vec2(0.5));
weight = pow(1.0 - weight, 10.0);
result += textureDistorted(
sInputTex,
fract(texcoord + haloVec),
normalize(ghostVec),
distortion
) * weight;
fResult = result; //Output final result
}
[/code]