Hey folks,
So I'm taking a rendering course this semester and we were given a framework in C++ to create functions for ray tracing etc., and I'm at an end were I'm supposed to add in a sample and shade function.
I've tried to implement something, but it's just returning a darker version of the image that I'm rendering, and I haven't been given an image that shows how it's supposed to look.
So I'm hoping that you guys can help me out a bit:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
| bool PointLight::sample(const float3& pos, float3& dir, float3& L) const {
if(!shadows) { return true; } float3 normal = normalize(pos - light_pos); Ray ray(pos, normal, 0, 1e-10f); HitInfo hit; if(tracer->trace_to_closest(ray, hit)) { float v = length(light_pos - pos); dir = normal; L = intensity / (v * v); return false; }
return true; } |
and
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
| float3 Lambertian::shade(const Ray& r, HitInfo& hit, bool emit) const { float3 rho_d = get_diffuse(hit); float3 result = make_float3(0.0f); float3 dir, radiance; float3 diffuse = (rho_d / M_PIf); for(size_t i = 0; i < lights.size(); i++) { if(lights[i]->sample(hit.position, dir, radiance)) { result += diffuse * radiance * dot(hit.shading_normal, dir); } } return result + Emission::shade(r, hit, emit); } |
The code runs, but it doesn't seem to "work," or at least I'm not sure what kind of image I'm supposed to get out of it.
Any help/insight would be awesome!
