from tdasm import Runtime from renmas3.base import create_shader, arg_map, Integer, Float, Vec3 from renmas3.base import create_function, arg_list arg_map1 = arg_map([('v1', Vec3), ('v2', Vec3), ('f1', Float), ('i1', Integer)]) code = """ p3 = (3.4, 3.3, 2.2) v1 = p3 mm = 4.4 f1 = mm gg = 44 i1 = gg + 88 p55 = 33 p55 = 4.4 """ shader = create_shader("test", code, arg_map1) print (shader._code) runtimes = [Runtime()] shader.prepare(runtimes) shader.execute() print(shader.get_value('v1')) print(shader.get_value('v2')) print(shader.get_value('f1')) print(shader.get_value('i1'))
x = pixel_size * (w2 + curx) y = pixel_size * (w2 + cury) sam.x = x sam.y = y sam.ix = curx sam.iy = cury return 1 """ args1 = arg_map([('endx', 0), ('endy', 0), ('tilex', 0), ('tiley', 0), ('pixel_size', 1.0), ('curx', 0), ('cury', 0), ('w2', 0.0), ('h2', 0.0)]) args2 = arg_list([('sam', sample)]) sample_shader = create_shader("generate_sample", code2, args1, args2, func=True) #print(sample_shader._code) arg_map1 = arg_map([('x', 0.0)]) code = """ sam = sample() ret = 1 while ret != 0: ret = generate_sample(sam) x = sam.y """ runtimes = [Runtime()] shader = create_shader("test", code, arg_map1, shaders=[sample_shader])
#x = pixel_size * (curx + w2) #y = pixel_size * (cury + h2) x = pixel_size * (w2 + curx) y = pixel_size * (w2 + cury) sam.x = x sam.y = y sam.ix = curx sam.iy = cury return 1 """ args1 = arg_map([('endx', 0), ('endy', 0), ('tilex', 0), ('tiley', 0), ('pixel_size', 1.0), ('curx', 0), ('cury', 0), ('w2', 0.0), ('h2', 0.0)]) args2 = arg_list([('sam', sample)]) sample_shader = create_shader("generate_sample", code2, args1, args2, func=True) #print(sample_shader._code) arg_map1 = arg_map([('x', 0.0)]) code = """ sam = sample() ret = 1 while ret != 0: ret = generate_sample(sam) x = sam.y """ runtimes = [Runtime()] shader = create_shader("test", code, arg_map1, shaders=[sample_shader]) #print(shader._code)
eye = Vector3(2.2, 3.3, 4.4) lookat = Vector3(1.1, 2.2, 0.0) distance = 3.3 sample = Sample(2.2, 3.3, 5, 6, 1.0) camera = create_perspective_camera(eye, lookat, distance) runtimes = [Runtime()] camera.prepare(runtimes) call_code = """ generate_ray(sample, ray) """ args = arg_map([('sample', Sample), ('ray', Ray)]) shader = create_shader('test', call_code, args=args, shaders=[camera.shader]) shader.prepare(runtimes) shader.set_value('sample', sample) ray = camera.execute_py(sample) shader.execute() def cmp_vec3(vec1, vec2): if round(vec1.x - vec2.x, 3) != 0: raise ValueError("Vectors are different", vec1, vec2) if round(vec1.y - vec2.y, 3) != 0: raise ValueError("Vectors are different", vec1, vec2) if round(vec1.z - vec2.z, 3) != 0: raise ValueError("Vectors are different", vec1, vec2)
nn = (2.2, 1.1, 3.4) set_rgb(slika, 1, 2, nn) rect.k = get_rgb(slika, 1, 2) rect.w = pow(rect.w, 3.3) p1 = int(3) + 4 """ code2 = """ #p1 is input argument p2 = p1 return p2 """ arg_lst = arg_list([('p1', 3)]) arg_map2 = arg_map([]) shader2 = create_shader("ret_arg", code2, arg_map2, arg_lst, func=True) runtimes = [Runtime()] shader = create_shader("test", code, arg_map1, shaders=[shader2]) print(shader._code) shader.prepare(runtimes) img = ImagePRGBA(3,3) img.set_pixel(1, 2, 0.2, 0.3, 0.1) shader.set_value('slika', img) shader.execute() print(shader.get_value('p1')) print(shader.get_value('ps.x')) print(shader.get_value('pm.x')) print(shader.get_value('p3'))
eye = Vector3(2.2, 3.3, 4.4) lookat = Vector3(1.1, 2.2, 0.0) distance = 3.3 sample = Sample(2.2, 3.3, 5, 6, 1.0) camera = create_perspective_camera(eye, lookat, distance) runtimes = [Runtime()] camera.prepare(runtimes) call_code = """ generate_ray(sample, ray) """ args = arg_map([("sample", Sample), ("ray", Ray)]) shader = create_shader("test", call_code, args=args, shaders=[camera.shader]) shader.prepare(runtimes) shader.set_value("sample", sample) ray = camera.execute_py(sample) shader.execute() def cmp_vec3(vec1, vec2): if round(vec1.x - vec2.x, 3) != 0: raise ValueError("Vectors are different", vec1, vec2) if round(vec1.y - vec2.y, 3) != 0: raise ValueError("Vectors are different", vec1, vec2) if round(vec1.z - vec2.z, 3) != 0: raise ValueError("Vectors are different", vec1, vec2)
""" arg_lst1 = arg_list([('a', Float), ('b', Integer)]) sh1 = create_function('conv_int', code2, input_args=arg_lst1) sh1.prepare(runtimes) arg_map1 = arg_map([('a', Integer), ('b', Float), ('c', Vec3), ('f', Vec3)]) code = """ a = 2 b = 2.2 c = (2, 3, 4) f = [6,7,7.7] b = conv_int(b, a) int(55) b = 3 + pow(2,3) * 2.5 #b = pow(2,3) * 2.5 + 3 """ shader = create_shader("test", code, arg_map1, shaders=[sh1]) shader.prepare(runtimes) shader.execute() print (shader._code) print(shader.get_value('a')) print(shader.get_value('b')) print(shader.get_value('c')) print(shader.get_value('f'))
code2 = """ #input a = float, b = int a = b return a """ arg_lst1 = arg_list([('a', Float), ('b', Integer)]) sh1 = create_function('conv_int', code2, input_args=arg_lst1) sh1.prepare(runtimes) arg_map1 = arg_map([('a', Integer), ('b', Float), ('c', Vec3), ('f', Vec3)]) code = """ a = 2 b = 2.2 c = (2, 3, 4) f = [6,7,7.7] b = conv_int(b, a) int(55) b = 3 + pow(2,3) * 2.5 #b = pow(2,3) * 2.5 + 3 """ shader = create_shader("test", code, arg_map1, shaders=[sh1]) shader.prepare(runtimes) shader.execute() print(shader._code) print(shader.get_value('a')) print(shader.get_value('b')) print(shader.get_value('c')) print(shader.get_value('f'))