-
Notifications
You must be signed in to change notification settings - Fork 32
Open
Description
I'm working on an simple ray tracer with code below
#version 430
out vec4 color;
uniform vec2 m_resolution;
const float INF = 1e9;
struct LightRay {
vec3 ro;
vec3 rd;
};
struct Sphere {
vec3 O;
float R;
};
struct Material {
vec3 color;
};
struct HitInfo {
bool didHit;
float d;
Material mati;
};
float sumcomp(vec3 v) {
return v.x+v.y+v.z;
}
Material sky(vec3 dir) {
return Material(vec3(0,0,0));
}
HitInfo rayTraceSphere(LightRay ray, Sphere sphere) {
vec3 ro = ray.ro - sphere.O;
vec3 rd = ray.rd;
float r = sphere.R;
float a = sumcomp(rd*rd), b = sumcomp(rd*ro)*2., c = sumcomp(ro*ro)-r*r;
float delta = b * b - 4. * a * c;
if (delta < 0) return HitInfo(false, INF, sky(rd));
float t1 = (-b + sqrt(delta)) / a * .5, t2 = (-b - sqrt(delta)) / a * .5;
if (t1 < 0 && t2 < 0) return HitInfo(false, INF, sky(rd));
if (t1 < 0 && t2 >= 0) return HitInfo(true, t2, Material(vec3(1,0,0)));
if (t2 < 0 && t1 >= 0) return HitInfo(true, t1, Material(vec3(1,0,0)));
return HitInfo(true, min(t1, t2), Material(vec3(1,0,0)));
}
HitInfo rayTrace(LightRay ray) {
return rayTraceSphere(ray, Sphere(vec3(0,0,0), 3.));
}
vec3 getCameraRay(vec2 uv, float focus) {
return normalize(vec3(uv, -focus));
}
void main(void) {
vec2 uv = (gl_FragCoord.xy - m_resolution.xy * .5) / m_resolution.xx * 2.;
vec3 rd = getCameraRay(uv, -5);
vec3 ro = vec3(0,0,-5);
LightRay ray = LightRay(ro, rd);
color = vec4(rayTrace(ray).d * .2,0,0,1.);
}
and when I tried to modify the last line color = vec4(rayTrace(ray).d * .2,0,0,1.); to color = vec4(rayTrace(ray).mati.color,1.);, VS crashed.
I think it can be some problems with member lists (I've tried many times and every time the member list opened, VS crashed.)
Metadata
Metadata
Assignees
Labels
No labels