Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- float pi = 3.14159265358979323846;
- // Raytrace renderer.
- static vec4f trace_raytrace(const rtr::scene* scene, const ray3f& ray,
- int bounce, rng_state& rng, const trace_params& params) {
- // intersect next point
- auto inter = intersect_scene_bvh(scene, ray);
- if(!inter.hit) {return {eval_environment(scene, ray), 1};}
- // evaluate geometry
- auto& el = inter.element;
- auto& forma = scene -> objects[inter.object];
- auto new_position = transform_point(forma -> frame, eval_position(forma -> shape, el, inter.uv));
- // normal corrections
- auto normal = transform_direction(forma -> frame, eval_normal(forma -> shape, el, inter.uv));
- // evaluate material
- auto material = forma -> material;
- auto temp_coord = eval_texcoord(scene -> objects[inter.object] -> shape, el, inter.uv);
- vec2f coord = vec2f{fmod(temp_coord.x, 1), fmod(temp_coord.y, 1)};
- auto color = forma -> material -> color * eval_texture(material -> color_tex, coord);
- auto radiance = forma -> material -> emission;
- auto outgoing = -ray.d;
- // handle opacity
- // accumulate emission
- // exit if enough bounces are done
- if (bounce >= params.bounces) {return {radiance, 1};}
- // compute indirect illumination
- auto ambient = sample_hemisphere(normal, rand2f(rng));
- // transmission -> polished dielectric
- if (material -> transmission) {
- if (rand1f(rng) < mean(fresnel_schlick(vec3f(0.04f), normal, outgoing))) {
- auto incoming = reflect(outgoing, normal);
- radiance += xyz(trace_raytrace(scene, ray3f{new_position, incoming}, ++bounce, rng, params));}
- else {
- auto incoming = -outgoing;
- radiance += color * xyz(trace_raytrace(scene, ray3f{new_position, incoming}, ++bounce, rng, params));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement