-
-
Notifications
You must be signed in to change notification settings - Fork 158
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cfc2c1e
commit 345a0ce
Showing
5 changed files
with
182 additions
and
128 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,35 @@ | ||
varying vec2 vTextureCoord; | ||
in vec2 vTextureCoord; | ||
out vec4 finalColor; | ||
|
||
uniform sampler2D uSampler; | ||
uniform sampler2D colorMap; | ||
uniform float _mix; | ||
uniform float _size; | ||
uniform float _sliceSize; | ||
uniform float _slicePixelSize; | ||
uniform float _sliceInnerSize; | ||
void main() { | ||
vec4 color = texture2D(uSampler, vTextureCoord.xy); | ||
uniform sampler2D uMapTexture; | ||
uniform float uMix; | ||
uniform float uSize; | ||
uniform float uSliceSize; | ||
uniform float uSlicePixelSize; | ||
uniform float uSliceInnerSize; | ||
|
||
void main() { | ||
vec4 color = texture(uSampler, vTextureCoord.xy); | ||
vec4 adjusted; | ||
|
||
if (color.a > 0.0) { | ||
color.rgb /= color.a; | ||
float innerWidth = _size - 1.0; | ||
float innerWidth = uSize - 1.0; | ||
float zSlice0 = min(floor(color.b * innerWidth), innerWidth); | ||
float zSlice1 = min(zSlice0 + 1.0, innerWidth); | ||
float xOffset = _slicePixelSize * 0.5 + color.r * _sliceInnerSize; | ||
float s0 = xOffset + (zSlice0 * _sliceSize); | ||
float s1 = xOffset + (zSlice1 * _sliceSize); | ||
float yOffset = _sliceSize * 0.5 + color.g * (1.0 - _sliceSize); | ||
vec4 slice0Color = texture2D(colorMap, vec2(s0,yOffset)); | ||
vec4 slice1Color = texture2D(colorMap, vec2(s1,yOffset)); | ||
float xOffset = uSlicePixelSize * 0.5 + color.r * uSliceInnerSize; | ||
float s0 = xOffset + (zSlice0 * uSliceSize); | ||
float s1 = xOffset + (zSlice1 * uSliceSize); | ||
float yOffset = uSliceSize * 0.5 + color.g * (1.0 - uSliceSize); | ||
vec4 slice0Color = texture(uMapTexture, vec2(s0,yOffset)); | ||
vec4 slice1Color = texture(uMapTexture, vec2(s1,yOffset)); | ||
float zOffset = fract(color.b * innerWidth); | ||
adjusted = mix(slice0Color, slice1Color, zOffset); | ||
|
||
color.rgb *= color.a; | ||
} | ||
gl_FragColor = vec4(mix(color, adjusted, _mix).rgb, color.a); | ||
|
||
finalColor = vec4(mix(color, adjusted, uMix).rgb, color.a); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
struct ColorMapUniforms { | ||
uMix: f32, | ||
uSize: f32, | ||
uSliceSize: f32, | ||
uSlicePixelSize: f32, | ||
uSliceInnerSize: f32, | ||
}; | ||
|
||
@group(0) @binding(1) var uSampler: texture_2d<f32>; | ||
@group(1) @binding(0) var<uniform> colorMapUniforms : ColorMapUniforms; | ||
@group(1) @binding(1) var uMapTexture: texture_2d<f32>; | ||
|
||
@fragment | ||
fn mainFragment( | ||
@builtin(position) position: vec4<f32>, | ||
@location(0) uv : vec2<f32> | ||
) -> @location(0) vec4<f32> { | ||
var color:vec4<f32> = textureSample(uSampler, uSampler, uv); | ||
|
||
var adjusted: vec4<f32>; | ||
|
||
var altColor: vec4<f32> = vec4<f32>(color.rgb / color.a, color.a); | ||
let innerWidth: f32 = colorMapUniforms.uSize - 1.0; | ||
let zSlice0: f32 = min(floor(color.b * innerWidth), innerWidth); | ||
let zSlice1: f32 = min(zSlice0 + 1.0, innerWidth); | ||
let xOffset: f32 = colorMapUniforms.uSlicePixelSize * 0.5 + color.r * colorMapUniforms.uSliceInnerSize; | ||
let s0: f32 = xOffset + (zSlice0 * colorMapUniforms.uSliceSize); | ||
let s1: f32 = xOffset + (zSlice1 * colorMapUniforms.uSliceSize); | ||
let yOffset: f32 = colorMapUniforms.uSliceSize * 0.5 + color.g * (1.0 - colorMapUniforms.uSliceSize); | ||
let slice0Color: vec4<f32> = textureSample(uMapTexture, iSampler, vec2(s0,yOffset)); | ||
let slice1Color: vec4<f32> = textureSample(uMapTexture, iSampler, vec2(s1,yOffset)); | ||
let zOffset: f32 = fract(color.b * innerWidth); | ||
adjusted = mix(slice0Color, slice1Color, zOffset); | ||
altColor = vec4<f32>(color.rgb * color.a, color.a); | ||
|
||
let realColor: vec4<f32> = select(color, altColor, color.a > 0.0); | ||
|
||
return vec4<f32>(mix(realColor, adjusted, colorMapUniforms.uMix).rgb, realColor.a); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.