def _get_scene( self, file0, file1, diff_mode=False, split=(0.5, 0.5), vertical_split=True, show_r=True, show_g=True, show_b=True, show_a=True, premultiplied=False, threshold=0.001, ): vert = pkgutil.get_data("pynodegl_utils.diff.shaders", "diff.vert") frag = pkgutil.get_data("pynodegl_utils.diff.shaders", "diff.frag") assert vert is not None and frag is not None quad = ngl.Quad((-1, -1, 0), (2, 0, 0), (0, 2, 0)) prog = ngl.Program(vertex=vert.decode(), fragment=frag.decode()) prog.update_vert_out_vars( uv=ngl.IOVec2(), tex0_coord=ngl.IOVec2(), tex1_coord=ngl.IOVec2(), ) scene = ngl.Render(quad, prog) scene.update_frag_resources( tex0=ngl.Texture2D(data_src=ngl.Media(file0)), tex1=ngl.Texture2D(data_src=ngl.Media(file1)), split=ngl.UniformVec2(split, live_id="split"), diff_mode=ngl.UniformBool(diff_mode, live_id="diff_mode"), vertical_split=ngl.UniformBool(vertical_split, live_id="vertical_split"), show_r=ngl.UniformBool(show_r, live_id="show_r"), show_g=ngl.UniformBool(show_g, live_id="show_g"), show_b=ngl.UniformBool(show_b, live_id="show_b"), show_a=ngl.UniformBool(show_a, live_id="show_a"), premultiplied=ngl.UniformBool(premultiplied, live_id="premultiplied"), threshold=ngl.UniformFloat(threshold, live_id="threshold", live_max=0.1), ) scene.update_vert_resources( reframing_scale=ngl.UniformFloat( self._reframing_scale, live_id="reframing_scale", live_min=self._MIN_SCALE, live_max=self._MAX_SCALE, ), reframing_off=ngl.UniformVec2( self._reframing_off, live_id="reframing_off", live_min=(-self._MAX_SCALE, -self._MAX_SCALE), live_max=(self._MAX_SCALE, self._MAX_SCALE), ), ) return scene
def compute_image_load_store(cfg, show_dbg_points=False): size = _N texture_data = ngl.BufferFloat( data=array.array("f", [x / (size**2) for x in range(size**2)])) texture_r = ngl.Texture2D(format="r32_sfloat", width=size, height=size, data_src=texture_data) texture_g = ngl.Texture2D(format="r32_sfloat", width=size, height=size, data_src=texture_data) texture_b = ngl.Texture2D(format="r32_sfloat", width=size, height=size, data_src=texture_data) scale = ngl.Block( fields=[ngl.UniformVec2(value=(-1.0, 1.0), label="factors")], layout="std140", ) texture_rgba = ngl.Texture2D(width=size, height=size) program = ngl.ComputeProgram(_IMAGE_LOAD_STORE_COMPUTE, workgroup_size=(size, size, 1)) program.update_properties( texture_r=ngl.ResourceProps(as_image=True), texture_g=ngl.ResourceProps(as_image=True), texture_b=ngl.ResourceProps(as_image=True), texture_rgba=ngl.ResourceProps(as_image=True, writable=True), ) compute = ngl.Compute(workgroup_count=(1, 1, 1), program=program) compute.update_resources(texture_r=texture_r, texture_g=texture_g, texture_b=texture_b, scale=scale, texture_rgba=texture_rgba) render = ngl.RenderTexture(texture_rgba) group = ngl.Group(children=(compute, render)) if show_dbg_points: cuepoints = _get_compute_histogram_cuepoints() group.add_children(get_debug_points(cfg, cuepoints)) return group
def py_bindings_dict(): foo = ngl.UniformVec3(value=(1, 2, 3), label="foo-node") assert foo.set_value(3, 2, 1) == 0 render = ngl.Render(vert_resources=dict(foo=foo)) assert render.set_label("r") == 0 # Delete the previous entry and add another ret = render.update_vert_resources( foo=None, bar=ngl.UniformFloat(value=4, label="bar-node"), ) assert ret == 0 # Update by using a dict ret = render.update_vert_resources( dict( foo=ngl.UniformVec2(), bar=ngl.EvalFloat(), )) assert ret == 0
array_vec3=lambda data: ngl.BufferVec3(data=data), array_vec4=lambda data: ngl.BufferVec4(data=data), single_bool=lambda data: ngl.UniformBool(data), single_float=lambda data: ngl.UniformFloat(data), single_int=lambda data: ngl.UniformInt(data), single_ivec2=lambda data: ngl.UniformIVec2(data), single_ivec3=lambda data: ngl.UniformIVec3(data), single_ivec4=lambda data: ngl.UniformIVec4(data), single_uint=lambda data: ngl.UniformUInt(data), single_uvec2=lambda data: ngl.UniformUIVec2(data), single_uvec3=lambda data: ngl.UniformUIVec3(data), single_uvec4=lambda data: ngl.UniformUIVec4(data), single_mat4=lambda data: ngl.UniformMat4(data), single_quat_mat4=lambda data: ngl.UniformQuat(data, as_mat4=True), single_quat_vec4=lambda data: ngl.UniformQuat(data, as_mat4=False), single_vec2=lambda data: ngl.UniformVec2(data), single_vec3=lambda data: ngl.UniformVec3(data), single_vec4=lambda data: ngl.UniformVec4(data), ) def _get_field_decl(layout, f): t = f['type'] t = t.split('_')[1] if t.startswith('quat') else t return '{}{:<5} {}{}{}'.format('uniform ' if layout == 'uniform' else '', t, 'field_' if layout == 'uniform' else '', f['name'], '[%d]' % f['len'] if 'len' in f else '') def get_random_block_info(spec, seed=0, layout=LAYOUTS[0], color_tint=True):