kovasb / gamma

glsl shaders made simple
Eclipse Public License 1.0
306 stars 20 forks source link

How to specify "precision mediump float;" in fragment shaders? #8

Closed sgrove closed 9 years ago

sgrove commented 9 years ago

I'm getting the error:

Uncaught Error: failed to compile fragment-shader:ERROR: 0:5: '' : No precision specified for (float)

from glsl:

uniform sampler2D uSampler;
varying mediump vec2 vTextureCoord;
varying mediump vec3 vLightWeighting;
void main(void){
vec4 v118;
(v118 = texture2D(uSampler, vec2(vTextureCoord.st)));
(gl_FragColor = vec4((v118.rgb * vLightWeighting), v118.a));
}

from gamma:

(def v-texture-coord
  (g/varying "vTextureCoord" :vec2 :mediump))

(def v-light-weighting
  (g/varying "vLightWeighting" :vec3 :mediump))

(def u-sampler
  (g/uniform "uSampler" :sampler2D))

(def program source
(p/program
{:fragment-shader (let [texture-color (g/texture2D u-sampler (g/vec2 (g/swizzle v-texture-coord :st)))
                           rgb           (g/* (g/swizzle texture-color :rgb) v-light-weighting)
                           a             (g/swizzle texture-color :a)]
                       {(g/gl-frag-color) (g/vec4 rgb a)})})

While trying to produce the equivalent of:

    precision mediump float;

    varying vec2 vTextureCoord;
    varying vec3 vLightWeighting;

    uniform sampler2D uSampler;

    void main(void) {
        vec4 textureColor = texture2D(uSampler, vec2(vTextureCoord.s, vTextureCoord.t));
        gl_FragColor = vec4(textureColor.rgb * vLightWeighting, textureColor.a);
    }
kovasb commented 9 years ago

Fixed as of https://github.com/kovasb/gamma/commit/8de0284f777ef15505273ef526b6050ead604cdf

program now takes a second arg: (p/program shaders {:precision {:float :mediump}})

If we need to specify precision defaults separately for vertex vs fragment shaders, will open a ticket for that.

kovasb commented 9 years ago

Changed the api to:

(p/program {:vertex-shader vs :fragment-shader fs :precision {:float :mediump}})

so its still just 1 argument. Not sure what I was thinking before.