static PT_THREAD(send_values(struct httpd_state *s)) { PSOCK_BEGIN(&s->sout); SEND_STRING(&s->sout, TOP); if(strncmp(s->filename, "/index", 6) == 0 || s->filename[1] == '\0') { /* Default page: show latest sensor values as text (does not require Internet connection to Google for charts). */ blen = 0; ADD("<h1>Websense</h1>\n"); #if CONTIKI_TARGET_SKY ADD("<h2>Current readings</h2>\n" "Light: %u<br>" "Temperature: %u° C", get_light(), get_temp()); #endif SEND_STRING(&s->sout, buf); } else if(s->filename[1] == '0') { /* Turn off leds */ leds_off(LEDS_ALL); SEND_STRING(&s->sout, "Turned off leds!"); } else if(s->filename[1] == '1') { /* Turn on leds */ leds_on(LEDS_ALL); SEND_STRING(&s->sout, "Turned on leds!"); } else { #if CONTIKI_TARGET_SKY if(s->filename[1] != 't') { generate_chart("Light", "Light", 0, 500, light1); SEND_STRING(&s->sout, buf); } if(s->filename[1] != 'l') { generate_chart("Temperature", "Celsius", 15, 50, temperature); SEND_STRING(&s->sout, buf); } #endif } SEND_STRING(&s->sout, BOTTOM); PSOCK_END(&s->sout); }
/*---------------------------------------------------------------------------*/ PROCESS_THREAD(test_light_process, ev, data) { static struct etimer et; PROCESS_BEGIN(); while(1) { printf("Light : %d\n",get_light()); printf("Temp : %d\n",get_temp()); etimer_set(&et, CLOCK_SECOND / 2); PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et)); } PROCESS_END(); }
PointLightShader::PointLightShader() : Shader( R"( // vertex shader --------------------------------------------------------- @include "instanced_quad_vertex_shader" )", R"( // fragment shader ------------------------------------------------------- @include "version" // varyings in vec2 texcoords; flat in int instance_id; // uniforms uniform sampler2D light_tex; uniform vec4 light_color[100]; uniform ivec2 screen_size; @include "gbuffer_input" @include "get_light" layout (location = 0) out vec4 fragLight; void main(void){ vec3 light_info = get_light_info(gl_FragCoord.xy/screen_size); float emit = light_info.r; if (emit >= 1.0) { discard; } float gloss = light_info.g; vec4 light = texture(light_tex, texcoords); vec3 light_dir = normalize(light.rgb - 0.5); float attenuation = light.a; fragLight = get_light( gl_FragCoord.xy/screen_size, light_dir, light_color[instance_id], gloss, emit, attenuation); }
t_data *get_obj_and_light(int fd, t_data *data) { char *line; int end; end = 0; line = NULL; while (end == 0) { line = get_next_line(fd); if (line == NULL || str_match(line, "#EOF") == 1) end = 1; else { if (my_strncmp(line, "LIGHT", my_strlen("LIGHT")) == 0) data->light = get_light(line, data->light); else data->obj = get_obj(line, data->obj); } if (line != NULL) free(line); } return (data); }
void read_scene(FILE* fp, int version) { if (version > -1 || version < -2) error("Scene file version %d is not supported", version); fread(&number_of_cameras, sizeof(int), 1, fp); if (number_of_cameras) { cameras = new OBJECT_3D_SCENE_CAMERA_INFO[number_of_cameras]; for (int camera_count = 0; camera_count < number_of_cameras; camera_count++) { cameras[camera_count].camera_name_index = get_camera(fp); cameras[camera_count].camera_index = read_new_camera(fp); } } else cameras = NULL; fread(&number_of_scene_link_objects, sizeof(int), 1, fp); if (number_of_scene_link_objects) { scene_link_objects = new OBJECT_3D_SCENE_LINK_OBJECT [number_of_scene_link_objects]; for (int tmp = 0; tmp < number_of_scene_link_objects; tmp++) { scene_link_objects[tmp].scene_index = get_scene(fp); fread(&scene_link_objects[tmp].x, sizeof(float), 1, fp); fread(&scene_link_objects[tmp].y, sizeof(float), 1, fp); fread(&scene_link_objects[tmp].z, sizeof(float), 1, fp); fread(&scene_link_objects[tmp].heading, sizeof(float), 1, fp); fread(&scene_link_objects[tmp].pitch, sizeof(float), 1, fp); fread(&scene_link_objects[tmp].roll, sizeof(float), 1, fp); } } else scene_link_objects = NULL; fread(&number_of_sprite_lights, sizeof(int), 1, fp); number_of_sprite_lights = number_of_sprite_lights; sprite_lights = NULL; if (number_of_sprite_lights) { sprite_lights = new OBJECT_3D_SPRITE_LIGHT[number_of_sprite_lights]; for (int tmp = 0; tmp < number_of_sprite_lights; tmp++) { int red, green, blue; fread(&sprite_lights[tmp].position.x, sizeof(float), 1, fp); fread(&sprite_lights[tmp].position.y, sizeof(float), 1, fp); fread(&sprite_lights[tmp].position.z, sizeof(float), 1, fp); fread(&sprite_lights[tmp].scale.x, sizeof(float), 1, fp); fread(&sprite_lights[tmp].scale.y, sizeof(float), 1, fp); fread(&sprite_lights[tmp].scale.z, sizeof(float), 1, fp); fread(&red, sizeof(int), 1, fp); fread(&green, sizeof(int), 1, fp); fread(&blue, sizeof(int), 1, fp); sprite_lights[tmp].colour.red = red; sprite_lights[tmp].colour.green = green; sprite_lights[tmp].colour.blue = blue; } } if (version <= -2) fread(&number_of_ambient_lights, sizeof(int), 1, fp); else number_of_ambient_lights = 0; ambient_lights = NULL; if (number_of_ambient_lights) { ambient_lights = new OBJECT_3D_AMBIENT_LIGHT[number_of_ambient_lights]; for (int tmp = 0; tmp < number_of_ambient_lights; tmp++) { fread(&ambient_lights[tmp].colour.red, sizeof(float), 1, fp); fread(&ambient_lights[tmp].colour.green, sizeof(float), 1, fp); fread(&ambient_lights[tmp].colour.blue, sizeof(float), 1, fp); ambient_lights[tmp].light_index = get_light(fp); } } if (version <= -2) fread(&number_of_distant_lights, sizeof(int), 1, fp); else number_of_distant_lights = 0; distant_lights = NULL; if (number_of_distant_lights) { distant_lights = new OBJECT_3D_DISTANT_LIGHT[number_of_distant_lights]; for (int tmp = 0; tmp < number_of_distant_lights; tmp++) { fread(&distant_lights[tmp].heading, sizeof(float), 1, fp); fread(&distant_lights[tmp].pitch, sizeof(float), 1, fp); fread(&distant_lights[tmp].roll, sizeof(float), 1, fp); fread(&distant_lights[tmp].colour.red, sizeof(float), 1, fp); fread(&distant_lights[tmp].colour.green, sizeof(float), 1, fp); fread(&distant_lights[tmp].colour.blue, sizeof(float), 1, fp); distant_lights[tmp].light_index = get_light(fp); } } fread(&total_number_of_sub_objects, sizeof(int), 1, fp); fread(&total_number_of_sub_object_indices, sizeof(int), 1, fp); if (total_number_of_sub_object_indices) current_scene_sub_object_index_array = new OBJECT_3D_SUB_OBJECT_INDEX[total_number_of_sub_object_indices]; else current_scene_sub_object_index_array = NULL; if (total_number_of_sub_objects) current_scene_sub_object_array = new OBJECT_3D_DATABASE_ENTRY[total_number_of_sub_objects]; else current_scene_sub_object_array = NULL; scene_sub_object_indices_array = current_scene_sub_object_index_array; scene_sub_object_array = current_scene_sub_object_array; fread(&number_of_texture_animations, sizeof(int), 1, fp); if (number_of_texture_animations) { texture_animations = new int[number_of_texture_animations]; for (int tmp = 0; tmp < number_of_texture_animations; tmp++) fread(&texture_animations[tmp], sizeof(int), 1, fp); } else texture_animations = NULL; fread(&number_of_approximations, sizeof(int), 1, fp); index = get_object(fp); if (number_of_approximations) { approximations = new OBJECT_3D_APPROXIMATION_INFO[number_of_approximations]; for (int approximation = 0; approximation < number_of_approximations; approximation++) { approximations[approximation].object_number = get_object(fp); fread(&approximations[approximation].distance, sizeof(float), 1, fp); } } fread(&shadow_approximation_index, sizeof(int), 1, fp); shadow_polygon_object_index = get_object(fp); fread(&shadow_polygon_object_scale.x, sizeof(float), 1, fp); fread(&shadow_polygon_object_scale.y, sizeof(float), 1, fp); fread(&shadow_polygon_object_scale.z, sizeof(float), 1, fp); collision_object_index = get_object(fp); if (!collision_object_index) collision_object_index = -1; read_keyframes(fp, &number_of_keyframes, &keyframes); fseek(fp, sizeof(float), SEEK_CUR); read_value_keyframes(fp, &number_of_object_dissolve_keyframes, &object_dissolve_keyframes); read_value_keyframes(fp, &number_of_displacement_amplitude_keyframes, &displacement_amplitude_keyframes); read_indices(fp, &number_of_sub_object_indices, &sub_object_indices); read_subobjects(fp, &number_of_sub_objects, &sub_objects, NULL); QuickSearch quick(*this); }
/* * Function: trace_path * * Samples light transport path in recursive manner. In curent * implementation, <trace_path> acts as distribution ray tracing. * * Parameters: * * *render - The global renderer data. * *ray - The ray to be traced. * *resut - Light transport result(including radiance). * * Returns: * * None. */ static void trace_path(ri_render_t *render, ri_ray_t *ray, ri_transport_info_t *result) { int max_nbound_specular = 10; if (result->nbound_specular > max_nbound_specular) { /* Too much reflection, terminate. */ return; } ri_light_t *light = NULL; int hit; /* hack */ vec white; vec black; ri_vector_set1(white, 1.0); ri_vector_set1(black, 0.0); hit = ri_raytrace(render, ray, &(result->state)); if (hit) { if (result->state.geom->light) { light = result->state.geom->light; /* Hit light geometry. */ vcpy(result->radiance, light->col); return; } vcpy(result->radiance, white); } else { vcpy(result->radiance, black); } return; #if 0 // TODO int hit, lighthit; int hasfresnel; ri_vector_t col; ri_vector_t transmit_ray; ri_vector_t reflect_ray; ri_vector_t offset; ri_vector_t raydir; ri_vector_t rayorg; ri_vector_t refrad, trasrad; ri_vector_t normal; ri_light_t *light; ri_vector_t rad; ri_material_t *material; ri_ray_t lightray; ri_transport_info_t ref_result; /* for reflection */ double r, d, s, t; float fresnel_factor = 1.0f; float kr, kt; float eta = 1.0f / 1.4f; float etaval; if (result->nbound_specular > 8) { //printf("too reflection\n"); return; } light = get_light(render); ri_vector_copy(&raydir, ray->dir); result->state.inside = 0; hit = ri_raytrace(render, ray, &(result->state)); if (hit) { if (light->geom) { /* Check if a ray also hits light geometry and * that is closer than scene geometry or not. */ ri_vector_copy(&lightray.org, ray->org); ri_vector_copy(&lightray.dir, ray->dir); lighthit = ri_raytrace_geom( light->geom, &lightray, &(result->state)); if (lighthit && (lightray.isectt < ray->isectt) ) { // light is "seen" ri_vector_copy(&result->radiance, light->col); result->hit = 1; return; } } r = randomMT(); material = result->state.geom->material; if (!material) { d = 1.0; s = 0.0; t = 0.0; } else { d = ri_vector_ave(&material->kd); s = ri_vector_ave(&material->ks); t = ri_vector_ave(&material->kt); } if (s > 0.0) { /* specular reflection */ if (result->state.geom->material && result->state.geom->material->fresnel) { /* Fresnel reflection */ ri_fresnel(&ray->dir, &transmit_ray, &kr, &kt, &ray->dir, &result->state.normal, eta); fresnel_factor = kr; } else { ri_reflect(&(ray->dir), &ray->dir, &result->state.normal); fresnel_factor = 1.0f; } ri_vector_copy(&(ray->org), result->state.P); ri_vector_copy(&col, result->state.color); result->nbound_specular++; /* push radiance */ ri_vector_copy(&rad, result->radiance); ri_vector_zero(&(result->radiance)); trace_path(render, ray, result); /* pop radiance */ ri_vector_mul(&(result->radiance), &result->radiance, &material->ks); ri_vector_mul(&(result->radiance), &result->radiance, &col); ri_vector_scale(&(result->radiance), fresnel_factor); ri_vector_add(&(result->radiance), &result->radiance, &rad); } if (d > 0.0) { /* diffuse reflection */ result->nbound_diffuse++; ri_shade(&rad, &ray->dir, ray, &(result->state)); ri_vector_mul(&rad, &rad, &material->kd); ri_vector_add(&(result->radiance), &result->radiance, &rad); } if (t > 0.0) { /* specular refraction */ if (result->state.geom->material && result->state.geom->material->fresnel) { hasfresnel = 1; } else { hasfresnel = 0; } if (hasfresnel) { /* Fresnel effect */ ri_vector_copy(&normal, result->state.normal); if (result->state.inside) { printf("inside val = %d\n", result->state.inside); printf("inside\n"); /* ray hits inside surface */ //ri_vector_neg(&normal); etaval = 1.0 / eta; } else { etaval = eta; } ri_fresnel(&reflect_ray, &transmit_ray, &kr, &kt, &ray->dir, &normal, etaval); } else { ri_refract(&(ray->dir), &ray->dir, &result->state.normal, eta); kr = 0.0; kt = 1.0; } /* slightly moves the ray towards outgoing direction */ ri_vector_copy(&rayorg, result->state.P); /* ray.org = ray.org + 0.001 * ray.dir */ ri_vector_copy(&offset, &transmit_ray); ri_vector_scale(&offset, 0.001); ri_vector_add(&(ray->org), &rayorg, &offset); /* ray.dir = refract direction */ ri_vector_copy(&(ray->dir), &transmit_ray); ri_vector_copy(&col, &result->state.color); result->nbound_specular++; ray->prev_hit = 'S'; /* push radiance */ ri_vector_copy(&rad, &result->radiance); ri_vector_zero(&(result->radiance)); trace_path(render, ray, result); /* pop radiance */ ri_vector_mul(&(result->radiance), &result->radiance, &material->kt); ri_vector_mul(&(result->radiance), &result->radiance, &col); ri_vector_scale(&(result->radiance), kt); if (hasfresnel) { /* add reflection color */ /* ray.org = ray.org + 0.001 * ray.dir */ ri_vector_copy(&offset, &reflect_ray); ri_vector_scale(&offset, 0.001); ri_vector_add(&(ray->org), &rayorg, &offset); ri_vector_copy(&(ray->dir), &reflect_ray); ri_vector_copy(&col, &result->state.color); ray->prev_hit = 'S'; ri_vector_zero(&ref_result.radiance); ref_result.nbound_specular = result->nbound_specular; ref_result.nbound_diffuse = result->nbound_diffuse; ref_result.state.inside = 0; trace_path(render, ray, &ref_result); /* pop radiance */ ri_vector_mul(&(ref_result.radiance), &ref_result.radiance, &col); ri_vector_scale(&(ref_result.radiance), kr); ri_vector_add(&(result->radiance), &result->radiance, &ref_result.radiance); } ri_vector_add(&(result->radiance), &result->radiance, &rad); } //} else if (result->nbound_specular + result->nbound_diffuse < 2) { } else { /* check if hit light geometry */ ray->isectt = 0.0f; if (light->type == LIGHTTYPE_IBL || light->type == LIGHTTYPE_SUNSKY) { ri_texture_ibl_fetch(&(result->radiance), light->texture, &ray->dir); result->hit = 1; return; } else if (ri_render_get()->background_map) { ri_texture_ibl_fetch(&(result->radiance), ri_render_get()->background_map, &ray->dir); result->hit = 1; return; } else { if (light->geom) { /* area light. */ lighthit = ri_raytrace_geom( light->geom, ray, &(result->state)); if (lighthit) { // light is "seen" result->radiance.e[0] = 1.0; result->radiance.e[1] = 1.0; result->radiance.e[2] = 1.0; result->hit = 1; return; } } else if (light->type == LIGHTTYPE_DOME) { //ri_vector_copy(&(result->radiance), // &(light->col)); //ri_vector_scale(&(result->radiance), // (float)light->intensity); } } } #endif return; }