So I've got the ray tracer to the point where it does chromatic aberration. I would also like to add in Fresnel reflection-refraction. I've been trying many codes, but none seem to do the trick, Any one with ideas?
The code is at: https://github.com/sjhalayka/sw_partial_reflectivity
The gist of it is:
for(int i = current_buffer_index - 1; i >= 0; i--)
{
float accum = rays[i].base_color;
// Fresnel code from some random book chapter that I can't find using Google any more
const float eta = (red_eta + green_eta + blue_eta)/3.0;
const float FresnelPower = 1.0;
const float F = ((1.0 - eta) * (1.0 - eta)) / ((1.0 + eta) * (1.0 + eta));
const vec3 incident = normalize(rays[i].direction.xyz);
const vec3 normal = normalize(rays[i].normal);
float Ratio = F + (1.0 - F) * pow((1.0 - dot(-incident, normal)), FresnelPower);
float mixed_color = 0.0;
if(rays[i].child_reflect_id != -1 && rays[i].child_refract_id != -1)
mixed_color = mix(rays[rays[i].child_refract_id].accumulated_color, rays[rays[i].child_reflect_id].accumulated_color, Ratio);
else if(rays[i].child_reflect_id != -1)
mixed_color = rays[rays[i].child_reflect_id].accumulated_color;
else if(rays[i].child_refract_id != -1)
mixed_color = rays[rays[i].child_refract_id].accumulated_color;
accum = mix(accum, mixed_color, 1.0 - rays[i].refraction_constant);
rays[i].accumulated_color = accum;
}
Where the basic non-Fresnel accumulator is:
for(int i = current_buffer_index - 1; i >= 0; i--)
{
float accum = rays[i].base_color;
if(rays[i].child_reflect_id != -1)
accum = mix(accum, rays[rays[i].child_reflect_id].accumulated_color, rays[i].reflection_constant);
if(rays[i].child_refract_id != -1)
accum = mix(accum, rays[rays[i].child_refract_id].accumulated_color, 1.0 - rays[i].refraction_constant);
rays[i].accumulated_color = accum;
}