编辑: f19970615123fa 2017-09-01

float3 ffnormal = faceforward( world_shade_normal, -ray.direction, world_geo_normal );

float3 color = Ka * ambient_light_color;

float t_hit = incoming_ray_t.get();

float3 hit_point = ray.origin + t_hit * ray.direction;

for(int i = 0;

i <

lights.size();

++i) { // Loop over lights BasicLight light = lights[i];

float3 L = normalize(light.pos - hit_point);

float nDl = dot( ffnormal, L);

if( nDl >

0 ) color += Kd * nDl * light.color;

} prd.result = color;

} SIGGRAPH?2009?presentation Lambertian shader?\ result SIGGRAPH?2009?presentation Adding?shadows?\ goal SIGGRAPH?2009?presentation for(int i = 0;

i <

lights.size();

++i) { BasicLight light = lights[i];

float3 L = normalize(light.pos - hit_point);

float nDl = dot( ffnormal, L);

if( nDl >

0.0f ){ // cast shadow ray PerRayData_shadow shadow_prd;

shadow_prd.attenuation = 1.0f;

float Ldist = length(light.pos - hit_point);

Ray shadow_ray = make_ray( hit_point, L, 1, scene_epsilon, Ldist );

rtTrace(top_shadower, shadow_ray, shadow_prd);

float light_attenuation = shadow_prd.attenuation;

if( light_attenuation >

0.0f ){ float3 Lc = light.color * light_attenuation;

color += Kd * nDl * Lc;

float3 H = normalize(L - ray.direction);

float nDh = dot( ffnormal, H );

if(nDh >

0) color += Ks * Lc * pow(nDh, phong_exp);

} } SIGGRAPH?2009?presentation Adding?shadows?\result SIGGRAPH?2009?presentation Adding?reflections?\ goal SIGGRAPH?2009?presentation … // reflection ray PerRayData_radiance refl_prd;

float3 R = reflect( ray.direction, ffnormal );

Ray refl_ray = make_ray( hit_point, R, 0, scene_epsilon, RT_DEFAULT_MAX );

rtTrace(top_object, refl_ray, refl_prd);

color += reflectivity * refl_prd.result;

SIGGRAPH?2009?presentation Per?ray?data Can?define?arbitrary?data?with?the?ray Sometimes?called?the? payload?of?the?ray Data?can?be?passed?down?or?up?the?ray?tree?(or?both) Just?a?user\defined?struct accessed?by?all?shader? programs Varies?per?ray?type Attenuation Color Depth importance Color Depth importance SIGGRAPH?2009?presentation struct PerRayData_radiance { float3 result;

float importance;

int depth;

};

… float importance = prd.importance * luminance( reflectivity );

// reflection ray if( importance >

importance_cutoff &

&

prd.depth <

max_depth) { PerRayData_radiance refl_prd;

refl_prd.importance = importance;

refl_prd.depth = prd.depth+1;

float3 R = reflect( ray.direction, ffnormal );

Ray refl_ray = make_ray( hit_point, R, 0, scene_epsilon, RT_DEFAULT_MAX );

rtTrace(top_object, refl_ray, refl_prd);

color += reflectivity * refl_prd.result;

} SIGGRAPH?2009?presentation Adding?reflections?\ result SIGGRAPH?2009?presentation Environment?map?\ goal SIGGRAPH?2009?presentation Miss?program Defines?what?happens?when?a?ray?misses?all?objects Accesses?per\ray?data Usually?C background?color SIGGRAPH?2009?presentation rtDeclareVariable(float3, bg_color);

RT_PROGRAM void miss() { PerRayData_radiance&

prd = prd_radiance.reference();

prd.result = bg_color;

} SIGGRAPH?2009?presentation rtTextureSampler envmap;

RT_PROGRAM void miss() { const Ray ray = incoming_ray.get();

PerRayData_radiance&

prd = prd_radiance.reference();

float theta = atan2f(ray.direction.x, ray.direction.z);

theta = (theta + M_PIf) * (0.5f * M_1_PIf);

float phi = ray.direction.y * 0.5f + 0.5f;

prd.result = make_float3(tex2D(envmap, theta, phi));

} SIGGRAPH?2009?presentation Environment?map?\ result SIGGRAPH?2009?presentation Schlick approximation?\ goal SIGGRAPH?2009?presentation float3 r = schlick(-dot(ffnormal, ray.direction), reflectivity_n);

下载(注:源文件不在本站服务器,都将跳转到源网站下载)
备用下载
发帖评论
相关话题
发布一个新话题