示例#1
0
    def intersect_call(self):
        code_tmplt = "intersect_cube({cubeMin}, {cubeMax})"

        return code_tmplt.format(
            cubeMin=utils.code_vec(self.cubeMin),
            cubeMax=utils.code_vec(self.cubeMax),
        )
示例#2
0
    def intersect_call(self):
        code_tmplt = "intersect_triangle({A}, {B}, {C})"

        return code_tmplt.format(
            A=utils.code_vec(self.A),
            B=utils.code_vec(self.B),
            C=utils.code_vec(self.C),
        )
示例#3
0
    def code(self):
        code_tmplt = "material_transparent({albedo}, {refract_factor});"

        return code_tmplt.format(
            albedo=utils.code_vec(self.albedo),
            refract_factor=self.refract_factor,
        )
示例#4
0
def glsl_main(scene, assignment):
    code_tmplt = """

varying vec4 position;
uniform vec2 offset;
uniform float nb_samples;
uniform float sample_id;


void
main()
{{
    int image_width = {image_width};
    int image_height = {image_height};
    float image_aspect_ratio = {image_aspect_ratio};

    int render_width = {render_width};
    int render_height = {render_height};
    int render_x = {render_x};
    int render_y = {render_y};

    vec3 camera_origin = {camera_origin};
    vec3 camera_dir = {camera_dir};
    float camera_field_of_view = {camera_field_of_view};
    float camera_near_plan = {camera_near_plan};
    float camera_focal_distance = {camera_focal_distance};
    float camera_blur_factor = {camera_blur_factor};

    vec2 screen_coord = (position.xy + offset) * 0.5 + 0.5;

    screen_coord.x *= float(render_width);
    screen_coord.y *= float(render_height);

    screen_coord.x += float(render_x);
    screen_coord.y += float(render_y);

    screen_coord.x /= float(image_width);
    screen_coord.y /= float(image_height);

    screen_coord = screen_coord * 2.0 - 1.0;

    random_seed = snoise(vec3(screen_coord.x, screen_coord.y, sample_id));

    float camera_tan = tan(camera_field_of_view * 0.5);
    float camera_cos = cos(camera_field_of_view * 0.5);

    float focal_plan_u = camera_tan * camera_focal_distance;
    float focal_plan_v = focal_plan_u / image_aspect_ratio;
    vec3 focal_plan_pos = camera_origin + camera_dir * (camera_focal_distance  * camera_cos);

    float camera_plan_u = camera_tan * camera_near_plan;
    float camera_plan_v = camera_plan_u / image_aspect_ratio;
    vec3 camera_plan_pos = camera_origin + camera_dir * (camera_near_plan  * camera_cos);

    vec3 u = normalize(cross(camera_dir, vec3(0.0, 0.0, 1.0)));
    vec3 v = cross(u, camera_dir);

    float rbt = random() * 2.0 * MATH_PI;
    float rbr = sqrt(random());

    vec2 blur_offset = (camera_blur_factor * rbr) * vec2(cos(rbt), sin(rbt));

    vec3 ray_focal_passby = focal_plan_pos + (focal_plan_u * screen_coord.x) * u + (focal_plan_v * screen_coord.y) * v;
    vec3 ray_pos = camera_plan_pos + (camera_plan_u * (screen_coord.x + blur_offset.x)) * u + (camera_plan_v * (screen_coord.y + blur_offset.y * image_aspect_ratio)) * v;

    vec3 ray_dir = normalize(ray_focal_passby - ray_pos);
    vec3 ray_color = ray_launch(ray_pos, ray_dir);

    gl_FragColor = vec4(ray_color / nb_samples, 1.0);
}}

"""

    image_aspect_ratio = float(assignment.rendering.width) / float(assignment.rendering.height)

    return code_tmplt.format(
        image_width=assignment.rendering.width,
        image_height=assignment.rendering.height,
        image_aspect_ratio=image_aspect_ratio,

        render_width=assignment.width,
        render_height=assignment.height,
        render_x=assignment.x,
        render_y=assignment.y,

        camera_origin=utils.code_vec(scene.camera.look_from),
        camera_dir=utils.code_vec(scene.camera.direction),
        camera_field_of_view=float(scene.camera.field_of_view),
        camera_near_plan=float(scene.camera.near_plan),
        camera_focal_distance=float(scene.camera.focal_distance),
        camera_blur_factor=float(scene.camera.blur_factor)
    )
示例#5
0
def test_code_vec():
    assert utils.code_vec([0.0, 1.0]) == "vec2(0.0, 1.0)"
    assert utils.code_vec([0.0, 1.0, 2.0]) == "vec3(0.0, 1.0, 2.0)"
    assert utils.code_vec([0.0, 1.0, 2.0, 3.0]) == "vec4(0.0, 1.0, 2.0, 3.0)"
示例#6
0
    def code(self):
        code_tmplt = "material_glossy({albedo});"

        return code_tmplt.format(
            albedo=utils.code_vec(self.vec4)
        )
示例#7
0
    def code(self):
        code_tmplt = "material_mirror({albedo});"

        return code_tmplt.format(
            albedo=utils.code_vec(self.albedo)
        )
示例#8
0
    def code(self):
        code_tmplt = "ray_color = {color};"

        return code_tmplt.format(
            color=utils.code_vec(self.color)
        )
示例#9
0
    def intersect_call(self):
        code_tmplt = "intersect_plan({plan})"

        return code_tmplt.format(
            plan=utils.code_vec(self.vec4)
        )
示例#10
0
    def intersect_call(self):
        code_tmplt = "intersect_sphere({sphere})"

        return code_tmplt.format(
            sphere=utils.code_vec(self.vec4)
        )