Skip to content

Commit

Permalink
made eye dome lighting support different resolution scales
Browse files Browse the repository at this point in the history
  • Loading branch information
IanLilleyT committed Oct 8, 2019
1 parent 7269eb7 commit 7203c9d
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 20 deletions.
13 changes: 6 additions & 7 deletions Source/Scene/PointCloudEyeDomeLighting.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Cartesian3 from '../Core/Cartesian3.js';
import Cartesian2 from '../Core/Cartesian2.js';
import Color from '../Core/Color.js';
import defined from '../Core/defined.js';
import destroyObject from '../Core/destroyObject.js';
Expand Down Expand Up @@ -111,7 +111,7 @@ import PointCloudEyeDomeLightingShader from '../Shaders/PostProcessStages/PointC
processor._depthTexture = depthTexture;
}

var distancesAndEdlStrengthScratch = new Cartesian3();
var distanceAndEdlStrengthScratch = new Cartesian2();

function createCommands(processor, context) {
var blendFS = PointCloudEyeDomeLightingShader;
Expand All @@ -123,11 +123,10 @@ import PointCloudEyeDomeLightingShader from '../Shaders/PostProcessStages/PointC
u_pointCloud_depthGBuffer : function() {
return processor._depthGBuffer;
},
u_distancesAndEdlStrength : function() {
distancesAndEdlStrengthScratch.x = processor._radius / context.drawingBufferWidth;
distancesAndEdlStrengthScratch.y = processor._radius / context.drawingBufferHeight;
distancesAndEdlStrengthScratch.z = processor._strength;
return distancesAndEdlStrengthScratch;
u_distanceAndEdlStrength : function() {
distanceAndEdlStrengthScratch.x = processor._radius;
distanceAndEdlStrengthScratch.y = processor._strength;
return distanceAndEdlStrengthScratch;
}
};

Expand Down
37 changes: 24 additions & 13 deletions Source/Shaders/PostProcessStages/PointCloudEyeDomeLighting.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,27 @@

uniform sampler2D u_pointCloud_colorGBuffer;
uniform sampler2D u_pointCloud_depthGBuffer;
uniform vec3 u_distancesAndEdlStrength;
uniform vec2 u_distanceAndEdlStrength;
varying vec2 v_textureCoordinates;

vec2 neighborContribution(float log2Depth, vec2 padding)
vec2 neighborContribution(float log2Depth, vec2 offset)
{
float depthOrLogDepth = czm_unpackDepth(texture2D(u_pointCloud_depthGBuffer, v_textureCoordinates + padding));
if (depthOrLogDepth == 0.0) { // 0.0 is the clear value for the gbuffer
float dist = u_distanceAndEdlStrength.x;
vec2 texCoordOrig = v_textureCoordinates + offset * dist;
vec2 texCoord0 = v_textureCoordinates + offset * floor(dist);
vec2 texCoord1 = v_textureCoordinates + offset * ceil(dist);

float depthOrLogDepth0 = czm_unpackDepth(texture2D(u_pointCloud_depthGBuffer, texCoord0));
float depthOrLogDepth1= czm_unpackDepth(texture2D(u_pointCloud_depthGBuffer, texCoord1));

// ignore depth values that are the clear depth
if (depthOrLogDepth0 == 0.0 || depthOrLogDepth1 == 0.0) {
return vec2(0.0);
}
vec4 eyeCoordinate = czm_windowToEyeCoordinates(v_textureCoordinates + padding, depthOrLogDepth);

// interpolate the two adjacent depth values
float depthMix = mix(depthOrLogDepth0, depthOrLogDepth1, fract(dist));
vec4 eyeCoordinate = czm_windowToEyeCoordinates(texCoordOrig, depthMix);
return vec2(max(0.0, log2Depth - log2(-eyeCoordinate.z / eyeCoordinate.w)), 1.0);
}

Expand All @@ -31,19 +42,19 @@ void main()

vec4 color = texture2D(u_pointCloud_colorGBuffer, v_textureCoordinates);

// sample from neighbors up, down, left, right
float distX = u_distancesAndEdlStrength.x;
float distY = u_distancesAndEdlStrength.y;
// sample from neighbors left, right, down, up
vec2 texelSize = 1.0 / czm_viewport.zw;

vec2 responseAndCount = vec2(0.0);

responseAndCount += neighborContribution(log2Depth, vec2(0, distY));
responseAndCount += neighborContribution(log2Depth, vec2(distX, 0));
responseAndCount += neighborContribution(log2Depth, vec2(0, -distY));
responseAndCount += neighborContribution(log2Depth, vec2(-distX, 0));
responseAndCount += neighborContribution(log2Depth, vec2(-texelSize.x, 0.0));
responseAndCount += neighborContribution(log2Depth, vec2(+texelSize.x, 0.0));
responseAndCount += neighborContribution(log2Depth, vec2(0.0, -texelSize.y));
responseAndCount += neighborContribution(log2Depth, vec2(0.0, +texelSize.y));

float response = responseAndCount.x / responseAndCount.y;
float shade = exp(-response * 300.0 * u_distancesAndEdlStrength.z);
float strength = u_distanceAndEdlStrength.y;
float shade = exp(-response * 300.0 * strength);
color.rgb *= shade;
gl_FragColor = vec4(color);

Expand Down

0 comments on commit 7203c9d

Please sign in to comment.