Skip to content

Instantly share code, notes, and snippets.

@BeRo1985
Last active December 22, 2016 14:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BeRo1985/3a47c5be8b08381edb2d670a13bca606 to your computer and use it in GitHub Desktop.
Save BeRo1985/3a47c5be8b08381edb2d670a13bca606 to your computer and use it in GitHub Desktop.
Intel GLSL function-inlining compiler bug testcase
Results see https://youtu.be/u0dNKo70X8s
///////// Fragment shader: //////////
#version 430
in vec2 vTexCoord;
uniform vec2 resolution; // the canvas resolution size
layout(location = 0) out vec4 oColor;
#if 1
float opUnion(const in float d1, const in float d2){
return min(d1, d2);
}
float opSub(const in float d1, const in float d2){
return max(d1, -d2);
}
float opIntersection(const in float d1, const in float d2){
return max(d1, d2);
}
#else
#define opUnion min
#define opSub(d1,d2) max((d1), -(d2))
#define opIntersection max
#endif
float map(vec3 p){
float d = 1e+14;
{
vec3 lp = p - vec3(0.0, 0.0, 0.0);
d = min(d, length(lp) - 2.0);
}
{
vec3 lp = p - vec3(0.0, -7.0, -3.0);
#if 0
float temp = opSub(length(lp.xz) - 5.25, lp.y - 6.0);
d = opSub(d, temp);
#else
d = opSub(d, opSub(length(lp.xz) - 5.25, lp.y - 6.0));
#endif
}
return d;
}
vec3 getNormal(vec3 p){
vec2 e = vec2(0.0, 1e-4);
return normalize(vec3(map(p + e.yxx) - map(p - e.yxx),
map(p + e.xyx) - map(p - e.xyx),
map(p + e.xxy) - map(p - e.xxy)));
}
void main(){
vec2 q = ((vTexCoord * 2.0) - vec2(1.0)) * vec2(1.0, resolution.y / resolution.x);
vec3 c = vec3(0.0, 0.5, 0.0),
ro = vec3(0.0, 0.0, 8.0),
rd = normalize(vec3(q, -1.0));
bool hit = false;
float t = 0.0, d = 0.0;
vec3 p = ro;
for(int i = 0; i < 64; i++){
if((d = map(p = ro + (rd * (t += d)))) < 1e-4){
hit = true;
break;
}
}
if(hit){
vec3 n = getNormal(p);
c = vec3(max(0.0, dot(n, vec3(0.0, 0.0, 1.0))));
}
oColor = vec4(c, 1.0);
}
///////// Vertex shader (for attribute-less oversized fullscreen single-triangle rendering): //////////
#version 430
out vec2 vTexCoord;
void main(){
vTexCoord = vec2((gl_VertexID >> 1) * 2.0, (gl_VertexID & 1) * 2.0);
gl_Position = vec4(((gl_VertexID >> 1) * 4.0) - 1.0, ((gl_VertexID & 1) * 4.0) - 1.0, 0.0, 1.0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment