Make camera in webgl with vertex shader? -
i have idea, i'm not sure it, because i'm no guru in webgl.
in webgl, there no camera. if 1 want simulate it, has operations lot of objects... precise, must change position hundreds of thousands of vertices. didn't study three.js or babylon js deep, have no clue, how work cameras.
since vertex shader can transform vertex positions , because can pass camera matrix
vertex shader, make sence let make calculations, gpu hard work instead of cpu?
do mean : create view matrix in vertex shader using data position , orientation instead of create application , send resulting matrix in shader ?
actually last case solutions three.js , lot of others : object representing camera can manipulated javascript. @ draw, view matrix built position , orientation parameters, , sent active shader program.
creating view matrix done in steps :
- create identity matrix (no transformation) ;
- combine matrix each transformations apply camera : translations , rotations ;
- invert matrix (this computation may quite heavy).
to decide (or when) matrix should computed depends on idea view matrix not change in process of drawing 1 image. in fact view matrix , projection matrix meant modified between 2 images.
don't forget vertex shader executed once each vertex send pipeline. if make computation of view matrix in vertex shader, re-computed thousand times per image.
so computation of view matrix should better stay in application , sent shader program.
if want take benefit performances of shaders in floating point arithmetics, can think using compute shaders (unfortunately not present in webgl) or take account mechanics read data shader programs in order compute matrix once, , send @ next draw calls.
Comments
Post a Comment