Old version: github.com/1vanK/Urho3DOutline
Now with multiple colors and without coping of mesh
Renderpath
<renderpath>
<rendertarget name="outlineMask" sizedivisor="1 1" format="rgba" filter="true" />
<rendertarget name="outlineBlurredMaskH" sizedivisor="2 2" format="rgba" filter="true" />
<rendertarget name="outlineBlurredMaskV" sizedivisor="2 2" format="rgba" filter="true" />
<command type="clear" color="fog" depth="1.0" stencil="0" />
<command type="clear" color="0 0 0 0" output="outlineMask" />
<command type="scenepass" pass="base" vertexlights="true" metadata="base" />
<command type="forwardlights" pass="light" />
<command type="scenepass" pass="postopaque" />
<command type="scenepass" pass="refract">
<texture unit="environment" name="viewport" />
</command>
<command type="scenepass" pass="alpha" vertexlights="true" sort="backtofront" metadata="alpha" />
<command type="scenepass" pass="postalpha" sort="backtofront" />
<command type="scenepass" pass="outline" output="outlineMask" />
<command type="quad" vs="Outline" ps="Outline" psdefines="BLURH" output="outlineBlurredMaskH">
<texture unit="diffuse" name="outlineMask" />
</command>
<command type="quad" vs="Outline" ps="Outline" psdefines="BLURV" output="outlineBlurredMaskV">
<texture unit="diffuse" name="outlineBlurredMaskH" />
</command>
<command type="quad" vs="Outline" ps="Outline" psdefines="OUTPUT" output="viewport">
<texture unit="diffuse" name="outlineBlurredMaskV" />
<texture unit="normal" name="outlineMask" />
<texture unit="specular" name="viewport" />
</command>
</renderpath>
Outline.glsl
#include "Uniforms.glsl"
#include "Samplers.glsl"
#include "Transform.glsl"
#include "ScreenPos.glsl"
varying vec2 vTexCoord;
varying vec2 vScreenPos;
#ifdef COMPILEPS
uniform vec4 cOutlineColor;
uniform vec2 cOutlineBlurredMaskHInvSize;
#endif
void VS()
{
mat4 modelMatrix = iModelMatrix;
vec3 worldPos = GetWorldPos(modelMatrix);
gl_Position = GetClipPos(worldPos);
vTexCoord = GetQuadTexCoord(gl_Position);
vScreenPos = GetScreenPosPreDiv(gl_Position);
}
void PS()
{
#ifdef MASK
gl_FragColor = vec4(cOutlineColor.rgb, 1.0);
#endif
#ifdef BLURH
vec4 rgba = texture2D(sDiffMap, vTexCoord + vec2(0.0, 0.0) * cOutlineBlurredMaskHInvSize) * 0.2;
rgba += texture2D(sDiffMap, vTexCoord + vec2(-1.0, 0.0) * cOutlineBlurredMaskHInvSize) * 0.2;
rgba += texture2D(sDiffMap, vTexCoord + vec2(1.0, 0.0) * cOutlineBlurredMaskHInvSize) * 0.2;
rgba += texture2D(sDiffMap, vTexCoord + vec2(-2.0, 0.0) * cOutlineBlurredMaskHInvSize) * 0.2;
rgba += texture2D(sDiffMap, vTexCoord + vec2(2.0, 0.0) * cOutlineBlurredMaskHInvSize) * 0.2;
gl_FragColor = rgba;
#endif
#ifdef BLURV
vec4 rgba = texture2D(sDiffMap, vTexCoord + vec2(0.0, 0.0) * cOutlineBlurredMaskHInvSize) * 0.2;
rgba += texture2D(sDiffMap, vTexCoord + vec2(0.0, -1.0) * cOutlineBlurredMaskHInvSize) * 0.2;
rgba += texture2D(sDiffMap, vTexCoord + vec2(0.0, 1.0) * cOutlineBlurredMaskHInvSize) * 0.2;
rgba += texture2D(sDiffMap, vTexCoord + vec2(0.0, -2.0) * cOutlineBlurredMaskHInvSize) * 0.2;
rgba += texture2D(sDiffMap, vTexCoord + vec2(0.0, 2.0) * cOutlineBlurredMaskHInvSize) * 0.2;
gl_FragColor = rgba;
#endif
#ifdef OUTPUT
vec4 blurredMask = texture2D(sDiffMap, vTexCoord);
vec4 mask = texture2D(sNormalMap, vTexCoord);
vec4 viewport = texture2D(sSpecMap, vTexCoord);
blurredMask = clamp(blurredMask - mask.a, 0.0, 1.0);
blurredMask *= 2.0;
gl_FragColor = viewport + blurredMask;
#endif
}
Techniques/NoTextureOutline.xml
<technique vs="LitSolid" ps="LitSolid" vsdefines="NOUV" >
<pass name="base" />
<pass name="litbase" psdefines="AMBIENT" />
<pass name="light" depthtest="equal" depthwrite="false" blend="add" />
<pass name="prepass" psdefines="PREPASS" />
<pass name="material" psdefines="MATERIAL" depthtest="equal" depthwrite="false" />
<pass name="deferred" psdefines="DEFERRED" />
<pass name="depth" vs="Depth" ps="Depth" />
<pass name="shadow" vs="Shadow" ps="Shadow" />
<pass name="outline" vs="Outline" ps="Outline" psdefines="MASK" depthwrite="false" />
</technique>
Material
<material>
<technique name="Techniques/NoTextureOutline.xml" />
<parameter name="MatDiffColor" value="1 1 1 1" />
<parameter name="MatSpecColor" value="1 1 1 300" />
<parameter name="OutlineColor" value="1 0 0 0" />
</material>
EDIT: Example topic1840-10.html#p10978