varjo
varjo copied to clipboard
glsl es support
Hello! Hope all is well :)
A couple weeks ago I looked into the details of abstracting glsl/glsl es shaders and found this blog post: https://goharsha.com/blog/abstracting-glsl-and-glsl-es-shaders/ (praise google).
I was able to slightly revise the gen-shader-string
to have #define
directives to give glsl es the syntax it needs to be happy. My hacky change looks like this:
(defun gen-shader-string (post-proc-obj)
(with-slots (varjo::env) post-proc-obj
(format nil "~%~{~%~{~a~%~}~}" ;; "100 es"
;; (varjo::get-version-from-context varjo::env)
(loop :for part :in
(list
`("#define in varying"
"#define texture texture2D"
,(format nil "#define ~a gl_FragColor" (varjo::glsl-name (first (varjo::out-vars post-proc-obj))))
"precision mediump float;")
(varjo::used-types post-proc-obj)
(mapcar #'varjo::%glsl-decl (varjo::in-args post-proc-obj))
;;(mapcar #'varjo::%glsl-decl (varjo::out-vars post-proc-obj))
(varjo::remove-empty
(append
(mapcar #'varjo::%glsl-decl (varjo::uniforms post-proc-obj))
(mapcar #'varjo::%glsl-decl (varjo::stemcells post-proc-obj))))
(varjo::signatures varjo::env)
(let* ((funcs (varjo::all-functions post-proc-obj))
(code (remove nil (mapcar #'varjo::glsl-code funcs))))
(reverse code)))
:if part :collect part))))
I would be happy to submit a PR for adding glsl es support--just wanted to reach out if you had suggestions of the best way to optionally add these directives. I was able to use the hack above to get some varjo glsl goodness on my personal webpage http://johannbestowro.us. Pretty cool!
Hi!
Yeah ES support would be interesting, however I think there will be a lot more fiddly details we would need to get right. To start though, someone needs to go through glsl-spec and add version info for GLES.
If your hack is working for you then it's probably best to stick with it for now but I'd rather not add it in to Varjo as supporting it will get tricky. It'll be better for us to gradually fix the problems in the correct places (like emitting attribute
& varying
based on version)
https://www.khronos.org/registry/OpenGL/index_es.php
Note to self: GLSL_ES_Specification_3.00.pdf has the changes from regular glsl-300. Super useful.