Archive 17/01/2023.

Scale along normals

1vanK

I’m trying to create shell for mesh

void VS()
{
    float offset = 0.1;
    mat4 modelMatrix = iModelMatrix;
    vec4 pos = iPos + vec4(iNormal * offset, 0.0);
    vec3 worldPos = (pos * modelMatrix).xyz;
    gl_Position = GetClipPos(worldPos);

but it works incorrect for sharp angles

(red mesh - scaled shell, white - original mesh)

How to fix it?

TikariSakari

This is my “outline” code, and it should scale things along normal, but I am not 100% sure if it works with sharp edges either. It inverts normals to give outline though

#include "Uniforms.glsl"
#include "Transform.glsl"

varying vec3 vNormal;

uniform vec4 cOutlineColor;
uniform float cOutLineThickness;


void VS()
{
    mat4 modelMatrix = iModelMatrix;
    vec3 worldPos = GetWorldPos(modelMatrix);

    worldPos += GetWorldNormal( modelMatrix ) * cOutLineThickness;
    vNormal = GetWorldNormal(modelMatrix) * - 1.0;
    
    gl_Position = GetClipPos(worldPos);
 
}

void PS()
{
    gl_FragColor = cOutlineColor;
}
thebluefish

This is an inherent limitation of that technique. So before we go into potential solutions, let’s look at our potential X/Y problem. What are you trying to accomplish?

1vanK

[quote=“TikariSakari”]This is my “outline” code, and it should scale things along normal, but I am not 100% sure if it works with sharp edges either. It inverts normals to give outline though

[code]
#include “Uniforms.glsl”
#include “Transform.glsl”

varying vec3 vNormal;

uniform vec4 cOutlineColor;
uniform float cOutLineThickness;

void VS()
{
mat4 modelMatrix = iModelMatrix;
vec3 worldPos = GetWorldPos(modelMatrix);

worldPos += GetWorldNormal( modelMatrix ) * cOutLineThickness;
vNormal = GetWorldNormal(modelMatrix) * - 1.0;

gl_Position = GetClipPos(worldPos);

}

void PS()
{
gl_FragColor = cOutlineColor;
}
[/code][/quote]

and where inverned vNormal is used?

OvermindDL1

Are you actually trying to encase it with something, or are you just trying to colorize it or render it differently without necessarily increasing the size? If so then you could just apply a shader on the original.

1vanK

gamedev.stackexchange.com/questi … ect-effect

1vanK

Previously, I created
github.com/1vanK/Urho3DOutline
but bluring is slow, so i try to using another method