Skip to content
Snippets Groups Projects
Commit 24a07538 authored by AronKovacs's avatar AronKovacs
Browse files

fix fog for outlines

parent 94d293a4
No related branches found
No related tags found
No related merge requests found
...@@ -183,6 +183,7 @@ const PostprocessingSchema = { ...@@ -183,6 +183,7 @@ const PostprocessingSchema = {
uTexSize: UniformSpec('v2'), uTexSize: UniformSpec('v2'),
dOrthographic: DefineSpec('number'), dOrthographic: DefineSpec('number'),
uInvProjection: UniformSpec('m4'),
uNear: UniformSpec('f'), uNear: UniformSpec('f'),
uFar: UniformSpec('f'), uFar: UniformSpec('f'),
uFogNear: UniformSpec('f'), uFogNear: UniformSpec('f'),
...@@ -211,6 +212,7 @@ function getPostprocessingRenderable(ctx: WebGLContext, colorTexture: Texture, d ...@@ -211,6 +212,7 @@ function getPostprocessingRenderable(ctx: WebGLContext, colorTexture: Texture, d
uTexSize: ValueCell.create(Vec2.create(colorTexture.getWidth(), colorTexture.getHeight())), uTexSize: ValueCell.create(Vec2.create(colorTexture.getWidth(), colorTexture.getHeight())),
dOrthographic: ValueCell.create(0), dOrthographic: ValueCell.create(0),
uInvProjection: ValueCell.create(Mat4.identity()),
uNear: ValueCell.create(1), uNear: ValueCell.create(1),
uFar: ValueCell.create(10000), uFar: ValueCell.create(10000),
uFogNear: ValueCell.create(10000), uFogNear: ValueCell.create(10000),
...@@ -408,6 +410,7 @@ export class PostprocessingPass { ...@@ -408,6 +410,7 @@ export class PostprocessingPass {
ValueCell.updateIfChanged(this.outlinesRenderable.values.uFar, camera.far); ValueCell.updateIfChanged(this.outlinesRenderable.values.uFar, camera.far);
ValueCell.updateIfChanged(this.outlinesRenderable.values.uMaxPossibleViewZDiff, maxPossibleViewZDiff); ValueCell.updateIfChanged(this.outlinesRenderable.values.uMaxPossibleViewZDiff, maxPossibleViewZDiff);
ValueCell.updateIfChanged(this.renderable.values.uInvProjection, invProjection);
ValueCell.updateIfChanged(this.renderable.values.uMaxPossibleViewZDiff, maxPossibleViewZDiff); ValueCell.updateIfChanged(this.renderable.values.uMaxPossibleViewZDiff, maxPossibleViewZDiff);
let fogColor = Vec3(); let fogColor = Vec3();
Color.toVec3Normalized(fogColor, backgroundColor); Color.toVec3Normalized(fogColor, backgroundColor);
......
...@@ -16,6 +16,7 @@ uniform sampler2D tDepth; ...@@ -16,6 +16,7 @@ uniform sampler2D tDepth;
uniform sampler2D tOutlines; uniform sampler2D tOutlines;
uniform vec2 uTexSize; uniform vec2 uTexSize;
uniform mat4 uInvProjection;
uniform float uNear; uniform float uNear;
uniform float uFar; uniform float uFar;
uniform float uFogNear; uniform float uFogNear;
...@@ -66,7 +67,7 @@ float getOutline(const in vec2 coords, out float closestTexel) { ...@@ -66,7 +67,7 @@ float getOutline(const in vec2 coords, out float closestTexel) {
float selfViewZ = isBackground(selfDepth) ? backgroundViewZ : getViewZ(getDepth(coords)); float selfViewZ = isBackground(selfDepth) ? backgroundViewZ : getViewZ(getDepth(coords));
float outline = 1.0; float outline = 1.0;
closestTexel = 1.0; closestTexel = backgroundViewZ;
for (float y = -uOutlineScale; y <= uOutlineScale; y++) { for (float y = -uOutlineScale; y <= uOutlineScale; y++) {
for (float x = -uOutlineScale; x <= uOutlineScale; x++) { for (float x = -uOutlineScale; x <= uOutlineScale; x++) {
if (x * x + y * y > uOutlineScale * uOutlineScale) { if (x * x + y * y > uOutlineScale * uOutlineScale) {
...@@ -79,7 +80,9 @@ float getOutline(const in vec2 coords, out float closestTexel) { ...@@ -79,7 +80,9 @@ float getOutline(const in vec2 coords, out float closestTexel) {
float sampleOutline = sampleOutlineCombined.r; float sampleOutline = sampleOutlineCombined.r;
float sampleOutlineDepth = unpackRGToUnitInterval(sampleOutlineCombined.gb); float sampleOutlineDepth = unpackRGToUnitInterval(sampleOutlineCombined.gb);
if (sampleOutline == 0.0 && sampleOutlineDepth < closestTexel && abs(selfViewZ - sampleOutlineDepth) > uMaxPossibleViewZDiff) { float sampleOutlineViewDirLength = length(screenSpaceToViewSpace(vec3(sampleCoords, sampleOutlineDepth), uInvProjection));
if (sampleOutline == 0.0 && sampleOutlineViewDirLength < closestTexel && abs(selfViewZ - sampleOutlineDepth) > uMaxPossibleViewZDiff) {
outline = 0.0; outline = 0.0;
closestTexel = sampleOutlineDepth; closestTexel = sampleOutlineDepth;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment