Jump to content

Shader swizzling


Recommended Posts



I am playing with Shaders (filters). Below is my shader code

I am not able to swizzle rgba values (https://www.opengl.org/wiki/GLSL_Optimizations). Can someone help?


precision mediump float;

varying vec2 vTextureCoord;
varying vec4 vColor;

uniform sampler2D uSampler;
uniform float customUniform;

void main(void)
   vec2 uvs = vTextureCoord.xy;

   vec4 fg = texture2D(uSampler, vTextureCoord);

   // THIS doesn't work
   // fg.rg = 0.0;

   fg.r = 0.0;
   fg.g = 0.0;
   gl_FragColor = fg;



Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...