Jump to content
  • Advertisement
Sign in to follow this  
Slug

Help with pixel shader

This topic is 4681 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, can somebody show me a simle pixel shader that will just invert the red and blue component of a fragment? I just need the simplest example possible... something to start with... Thx in advance. ps: i'm using Cg.

Share this post


Link to post
Share on other sites
Advertisement

struct PS_INPUT {
float4 color : COLOR;
};

struct PS_OUTPUT {
float4 color : COLOR;
};

const float4 MULT = float4( -1, 1, -1, 1 );
const float4 ADD = float4( 1, 0, 1, 0 );

PS_OUTPUT my_pixel_shader( const PS_INPUT frag ) {
PS_OUTPUT o;
o.color = frag.color * MULT + ADD;
}


Share this post


Link to post
Share on other sites
GLSL:

Vertex Shader:

varying vec4 color;

void main(void) {
color = gl_Color;
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
}

Fragment Shader:

varying vec4 color;

void main(void) {
vec4 invvec = vec4(-1.0, 1.0, -1.0, 1.0);
vec4 addvec = vec4(1.0, 0.0, 1.0, 0.0);
gl_FragColor = color * invvec + addvec;
}

edit:
sorry, didn't read that you use cg...

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!