Esempio n. 1
0
    def test_set_prgba(self):
        code = """
val = (0.67, 0.88, 0.11, 0.55)
v1 = set_rgba(image1, 10, 10, val)
        """
        image = ImagePRGBA(200, 200)
        p1 = StructArg('image1', image)
        shader = Shader(code=code, args=[p1])
        shader.compile()
        shader.prepare([Runtime()])
        shader.execute()

        r, g, b, a = image.get_pixel(10, 10)
        self.assertAlmostEqual(r, 0.67)
        self.assertAlmostEqual(g, 0.88)
        self.assertAlmostEqual(b, 0.11)
        self.assertAlmostEqual(a, 0.55)
Esempio n. 2
0
    def test_set_prgba(self):
        code = """
val = (0.67, 0.88, 0.11, 0.55)
v1 = set_rgba(image1, 10, 10, val)
        """
        image = ImagePRGBA(200, 200)
        p1 = StructArg('image1', image)
        shader = Shader(code=code, args=[p1])
        shader.compile()
        shader.prepare([Runtime()])
        shader.execute()

        r, g, b, a = image.get_pixel(10, 10)
        self.assertAlmostEqual(r, 0.67)
        self.assertAlmostEqual(g, 0.88)
        self.assertAlmostEqual(b, 0.11)
        self.assertAlmostEqual(a, 0.55)
Esempio n. 3
0
    def test_get_prgba(self):
        code = """
v1 = get_rgba(image1, 10, 10)
        """
        image = ImagePRGBA(200, 200)
        image.set_pixel(10, 10, 0.23, 0.28, 0.55, 0.8)
        p1 = StructArg('image1', image)
        p2 = Vec4Arg('v1', Vector4(0.0, 0.0, 0.0, 0.0))

        shader = Shader(code=code, args=[p1, p2])
        shader.compile()
        shader.prepare([Runtime()])
        shader.execute()

        val = shader.get_value('v1')
        self.assertAlmostEqual(val.x, 0.23)
        self.assertAlmostEqual(val.y, 0.28)
        self.assertAlmostEqual(val.z, 0.55)
        self.assertAlmostEqual(val.w, 0.8)
Esempio n. 4
0
    def test_get_prgba(self):
        code = """
v1 = get_rgba(image1, 10, 10)
        """
        image = ImagePRGBA(200, 200)
        image.set_pixel(10, 10, 0.23, 0.28, 0.55, 0.8)
        p1 = StructArg('image1', image)
        p2 = Vec4Arg('v1', Vector4(0.0, 0.0, 0.0, 0.0))

        shader = Shader(code=code, args=[p1, p2])
        shader.compile()
        shader.prepare([Runtime()])
        shader.execute()

        val = shader.get_value('v1')
        self.assertAlmostEqual(val.x, 0.23)
        self.assertAlmostEqual(val.y, 0.28)
        self.assertAlmostEqual(val.z, 0.55)
        self.assertAlmostEqual(val.w, 0.8)
Esempio n. 5
0
    sphere = Sphere(Vector3(0.0, 0.0, 0.0), 2.0, 0)
    mgr.add('sph1', sphere)

    isector = LinearIsect(mgr)
    isector.compile()
    isector.prepare(runtimes)

    ###################

    integrator = Integrator()
    integrator.load('isect_shader')

    sampler.compile()
    camera.compile()
    sampler.prepare(runtimes)
    camera.prepare(runtimes)

    integrator.compile([sampler.shader, camera.shader, isector.shader])
    integrator.prepare(runtimes)
    img = ImagePRGBA(1024, 768)
    integrator.shader.set_value('image', img)

    start = time.clock()
    integrator.execute()
    end = time.clock()
    print("Rendering time:", end-start)

    img2 = ImageRGBA(1024, 768)
    blt_prgba_to_rgba(img, img2)
    show_image_in_window(img2, fliped=False)
Esempio n. 6
0
from .loader import Loader
from .shader import Shader
from .builtins import *
from .args import register_struct, Vec3Arg, StructArgPtr,\
    StructArg, PointerArg, parse_args

from renlight.ray import Ray
from renlight.vector import Vector3
from renlight.image import ImageRGBA, ImagePRGBA

register_struct(
    Ray,
    'Ray',
    fields=[('origin', Vec3Arg), ('direction', Vec3Arg)],
    factory=lambda: Ray(Vector3(0.0, 0.0, 0.0), Vector3(0.0, 0.0, 0.0)))

register_struct(ImageRGBA,
                'ImageRGBA',
                fields=[('width', IntArg), ('height', IntArg),
                        ('pitch', IntArg), ('pixels', PointerArg)],
                factory=lambda: ImageRGBA(1, 1))

register_struct(ImagePRGBA,
                'ImagePRGBA',
                fields=[('width', IntArg), ('height', IntArg),
                        ('pitch', IntArg), ('pixels', PointerArg)],
                factory=lambda: ImagePRGBA(1, 1))