Skip to content

Commit

Permalink
Merge pull request #43 from JuliaPlots/sd-fixAMD
Browse files Browse the repository at this point in the history
fix amd gpu
  • Loading branch information
SimonDanisch authored Sep 12, 2019
2 parents 8bb3a48 + d393e63 commit 123a89c
Showing 1 changed file with 17 additions and 12 deletions.
29 changes: 17 additions & 12 deletions src/GLVisualize/assets/shader/intensity.frag
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,17 @@ uniform float levels;

vec4 getindex(sampler2D image, vec2 uv){return texture(image, vec2(uv.x, 1-uv.y));}
vec4 getindex(sampler1D image, vec2 uv){return texture(image, uv.y);}
float _normalize(float val, float from, float to){return (val-from) / (to - from);}
float clamp_01(float val, float from, float to){
return clamp((val - from) / (to - from), 0.0, 1.0);
}

vec4 color_lookup(float intensity, sampler1D color_ramp, vec2 norm){
return texture(color_ramp, _normalize(intensity, norm.x, norm.y));
return texture(color_ramp, clamp_01(intensity, norm.x, norm.y));
}

#define ALIASING_CONST 0.70710678118654757
#define M_PI 3.1415926535897932384626433832795

float aastep(float threshold1, float threshold2, float value) {
float afwidth = length(vec2(dFdx(value), dFdy(value))) * ALIASING_CONST;
return smoothstep(threshold1-afwidth, threshold1+afwidth, value)-smoothstep(threshold2-afwidth, threshold2+afwidth, value);
Expand All @@ -31,16 +35,17 @@ void write2framebuffer(vec4 color, uvec2 id);

void main(){
float i = float(getindex(intensity, o_uv).x);
vec4 color;
if(isnan(i)){
color = vec4(0);
}else{
i = _normalize(i, color_norm.x, color_norm.y);
float lines = i*levels;
lines = abs(fract(lines-0.5));
float half_stroke = stroke_width*0.5;
lines = aastep(0.5 - half_stroke, 0.5 + half_stroke, lines);
color = mix(texture(color_map, i), stroke_color, lines);
i = clamp_01(i, color_norm.x, color_norm.y);
vec4 color = vec4(0);
if(!isnan(i)){
color = texture(color_map, i);
if(stroke_width > 0.0){
float lines = i * levels;
lines = abs(fract(lines - 0.5));
float half_stroke = stroke_width * 0.5;
lines = aastep(0.5 - half_stroke, 0.5 + half_stroke, lines);
color = mix(color, stroke_color, lines);
}
}
write2framebuffer(color, uvec2(o_objectid.x, 0));
}

0 comments on commit 123a89c

Please sign in to comment.