{"action":"created","issue":{"url":"https://api.github.com/repos/JuliaGL/GLVisualize.jl/issues/56","repository_url":"https://api.github.com/repos/JuliaGL/GLVisualize.jl","labels_url":"https://api.github.com/repos/JuliaGL/GLVisualize.jl/issues/56/labels{/name}","comments_url":"https://api.github.com/repos/JuliaGL/GLVisualize.jl/issues/56/comments","events_url":"https://api.github.com/repos/JuliaGL/GLVisualize.jl/issues/56/events","html_url":"https://github.com/JuliaGL/GLVisualize.jl/issues/56","id":130829529,"number":56,"title":"Dynamic creation of optimized shaders","user":{"login":"paulmthompson","id":8922014,"avatar_url":"https://avatars.githubusercontent.com/u/8922014?v=3","gravatar_id":"","url":"https://api.github.com/users/paulmthompson","html_url":"https://github.com/paulmthompson","followers_url":"https://api.github.com/users/paulmthompson/followers","following_url":"https://api.github.com/users/paulmthompson/following{/other_user}","gists_url":"https://api.github.com/users/paulmthompson/gists{/gist_id}","starred_url":"https://api.github.com/users/paulmthompson/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/paulmthompson/subscriptions","organizations_url":"https://api.github.com/users/paulmthompson/orgs","repos_url":"https://api.github.com/users/paulmthompson/repos","events_url":"https://api.github.com/users/paulmthompson/events{/privacy}","received_events_url":"https://api.github.com/users/paulmthompson/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2016-02-02T21:51:12Z","updated_at":"2016-02-05T20:10:45Z","closed_at":null,"body":"I've been going through your next2 branch and was wondering if you have tried any experiments with creating vertex shaders on the fly to try to push some of the work to the GPU. When I look at your bouncy.jl example, am I correct thinking that the Reactive package is using a timer to continuously update all of the circle positions and these are pushed to the GPU with every new timestamp?\r\n\r\nIt might be more efficient to use a macro or some other metaprogramming technique to create shaders on the fly that would apply the position transformations on the GPU rather than have the CPU do it and push the results there. Very roughly it could look something like this to change the x and y position:\r\n\r\n```\r\nmyexpr=\"pos.x+=t;\r\npos.y+=t\"\r\n\r\nmyshaderbody= \"\"\"\r\n{{GLSL_VERSION}}\r\n{{kernel}} // kernel function will get spliced into the shader\r\n\r\n    #version 140\r\n\r\n    in vec2 position;\r\n\r\n    uniform float t;\r\n\r\n    void main() {\r\n        vec2 pos = position;\r\n        $myexpr\r\n        gl_Position = vec4(pos, 0.0, 1.0);\r\n\r\n}\r\n\"\"\"\r\n\r\nconst myshader = Shader(symbol(@__FILE__), (Vector{UInt8}(myshaderbody)), GLAbstraction.GL_COMPUTE_SHADER)\r\n```\r\n\r\nAs computations get more complex, this would get more beneficial. Have you tried anything like this in the past? I'd be happy to make a fork and get a working prototype started."},"comment":{"url":"https://api.github.com/repos/JuliaGL/GLVisualize.jl/issues/comments/180538015","html_url":"https://github.com/JuliaGL/GLVisualize.jl/issues/56#issuecomment-180538015","issue_url":"https://api.github.com/repos/JuliaGL/GLVisualize.jl/issues/56","id":180538015,"user":{"login":"SimonDanisch","id":1010467,"avatar_url":"https://avatars.githubusercontent.com/u/1010467?v=3","gravatar_id":"","url":"https://api.github.com/users/SimonDanisch","html_url":"https://github.com/SimonDanisch","followers_url":"https://api.github.com/users/SimonDanisch/followers","following_url":"https://api.github.com/users/SimonDanisch/following{/other_user}","gists_url":"https://api.github.com/users/SimonDanisch/gists{/gist_id}","starred_url":"https://api.github.com/users/SimonDanisch/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/SimonDanisch/subscriptions","organizations_url":"https://api.github.com/users/SimonDanisch/orgs","repos_url":"https://api.github.com/users/SimonDanisch/repos","events_url":"https://api.github.com/users/SimonDanisch/events{/privacy}","received_events_url":"https://api.github.com/users/SimonDanisch/received_events","type":"User","site_admin":false},"created_at":"2016-02-05T20:10:45Z","updated_at":"2016-02-05T20:10:45Z","body":"Thanks :)\r\n\r\nI was thinking to create something like that for the near future:\r\n```Julia\r\nimmutable Material{ShaderType, ColorType, ReflectanceType}\r\ncolor::ColorType\r\nreflectance::ReflectanceType\r\nend\r\nimmutable Instances{PositionType, ScaleType, RotationType}\r\nposition::PositionType\r\nscale::ScaleType\r\nrotation::RotationType\r\nend\r\n\r\nfunction call(m::Material{Phong}, backend::OpenGL)\r\n\"\"\"\r\nin $(to_gltype(m.color)) color;\r\nin $(to_gltype(m.reflectance)) reflectance;\r\nvec3 phong_lighting(...){\r\n...\r\n}\r\n\"\"\"\r\nend\r\n\r\nfunction call(instance::Instance, backend::OpenGL)\r\n\"\"\"\r\nin $(to_gltype(instance.position)) position;\r\nin $(to_gltype(instance.scale)) scale;\r\nin $(to_gltype(instance.rotation)) rotation;\r\nvec3 do_position_transform(...){\r\n...\r\n}\r\n\"\"\"\r\nend\r\n\r\nfunction visualize{Inst,Mat}(instance::Inst, material::Mat, backend)\r\n    vertex_kernel = Inst(backend)\r\n    fragmen_kernel = Mat(backend)\r\n    compile(vertex_kernel, fragmen_kernel)\r\nend\r\n```\r\n\r\nThis is obviously not really thought out yet, but it would nicely scale with Vulkan and offer the user the possibility to overwrite and customize the whole pipeline right away! It would also make it easier to create shaders for different OpenGL and WebGL versions..."}}