Skip to main content
gamedev.net
🔒 Locked 🎮 Unity

Shader Function & Transformations

Started by dehebo 0 replies 800+ views
Original Post
dehebo
dehebo
Hi, I am wondering how a function called outside of main in a vertex shader is handled. if we have a vertex shader like...


mat4 createMatrix()
{...}
mat4 test = createMatrix();

void main()
{...}
Q. Does the assignment mat4 test = createMatrix(); get calculated every vertex? Or just the once? I am basically looking at doing my OpenGL transformations(translate, rotate) within the Vertex shader and am trying to figure out the most efficient approach... 1. constructing transform matrix outside shader then passing in as a uniform, along with passing in the modelView/Projection. then do matri multiplication in the shader. 2. pass in transform values(translate, rotate) to shader, construct matrix here then do the same multiplications. Anyone advise would be appreciated. Thanks.
Geometrian
Geometrian
It will be quite fast either way--though my thinking is that if you're using the same thing for every vertex, or multiple frames, etc., best to do it in software. That said, matrix operations are "blazingly fast" on the GPU. In either case, a few matrix operations is nothing.
[size="1"]And a Unix user said rm -rf *.* and all was null and void...|There's no place like 127.0.0.1|The Application "Programmer" has unexpectedly quit. An error of type A.M. has occurred.
[size="2"]

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.