- Home /
ShaderLab CG question
In CG vertex shader i have an output structure which contains float4 variable (as TEXCOORD1). In vertex shader i do some calculations and write results to this variable. These calulations make the same result every vertex shader run(for every vertex). But i cannot pass this result via uniform, because it is related to MVP matrix which changes almost all the time. But in shader pass it does not change, because it's the same frame. I actually tried to calculate this in script on update() and pass to shader as uniform, and after than i use it in fragment shader, but i have very slow fps in result. My solution (to calculate it every vertex shader call and keep it in v2f struct) works, but it's obviously not the most optimized one. What i was thinking about is, how can i calculate this float4 variable only one time per pass. For example if i have function on gpu which is called before all vertex and fragment shaders are called, and stores the result in "global" readonly(i know shaders work in parallel) variable, after that i would read this variable from fragment shader, that would solve my problem.
So my question is, how to make it right? Or my solution is ok? I really know very few about shaders that's why i am asking. Thanks in advance.
Your answer
![](https://koobas.hobune.stream/wayback/20220613200955im_/https://answers.unity.com/themes/thub/images/avi.jpg)