i've created subclass of glkviewcontroller render waveforms using glkbaseeffect works fine.
i want use own vertex , fragment shaders, used boilerplate code default opengl game project. both shaders compile, link, , usable. can alter color in vertex shader without issue.
the problem i'm having passing own uniforms fragment shader. can pass vertex shader , use there, when declare same variable in
code:
// vertex shader
attribute vec4 position; uniform float amplitudemax; void main() { gl_position = position + amplitudemax; // works , offsets drawing }
// fragment shader
uniform float amplitudemax; // fails compile //uniform float amplitudemax; // compiles fine void main() { gl_fragcolor = vec4(0.0, 0.0, 1.0, 1.0); }
if curious, here how set uniforms , shaders
func loadshaders() -> bool { // copied default opengl game project // link program ... uniforms[uniform_amplitude_max] = glgetuniformlocation(program, "amplitudemax") // release shaders ... } // draw loop func render() { configureshaders() // ... draw } func configureshaders() { gluseprogram(program) let max = audiomanager.sharedinstance.buffermanager.currentpower) gluniform1f(uniforms[uniform_amplitude_max], max) }
i had idea of passing value vertex shader fragment shader using varying float. again can declare , use variable in vertex shader delaring in fragment shader cause fail compiling.
edit: --------------------------------------------------
through trial , error found if (in fragment shader) qualify uniform declaration precision works both uniforms , varying (can pass vertex shader).
uniform lowp float amplitudemax; void main() { gl_fragcolor = vec4(amplitudemax, 0.0, 1.0, 1.0); }
Comments
Post a Comment