Skip to content

Instantly share code, notes, and snippets.

@BeRo1985
Last active Dec 22, 2016
Embed
What would you like to do?
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