Modifying a uniform variable inside a shader program to be used by another shader program - RenderMonkey

228 views Asked by At

RenderMonkey is pretty ancient so I'm struggling to find a way to do this. To be clear, the only reason I'm using RenderMonkey is because it's for a University assignment.

RenderMonkey allows you to define uniform variables in the workspace that your shader programs can refer to. They also offer "variable semantics" which are predefined variables that change depending on the situation. For example, time elapsed. As time increases, the float "time" increases.

I have an elephant with a gun strapped to it's back (strange I know). The gun fires particles over time. The gun also rotates over time. In order for the bullet particles to fire in the correct direction, they also need to be rotated in the same way as the gun. Applying the same rotation calculation (the one that depends on time elapsed) used for the gun, to the bullets was my first thought but this causes the bullets to continue rotating after they've been fired which isn't ideal.

I was wondering if there's a way to have one uniform variable "gunAngle" that is edited in the gun shader (i.e rotated in the gun pass) and then that modified value is given to the bullet particle shader. If that's not possible in Rendermonkey, does anyone have any ideas for a workaround to this?

1

There are 1 answers

2
Rabbid76 On

The "gunAngle" must be calculated on the CPU and set to the uniforms in each frame. If you want to use data in multiple shader programs you have to use a Shader Storage Buffer Object or Uniform Block.