//reflect across the line containing points p and q point reflect(const point & p, const point & q) const { if (p == q) return reflect(p); point r(*this - p), s = q - p; r = point(r.x * s.x + r.y * s.y, r.x * s.y - r.y * s.x) / s.norm(); r = point(r.x * s.x - r.y * s.y, r.x * s.y + r.y * s.x) + p; return r; }
Spectrum eval(const BSDFSamplingRecord &bRec, EMeasure measure) const { if (Frame::cosTheta(bRec.wi) <= 0 || Frame::cosTheta(bRec.wo) <= 0 || measure != ESolidAngle) return Spectrum(0.0f); bool hasSpecular = (bRec.typeMask & EGlossyReflection) && (bRec.component == -1 || bRec.component == 0); bool hasDiffuse = (bRec.typeMask & EDiffuseReflection) && (bRec.component == -1 || bRec.component == 1); Spectrum result(0.0f); if (hasSpecular) { Float alpha = dot(bRec.wo, reflect(bRec.wi)), exponent = m_exponent->eval(bRec.its).average(); if (alpha > 0.0f) { result += m_specularReflectance->eval(bRec.its) * ((exponent + 2) * INV_TWOPI * std::pow(alpha, exponent)); } } if (hasDiffuse) result += m_diffuseReflectance->eval(bRec.its) * INV_PI; return result * Frame::cosTheta(bRec.wo); }
static void gentab(int bits, uint64 poly, int reflected) { int i; uint64 topbit = 1ULL << (bits-1); uint64 mask = ~0ULL >> (64-bits); for (i = 0; i < 256; ++i) { uint64 crc = i; int j; if (reflected) crc = reflect(crc, 8); crc <<= bits - 8; for (j = 0; j < 8; ++j) crc = (crc << 1) ^ ((crc & topbit) ? poly : 0); if (reflected) crc = reflect(crc, bits); crctab[i] = crc & mask; } }
void RunFloat2Or3Tests(std::string const& typeName) { RunCommonVectorTests<T>(typeName); RunPerfTest<T, T>(typeName + " reflect", [](T* value, T const& param) { *value = reflect(*value, param); }); RunPerfTest<T, float4x4>(typeName + " transform_normal (float4x4)", [](T* value, float4x4 const& param) { *value = transform_normal(*value, param); }); RunPerfTest<T, float4x4>(typeName + " transform4 (float4x4)", [](T* value, float4x4 const& param) { float4 t = transform4(*value, param); value->x = t.x + t.y + t.z + t.w; }); RunPerfTest<T, quaternion>(typeName + " transform4 (quaternion)", [](T* value, quaternion const& param) { float4 t = transform4(*value, param); value->x = t.x + t.y + t.z + t.w; }); }
t_double3 color_diffused(t_scene *scene, t_surface *surface, t_vector ray) { t_double3 color_hit; t_light *light; int light_nb; double dot_light; t_surface *light_intersect; t_double3 reflected; color_hit = (t_double3){0, 0, 0}; light = scene->light; light_nb = 0; while (light) { light_intersect = is_in_light(surface, scene, light, &dot_light); if (light_intersect->object == NULL || light_intersect->distance > 0) { color_hit = v_plus_v(color_hit, color_mix(scale_v(light->color, dot_light), surface->object->gloss, // scale_v(surface->object->color, dot_light))); scale_v(surface->color, dot_light))); reflected = reflect(scale_v(normalize(v_minus_v(light->pos, surface->point)), -1), surface->normal); color_hit = v_plus_v(color_hit, scale_v(light->color, pow(max_double(0, -dot_product(reflected, ray.dir) * surface->object->gloss), 2))); } free(light_intersect); light_nb++; light = light->next; } if (light_nb > 1) color_hit = scale_v(color_hit, (1.0 / (double)light_nb)); return (color_hit); }
color getPhong( const normal& i_N, const vector& i_V, const float cosinePower, const eiBool i_keyLightsOnly, const eiBool unshadowed) { color C = 0.0f; vector R = reflect( normalize(i_V), normalize(i_N) ); LightSampler sampler(this, P, i_N, PI/2.0f ); float isKeyLight = 1; //if( i_keyLightsOnly != 0 ) //{ // lightsource( "iskeylight", isKeyLight ); //} if( isKeyLight != 0 ) { const float nonspecular = 0.0f; //lightsource( "__nonspecular", nonspecular ); if( nonspecular < 1 ) { //SAMPLE_LIGHT_2(color, C, 0.0f, // C += Cl()*pow(max<float>(0.0f,R%Ln),cosinePower)*(1.0f-nonspecular); //); while (sampler.sample()) { vector Ln = normalize(L); C += Cl*pow(max<float>(0.0f,R%Ln),cosinePower)*(1.0f-nonspecular); } } } return C; }
void D3DShaderObjectProvider::find_locations() { sampler_locations.clear(); texture_locations.clear(); uniform_buffer_locations.clear(); if (d3dcompiler_dll) // If the compiler is available, we must use it! This ensures compatility with the blob { ComPtr<ID3D11ShaderReflection> reflect; HRESULT result = d3dreflect(bytecode.get_data(), bytecode.get_size(), IID_ID3D11ShaderReflection, (void**)reflect.output_variable()); D3DTarget::throw_if_failed("D3DReflect failed", result); D3D11_SHADER_DESC desc; result = reflect->GetDesc(&desc); D3DTarget::throw_if_failed("D3DReflect.GetDesc failed", result); for (UINT i = 0; i < desc.BoundResources; i++) { D3D11_SHADER_INPUT_BIND_DESC binding; result = reflect->GetResourceBindingDesc(i, &binding); D3DTarget::throw_if_failed("D3DReflect.GetResourceBindingDesc failed", result); set_binding(binding); } } else { DXBC_Reflect reflect(bytecode.get_data(), bytecode.get_size()); for (size_t cnt = 0; cnt < reflect.binding.size(); cnt++) { set_binding(reflect.binding[cnt]); } } }
color getPhong( const normal& i_N, const vector& i_V, const float cosinePower, const eiBool i_keyLightsOnly, const eiBool unshadowed) { color C = 0; vector R = reflect( normalize(i_V), normalize(i_N) ); while( illuminance( P(), i_N, PI/2.0f ) ) { float isKeyLight = 1; //if( i_keyLightsOnly != 0 ) //{ // lightsource( "iskeylight", isKeyLight ); //} if( isKeyLight != 0 ) { const float nonspecular = 0.0f; //lightsource( "__nonspecular", nonspecular ); if( nonspecular < 1 ) { vector Ln = normalize(L()); SAMPLE_LIGHT_2(color, C, 0.0f, C += Cl()*pow(max<float>(0.0f,R%Ln),cosinePower)*(1.0f-nonspecular); ); } }
Ray Ray::refract(const HitInfo& hit) const { Vector3 n; // indices of refraction float n1 = 1.0f; float n2 = 1.0f; if (dot(hit.N, this->d) < 0) { // entering object n2 = hit.material->getRefractionIndex(); n = hit.N; } else { // leaving object n1 = hit.material->getRefractionIndex(); n = -hit.N; } // compute energy of refracted ray ( cos^2 (theta2) ) float cosTheta1 = dot(this->d, n); // NOTE: should this be n or hit.N? float e = 1 - ((n1*n1) / (n2*n2)) * (1 - cosTheta1*cosTheta1); // total internal reflection if (e < 0.0f) return reflect(hit); // create refraction ray Vector3 dir = (n1 / n2) * (this->d - n * cosTheta1) - n * (sqrt(e)); Vector3 origin = hit.P + (dir * epsilon); return Ray(origin, dir); }
Float pdf(const BSDFSamplingRecord &bRec, EMeasure measure) const { if (Frame::cosTheta(bRec.wi) <= 0 || Frame::cosTheta(bRec.wo) <= 0 || measure != ESolidAngle) return 0.0f; bool hasSpecular = (bRec.typeMask & EGlossyReflection) && (bRec.component == -1 || bRec.component == 0); bool hasDiffuse = (bRec.typeMask & EDiffuseReflection) && (bRec.component == -1 || bRec.component == 1); Float diffuseProb = 0.0f, specProb = 0.0f; if (hasDiffuse) diffuseProb = warp::squareToCosineHemispherePdf(bRec.wo); if (hasSpecular) { Float alpha = dot(bRec.wo, reflect(bRec.wi)), exponent = m_exponent->eval(bRec.its).average(); if (alpha > 0) specProb = std::pow(alpha, exponent) * (exponent + 1.0f) / (2.0f * M_PI); } if (hasDiffuse && hasSpecular) return m_specularSamplingWeight * specProb + (1-m_specularSamplingWeight) * diffuseProb; else if (hasDiffuse) return diffuseProb; else if (hasSpecular) return specProb; else return 0.0f; }
void Douille::update(float pDelay, Map * map) { CVector3f lastPos = position; delay -= pDelay; if (vel.length() > .5f) { position += vel * pDelay; vel[2] -= 9.8f * pDelay; CVector3f p1 = lastPos; CVector3f p2 = position; CVector3f normal; if (map->rayTest(p1, p2, normal)) { // On dit à tout le monde de jouer le son (pour l'instant juste server side) if (!soundPlayed) { if (type == DOUILLE_TYPE_DOUILLE) dksPlay3DSound(gameVar.sfx_douille[rand()%3],-1,1,position,255); else if (type == DOUILLE_TYPE_GIB) { scene->client->game->spawnBlood(position, .1f); // delay = 0; } soundPlayed = true; } position = p2 + normal*.1f; vel = reflect(vel, normal); vel *= .3f; } } }
Vec4d Raytracer::shade(const RayIntersection& intersection, size_t depth) const { // This offset must be added to intersection points for further // traced rays to avoid noise in the image const Vec3d offset(intersection.normal() * Math::safetyEps()); Vec4d color(0,0,0,1); std::shared_ptr<const Renderable> renderable = intersection.renderable(); std::shared_ptr<const Material> material = renderable->material(); for(size_t i=0;i <mScene->lights().size();++i) { const Light &light = *(mScene->lights()[i].get()); //Shadow ray from light to hit point. const Vec3d L = (intersection.position() + offset) - light.position(); const Ray shadowRay(light.position(), L); //Shade only if light in visible from intersection point. if (!mScene->anyIntersection(shadowRay,L.length())) color += material->shade(intersection,light); } // limit recursion depth if (depth >= mMaxDepth) return color; Vec3d dir = reflect(intersection.ray().direction(), intersection.normal()); Ray reflectedRay(intersection.position() + offset, dir); double reflectance = material->reflectance(); color = color * (1 - reflectance) + reflectance * trace(reflectedRay, depth - 1) + Vec4d(0.0,0.0,0.0,1.0); return color; }
/* menu: return one of the possible transformation */ int menu(char (*sq)[MAXN + 1], char (*trans)[MAXN + 1], int n) { char mirror[MAXN][MAXN + 1]; if (de90(sq, trans, n)) return 1; if (de180(sq, trans, n)) return 2; if (de270(sq, trans, n)) return 3; reflect(sq, mirror, n); if (equal(mirror, trans, n)) return 4; if (de90(mirror, trans, n) || de180(mirror, trans, n) || de270(mirror, trans, n)) return 5; if (equal(sq, trans, n)) return 6; return 7; }
int main() { srand(0); //seed generator with 0 for debugging dungeon *game = generate_dungeon(10, 20); tutorial(game); for(;;) { set_stage(game); get_desc(game); switch(input("", I_CHAR)) { case 'q': goto END_GAME; case 'n': move(game, D_NORTH); break; case 's': move(game, D_SOUTH); break; case 'e': move(game, D_EAST); break; case 'w': move(game, D_WEST); break; case 'i': action(game, A_INVENTORY); break; case 'd': action(game, A_DROP); break; case 'l': action(game, A_LOOT); break; case 'p': action(game, A_PUTON); break; case 'a': action(game, A_ARM); break; case 'c': action(game, A_CONSUME); break; case 'f': fight(game); break; case 'h': help(); break; case 'r': reflect(&(game->player)); break; case 'z': dump_dungeon(game); break; default: printf("Invalid Command!\n"); } } END_GAME: return 0; }
void main(void){ float dxtex = 1.0 / textureSizeX; float dytex = 1.0 / textureSizeY; vec2 st = gl_TexCoord[0].st; // access center pixel and 4 surrounded pixel vec3 center = getNormal(st).rgb; vec3 left = getNormal(st + vec2(dxtex, 0.0)).rgb; vec3 right = getNormal(st + vec2(-dxtex, 0.0)).rgb; vec3 up = getNormal(st + vec2(0.0, -dytex)).rgb; vec3 down = getNormal(st + vec2(0.0, dytex)).rgb; // discrete Laplace operator vec3 laplace = abs(-4.0*center + left + right + up + down); // if one rgb-component of convolution result is over threshold => edge vec4 line = texture2D(normalImage, st); if(laplace.r > normalEdgeThreshold || laplace.g > normalEdgeThreshold || laplace.b > normalEdgeThreshold){ line = vec4(0.0, 0.0, 0.0, 1.0); // => color the pixel green } else { line = vec4(1.0, 1.0, 1.0, 1.0); // black } //end Line; //start Phong //vec3 lightPosition = vec3(100.0, 100.0, 50.0); vec3 lightPosition = gl_LightSource[0].position.xyz; vec3 L = normalize(lightPosition - v); vec3 E = normalize(-v); vec3 R = normalize(-reflect(L,N)); // ambient term vec4 Iamb = ambient; // diffuse term vec4 Idiff = texture2D( normalImage, gl_TexCoord[0].st) * diffuse; //vec4 Idiff = vec4(1.0, 1.0, 1.0, 1.0) * diffuse; Idiff *= max(dot(N,L), 0.0); Idiff = clamp(Idiff, 0.0, 1.0); // specular term vec4 Ispec = specular; Ispec *= pow(max(dot(R,E),0.0), shinyness); Ispec = clamp(Ispec, 0.0, 1.0); vec4 color = Iamb + Idiff; if ( bSpecular == 1 ) color += Ispec; // store previous alpha value float alpha = color.a; // quantize process: multiply by factor, round and divde by factor color = floor(0.5 + (qLevel * color)) / qLevel; // set fragment/pixel color color.a = alpha; gl_FragColor = color * line; }
/* task that renders a single screen tile */ Vec3fa renderPixelStandard(float x, float y, const ISPCCamera& camera) { /* initialize ray */ RTCRay ray; ray.org = Vec3fa(camera.xfm.p); ray.dir = Vec3fa(normalize(x*camera.xfm.l.vx + y*camera.xfm.l.vy + camera.xfm.l.vz)); ray.tnear = 0.0f; ray.tfar = inf; ray.geomID = RTC_INVALID_GEOMETRY_ID; ray.primID = RTC_INVALID_GEOMETRY_ID; ray.mask = -1; ray.time = 0; /* intersect ray with scene */ rtcIntersect(g_scene,ray); /* shade pixels */ Vec3fa color = Vec3fa(0.0f); if (ray.geomID != RTC_INVALID_GEOMETRY_ID) { /* interpolate diffuse color */ Vec3fa diffuse = Vec3fa(1.0f,0.0f,0.0f); if (ray.geomID > 0) { unsigned int geomID = ray.geomID; { rtcInterpolate(g_scene,geomID,ray.primID,ray.u,ray.v,RTC_USER_VERTEX_BUFFER0,&diffuse.x,nullptr,nullptr,3); } diffuse = 0.5f*diffuse; } /* calculate smooth shading normal */ Vec3fa Ng = normalize(ray.Ng); color = color + diffuse*0.5f; Vec3fa lightDir = normalize(Vec3fa(-1,-1,-1)); /* initialize shadow ray */ RTCRay shadow; shadow.org = ray.org + ray.tfar*ray.dir; shadow.dir = neg(lightDir); shadow.tnear = 0.001f; shadow.tfar = inf; shadow.geomID = 1; shadow.primID = 0; shadow.mask = -1; shadow.time = 0; /* trace shadow ray */ rtcOccluded(g_scene,shadow); /* add light contribution */ if (shadow.geomID) { Vec3fa r = normalize(reflect(ray.dir,Ng)); float s = pow(clamp(dot(r,lightDir),0.0f,1.0f),10.0f); float d = clamp(-dot(lightDir,Ng),0.0f,1.0f); color = color + diffuse*d + 0.5f*Vec3fa(s); } } return color; }
float3 refract(float3 inDir, float3 normal) { float ri = refractiveIndex; float cosa = -normal.dot(inDir); if(cosa < 0) { cosa = -cosa; normal = -normal; ri = 1 / ri; } float disc = 1 - (1 - cosa * cosa) / ri / ri; if(disc < 0) return reflect(inDir, normal); return inDir * (1.0 / ri) + normal * (cosa / ri - sqrt(disc)); }
Spectrum MirrorBSDF::sample_f(const Vector3D& wo, Vector3D* wi, float* pdf) { // TODO Part 5: // Implement MirrorBSDF reflect(wo, wi); *pdf = 1.0; return reflectance * (1 / fabs(wi->z)); }
void PremadeMap::drawReflect(void) const { glPushMatrix(); flatTexture reflect(Bomberman::ModelHandler::get().getModel("loadmap_reflect")); glTranslated(515, 203, 0); reflect.draw(); glPopMatrix(); }
Spectrum MirrorBSDF::sample_f(const Vector3D& wo, Vector3D* wi, float* pdf) { // TODO: // Implement MirrorBSDF reflect(wo,wi); *pdf = 1.f; return this->reflectance * (1.f / fabs(wo.z)); }
ostream & NeRegSuf::print(ostream &out)const{ reflect(); return out << "sumsqy = " << sumsqy << endl << "sumy_ = " << sumy_ << endl << "n_ = " << n_ << endl << "xty_ = " << xty_ << endl << "xtx = " << endl << xtx_; }
nex::color specular_reflection_brdf::sample(const lumen::sample& sample, const surface& surface, const nex::vector& wo, nex::vector* wi, float* pdf) const { *wi = reflect(wo, surface.normal); *pdf = 1.0f; return reflectance / std::abs(nex::dot(surface.normal, *wi)); }
polyvertex_cube::polyvertex_cube() { const double inv_s3 = 1.0 / sqrt(3.0); vertices.push_back(point3D(inv_s3, inv_s3, inv_s3)); vertices.push_back(point3D(inv_s3, inv_s3, -inv_s3)); vertices.push_back(point3D(inv_s3, -inv_s3, inv_s3)); vertices.push_back(point3D(inv_s3, -inv_s3, -inv_s3)); reflect(); }
ColorRGB RayTracer::trace(const Ray& p_ray, const SceneList& p_scene, int p_bounce) { if (p_bounce > m_settings.maxBounces) { return m_settings.clearColor; } std::pair<Shape*, float> closestInfo = getClosestShape(p_ray, p_scene); if (closestInfo.first != nullptr) { Point3 intersectionPoint = p_ray.origin + closestInfo.second * p_ray.direction; Vector3 intersectionNormal = closestInfo.first->getNormal(intersectionPoint); intersectionNormal.normalize(); // Offset to prevent self intersection intersectionPoint += 0.0001f * intersectionNormal; //ColorRGB reflectedColor = ColorRGB(255, 255, 255); if (closestInfo.first->reflective) { // Trace reflection ray Ray reflectionRay( intersectionPoint, reflect(p_ray.direction, intersectionNormal)); return trace(reflectionRay, p_scene, p_bounce + 1); } if (m_settings.lightEnabled == false) { return closestInfo.first->color.rgb(); } // Compute shadow ray const Point3 lightPosition(0, 500, 0); Vector3 shadowVector = lightPosition - intersectionPoint; shadowVector.normalize(); Ray shadowRay(intersectionPoint, shadowVector); std::pair<Shape*, float> shadowInfo = getClosestShape(shadowRay, p_scene); float lightContribution = 0.2f; // Ambient light if (shadowInfo.first == nullptr) { // Compute diffuse light factor float diffuseFactor = dotProduct(intersectionNormal, shadowRay.direction); if (diffuseFactor > 0.0f) { lightContribution += diffuseFactor; } } return std::min(lightContribution, 1.0f) * closestInfo.first->color.rgb(); } return m_settings.clearColor; }
/* task that renders a single screen tile */ Vec3fa renderPixelStandard(float x, float y, const ISPCCamera& camera, RayStats& stats) { RTCIntersectContext context; rtcInitIntersectContext(&context); /* initialize ray */ Ray ray(Vec3fa(camera.xfm.p), Vec3fa(normalize(x*camera.xfm.l.vx + y*camera.xfm.l.vy + camera.xfm.l.vz)), 0.0f, inf); /* intersect ray with scene */ rtcIntersect1(g_scene,&context,RTCRayHit_(ray)); RayStats_addRay(stats); /* shade pixels */ Vec3fa color = Vec3fa(0.0f); if (ray.geomID != RTC_INVALID_GEOMETRY_ID) { /* interpolate diffuse color */ Vec3fa diffuse = Vec3fa(1.0f,0.0f,0.0f); if (ray.geomID > 0) { unsigned int geomID = ray.geomID; { rtcInterpolate0(rtcGetGeometry(g_scene,geomID),ray.primID,ray.u,ray.v,RTC_BUFFER_TYPE_VERTEX_ATTRIBUTE,0,&diffuse.x,3); } //return diffuse; diffuse = 0.5f*diffuse; } /* calculate smooth shading normal */ Vec3fa Ng = ray.Ng; if (ray.geomID == 2 || ray.geomID == 3) { Vec3fa dPdu,dPdv; unsigned int geomID = ray.geomID; { rtcInterpolate1(rtcGetGeometry(g_scene,geomID),ray.primID,ray.u,ray.v,RTC_BUFFER_TYPE_VERTEX,0,nullptr,&dPdu.x,&dPdv.x,3); } //return dPdu; Ng = cross(dPdu,dPdv); } Ng = normalize(Ng); color = color + diffuse*0.5f; Vec3fa lightDir = normalize(Vec3fa(-1,-1,-1)); /* initialize shadow ray */ Ray shadow(ray.org + ray.tfar*ray.dir, neg(lightDir), 0.001f, inf); /* trace shadow ray */ rtcOccluded1(g_scene,&context,RTCRay_(shadow)); RayStats_addShadowRay(stats); /* add light contribution */ if (shadow.tfar >= 0.0f) { Vec3fa r = normalize(reflect(ray.dir,Ng)); float s = pow(clamp(dot(r,lightDir),0.0f,1.0f),10.0f); float d = clamp(-dot(lightDir,Ng),0.0f,1.0f); color = color + diffuse*d + 0.5f*Vec3fa(s); } } return color; }
inline Spectrum sample(BSDFSamplingRecord &bRec, Float &_pdf, const Point2 &_sample) const { Point2 sample(_sample); bool hasSpecular = (bRec.typeMask & EGlossyReflection) && (bRec.component == -1 || bRec.component == 0); bool hasDiffuse = (bRec.typeMask & EDiffuseReflection) && (bRec.component == -1 || bRec.component == 1); if (!hasSpecular && !hasDiffuse) return Spectrum(0.0f); bool choseSpecular = hasSpecular; if (hasDiffuse && hasSpecular) { if (sample.x <= m_specularSamplingWeight) { sample.x /= m_specularSamplingWeight; } else { sample.x = (sample.x - m_specularSamplingWeight) / (1-m_specularSamplingWeight); choseSpecular = false; } } if (choseSpecular) { Vector R = reflect(bRec.wi); Float exponent = m_exponent->eval(bRec.its).average(); /* Sample from a Phong lobe centered around (0, 0, 1) */ Float sinAlpha = std::sqrt(1-std::pow(sample.y, 2/(exponent + 1))); Float cosAlpha = std::pow(sample.y, 1/(exponent + 1)); Float phi = (2.0f * M_PI) * sample.x; Vector localDir = Vector( sinAlpha * std::cos(phi), sinAlpha * std::sin(phi), cosAlpha ); /* Rotate into the correct coordinate system */ bRec.wo = Frame(R).toWorld(localDir); bRec.sampledComponent = 1; bRec.sampledType = EGlossyReflection; if (Frame::cosTheta(bRec.wo) <= 0) return Spectrum(0.0f); } else { bRec.wo = warp::squareToCosineHemisphere(sample); bRec.sampledComponent = 0; bRec.sampledType = EDiffuseReflection; } bRec.eta = 1.0f; _pdf = pdf(bRec, ESolidAngle); if (_pdf == 0) return Spectrum(0.0f); else return eval(bRec, ESolidAngle) / _pdf; }
/******* Fonction à écrire par les etudiants ******/ Color trace_ray (Ray ray_) { /** * \todo : recursive raytracing * * La fonction trace_ray() renvoie une couleur obtenue par la somme de l'éclairage direct (couleur calculée par la fonction * compute_direct_lighting()) et des couleurs provenant des reflets et transparences éventuels aux points d'intersection. * Dans la première partie du TP, seul l'éclairage direct sera calculé. Dans la seconde partie, les reflets et transparences seront rajoutés. * * Pour la première étape, la fonction trace_ray() ne calculant que les rayons primaires, l'intersection * entre le rayon et la scène doit être calculée (fonction intersect_scene() du module \ref RayAPI). * S'il n'y a pas d'intersection, une couleur blanche (triplet RGB [1, 1, 1], élément neutre de la multiplication des couleurs) * devra être retournée. * S'il y a une intersection, la couleur retournée sera la couleur résultante de l'éclairage direct du point d'intersection par les * sources lumineuses de la scène et calculée par la fonction compute_direct_lighting() à écrire dans la suite. * * Pour la deuxième étape, à partir des fonctions définies dans le module \ref RayAPI et permettant d'accéder aux informations de * profondeur et d'importance sur le rayon, définir un cas d'arêt dela récursivité et renvoyer si ce cas est vérifié la couleur * résultante de l'éclairage direct. Si la récursivité n'est pas terminée, en utilisant les fonctions définies dans le module \ref LightAPI, * calculer la couleur réfléchie. Pour cela, il faut tester si le matériau est réflechissant et, si c'est le cas, calculer le rayon * réfléchi et le coefficient de réflexion (une couleur). La couleur calculée en lançant le rayon réfléchi devra alors être multipliée par ce coefficient avant d'être ajoutée * à la couleur renvoyée par trace_ray(). * * Pour la troisème étape et de façon très similaire à la réflexion, utiliser les fonctions définies dans le module \ref LightAPI pour calculer la couleur réfractée. * Pour cela, il faut tester si le matériau est transparent et, si c'est le cas, calculer le rayon réfracté et le coefficient de * transparence (une couleur). La couleur calculée en lançant le rayon réfracté devra alors être multipliée par ce coefficient avant * d'être ajoutée à la couleur renvoyée par trace_ray(). * */ Color l = init_color (0.075f, 0.075f, 0.075f); Isect isect_; int isInter = intersect_scene (&ray_, &isect_ ); if (isInter!=0){ l = compute_direct_lighting (ray_, isect_); } if (ray_depth(ray_)>10 || ray_importance(ray_)<0.01f) return (l); //reflection if(isect_has_reflection(isect_)){ Ray refl_ray; Color refl_col = reflect(ray_, isect_, &refl_ray); l = l+refl_col*(trace_ray(refl_ray)); } //refraction if(isect_has_refraction(isect_)){ Ray rafr_ray; Color rafr_col = refract(ray_, isect_, &rafr_ray); if(color_is_black(rafr_col)==0) l = l+rafr_col*(trace_ray(rafr_ray)); } return l; }
Spectrum sample(BSDFQueryRecord &bRec, Float &pdf, const Point2 &sample) const { if (!(bRec.typeMask & m_combinedType)) return Spectrum(0.0f); reflect(bRec.wi, bRec.wo); bRec.sampledComponent = 0; bRec.sampledType = EDeltaReflection; pdf = std::abs(Frame::cosTheta(bRec.wo)); return m_reflectance; }
Vector NeRegSuf::vectorize(bool minimal)const{ reflect(); Vector ans = xtx_.vectorize(minimal); ans.concat(xty_); ans.push_back(sumsqy); ans.push_back(n_); ans.push_back(sumy_); return ans; }
Spectrum MirrorBSDF::sample_f(const Vector3D& wo, Vector3D* wi, float* pdf) { // TODO Part 5: // Implement MirrorBSDF reflect(wo, wi); double cosine = abs_cos_theta(*wi); Spectrum result = reflectance/cosine; *pdf = 1; return result; }