### Chromatic Aberration Shader

Hi all,

I’ve finally started looking into glsl, and intrigued by the

chromatic aberration shader I tried implementing it from the orange

book…

but, here goes, of course it doesn’t work ;)

It’s probably something stupid, or maybe it’s completely and utterly

wrong…

I get ‘undeclared identifier’ errors in the max window.

Chromatic Aberration

< ![CDATA[

varying vec3 Reflect;

varying vec3 RefractR;

varying vec3 RefractG;

varying vec3 RefractB;

varying float Ratio;

void main()

{

vec4 ecPosition = gl_ModelViewMatrix * gl_Vertex;

vec3 ecPosition3 = ecPosition.xyz / ecPosition.w;

vec3 i = normalize(ecPosition3);

vec3 n = normalize(gl_NormalMatrix * gl_Normal);

Ratio = F + (1.0 – F) * pow((1.0 – dot(-i, n)), FresnelPower);

RefractR = refract(i, n, EtaR);

RefractR = vec3(gl_TextureMatrix[0] * vec4(RefractR, 1.0));

RefractG = refract(i, n, EtaG);

RefractG = vec3(gl_TextureMatrix[0] * vec4(RefractG, 1.0));

RefractB = refract(i, n, EtaB);

RefractB = vec3(gl_TextureMatrix[0] * vec4(RefractB, 1.0));

Reflect = reflect(i, n);

Reflect = vec3(gl_TextureMatrix[0] * vec4(Reflect, 1.0));

gl_Position = ftransform();

}

]]>

Brecht Debackere

http://www.autofasurer.net

M+32(0)498319302

F+32(0)70429559

Skype : Bdebackere

brecht@visualantics.net

Hi.

A few things

I do not believe you are allowed to set parameter defaults to formulas :

>

Do this math in the shader, or outside of it.

Also, typically jitter binds the textures within the shader to

texture units via

(for zeroth texture unit)

and lastly but most importantly, you are not, as far as I can see,

specifying gl_FragColor, which is reqired in a fragment program to

tell the GPU what your output color is. In fact, it seems as though

you do not have a fragment program at all.

On Sep 20, 2007, at 6:26 AM, Brecht Debackere wrote:

> Hi all,

>

> I’ve finally started looking into glsl, and intrigued by the

> chromatic aberration shader I tried implementing it from the orange

> book…

> but, here goes, of course it doesn’t work ;)

> It’s probably something stupid, or maybe it’s completely and

> utterly wrong…

> I get ‘undeclared identifier’ errors in the max window.

>

>

>

>

> Chromatic Aberration

>

>

>

>

>

>

>

>

>

> < ![CDATA[

>

> varying vec3 Reflect;

> varying vec3 RefractR;

> varying vec3 RefractG;

> varying vec3 RefractB;

> varying float Ratio;

>

> void main()

> {

>

> vec4 ecPosition = gl_ModelViewMatrix * gl_Vertex;

> vec3 ecPosition3 = ecPosition.xyz / ecPosition.w;

>

> vec3 i = normalize(ecPosition3);

> vec3 n = normalize(gl_NormalMatrix * gl_Normal);

>

> Ratio = F + (1.0 – F) * pow((1.0 – dot(-i, n)), FresnelPower);

>

> RefractR = refract(i, n, EtaR);

> RefractR = vec3(gl_TextureMatrix[0] * vec4(RefractR, 1.0));

>

> RefractG = refract(i, n, EtaG);

> RefractG = vec3(gl_TextureMatrix[0] * vec4(RefractG, 1.0));

>

> RefractB = refract(i, n, EtaB);

> RefractB = vec3(gl_TextureMatrix[0] * vec4(RefractB, 1.0));

>

> Reflect = reflect(i, n);

> Reflect = vec3(gl_TextureMatrix[0] * vec4(Reflect, 1.0));

>

> gl_Position = ftransform();

> }

> ]]>

>

>

>

>

>

>

> Brecht Debackere

> http://www.autofasurer.net

> M+32(0)498319302

> F+32(0)70429559

> Skype : Bdebackere

> brecht@visualantics.net

>

>

>

v a d e //

http://www.vade.info

abstrakt.vade.info

right. back to the drawing board :)

thanks for the explanation…

…You live and learn. At any rate, you live.

On 20 Sep 2007, at 18:42, vade wrote:

> Hi.

>

> A few things

>

> I do not believe you are allowed to set parameter defaults to

> formulas :

>>

>

> Do this math in the shader, or outside of it.

>

> Also, typically jitter binds the textures within the shader to

> texture units via

>

> >

> (for zeroth texture unit)

>

> and lastly but most importantly, you are not, as far as I can see,

> specifying gl_FragColor, which is reqired in a fragment program to

> tell the GPU what your output color is. In fact, it seems as though

> you do not have a fragment program at all.

>

>

> On Sep 20, 2007, at 6:26 AM, Brecht Debackere wrote:

>

>> Hi all,

>>

>> I’ve finally started looking into glsl, and intrigued by the

>> chromatic aberration shader I tried implementing it from the

>> orange book…

>> but, here goes, of course it doesn’t work ;)

>> It’s probably something stupid, or maybe it’s completely and

>> utterly wrong…

>> I get ‘undeclared identifier’ errors in the max window.

>>

>>

>>

>>

>> Chromatic Aberration

>>

>> >> >> >> >>

>>

>>

>>

>>

>>

>>

>>

>> < ![CDATA[

>>

>> varying vec3 Reflect;

>> varying vec3 RefractR;

>> varying vec3 RefractG;

>> varying vec3 RefractB;

>> varying float Ratio;

>>

>> void main()

>> {

>>

>> vec4 ecPosition = gl_ModelViewMatrix * gl_Vertex;

>> vec3 ecPosition3 = ecPosition.xyz / ecPosition.w;

>>

>> vec3 i = normalize(ecPosition3);

>> vec3 n = normalize(gl_NormalMatrix * gl_Normal);

>>

>> Ratio = F + (1.0 – F) * pow((1.0 – dot(-i, n)), FresnelPower);

>>

>> RefractR = refract(i, n, EtaR);

>> RefractR = vec3(gl_TextureMatrix[0] * vec4(RefractR, 1.0));

>>

>> RefractG = refract(i, n, EtaG);

>> RefractG = vec3(gl_TextureMatrix[0] * vec4(RefractG, 1.0));

>>

>> RefractB = refract(i, n, EtaB);

>> RefractB = vec3(gl_TextureMatrix[0] * vec4(RefractB, 1.0));

>>

>> Reflect = reflect(i, n);

>> Reflect = vec3(gl_TextureMatrix[0] * vec4(Reflect, 1.0));

>>

>> gl_Position = ftransform();

>> }

>> ]]>

>>

>>

>>

>>

>>

>>

>> Brecht Debackere

>> http://www.autofasurer.net

>> M+32(0)498319302

>> F+32(0)70429559

>> Skype : Bdebackere

>> brecht@visualantics.net

>>

>>

>>

>

> v a d e //

>

> http://www.vade.info

> abstrakt.vade.info

>

>

>

Brecht Debackere

http://www.autofasurer.net

M+32(0)498319302

F+32(0)70429559

Skype : Bdebackere

brecht@visualantics.net

Apologies for digging up this old thread. I’ve finally continued my

dabbling with glsl, still the same one from the orange book.

I’ve started anew and so far came up with nothing much except for

trying to fit the code into the .jxs format. In the end I’m trying to

find figure out how the examples in the orange book translate to jitter.

Surprisingly, it’s not working ;) Any shader guru’s willing to stare

into this mess?

const float EtaR = 0.65;

const float EtaG = 0.67;

const float EtaB = 0.69;

const float FresnelPower = 5.0;

const float F = ((1.0-EtaG)*(1.0-EtaG))/((1.0+EtaG)*(1.0+EtaG));

varying vec3 Reflect;

varying vec3 RefractR;

varying vec3 RefractG;

varying vec3 RefractB;

varying float Ratio;

void main()

{

vec4 ecPosition = gl_ModelViewMatrix * gl_Vertex;

vec3 ecPosition3 = ecPosition.xyz / ecPosition.w;

vec3 i = normalize(ecPosition3);

vec3 n = normalize(gl_NormalMatrix * gl_Normal);

Ratio = F + (1.0 – F) * pow((1.0 – dot(-i, n)), FresnelPower);

RefractR = refract(i, n, EtaR);

RefractR = vec3(gl_TextureMatrix[0] * vec4(RefractR, 1.0));

RefractG = refract(i, n, EtaG);

RefractG = vec3(gl_TextureMatrix[0] * vec4(RefractG, 1.0));

RefractB = refract(i, n, EtaB);

RefractB = vec3(gl_TextureMatrix[0] * vec4(RefractB, 1.0));

Reflect = reflect(i,n);

Reflect = vec3(gl_TextureMatrix[0]* vec4(Reflect, 1.0));

gl_Position = ftransform();

}

]]>

varying vec3 Reflect;

varying vec3 RefractR;

varying vec3 RefractG;

varying vec3 RefractB;

varying float Ratio;

uniform samplerCube Cubemap;

void main()

{

vec3 refractColor, reflectColor;

refractColor.r = vec3(textureCube(Cubemap, RefractR)).r;

refractColor.g = vec3(textureCube(Cubemap, RefractG)).g;

refractColor.b = vec3(textureCube(Cubemap, RefractB)).b;

reflectColor = vec3(textureCube(Cubemap, Reflect));

vec3 color = mix(refractColor, reflectColor, Reflect));

gl_FragColor = vec4(color, 1.0);

}

]]>

I *believe* this is not working because Jitter 1.7, to my knowledge, does not support "uniform samplerCube Cubemap". I could be mistaken though.

On Tue, Jun 10, 2008 at 11:12 PM, vade

>

> I *believe* this is not working because Jitter 1.7, to my knowledge, does not support "uniform samplerCube Cubemap". I could be mistaken though.

>

Actually, one of the new things in Jitter 1.7 is cubemap support. See

jit.gl.cubemap’s help for more on this. As an example shader, here’s

a Fresnel shader that mixes reflection and refraction based on the

angle of a ray hitting the object:

varying vec3 V;

varying vec3 N;

void main()

{

gl_Position = ftransform();

V = (gl_ModelViewMatrix * gl_Vertex).xyz;

N = gl_NormalMatrix * gl_Normal;

}

]]>

varying vec3 V;

varying vec3 N;

uniform samplerCube environmentMap;

uniform vec3 eyePosition;

uniform vec3 fresnelTerms;

void main()

{

vec3 Nn = normalize(N);

vec3 I = normalize(V – eyePosition);

float etaRatio = 0.75;

vec3 R = reflect(I, Nn);

vec3 Rf = refract(I, N, etaRatio);

float reflectionCoeff = max(0., min(1., fresnelTerms.x + fresnelTerms.y *

pow(1.+dot(I, N), fresnelTerms.z)));

vec4 reflectedColor = textureCube(environmentMap, R);

vec4 refractedColor = textureCube(environmentMap, Rf);

gl_FragColor = mix(reflectedColor, refractedColor, reflectionCoeff);

}

]]>

I’m not sure why you’re multiplying the refractino vector by the

gl_TextureMatrix. I think this might be your problem. See the shader

I just posted as it does most of what you want. You’ll just have to

move some things from the fragment shader to the vertex shader.

wes

Thanks guys. I’ll scrutinize that shader.

To elaborate on the gl_TextureMatrix : this code is literally from

the orange book. That’s what I’m trying to find out: how to get the

examples in there to work.

On 11 Jun 2008, at 08:42, Wesley Smith wrote:

> I’m not sure why you’re multiplying the refractino vector by the

> gl_TextureMatrix. I think this might be your problem. See the shader

> I just posted as it does most of what you want. You’ll just have to

> move some things from the fragment shader to the vertex shader.

>

> wes

On Mon, Jun 9, 2008 at 12:51 PM, Brecht Debackere

wrote:

> Apologies for digging up this old thread. I’ve finally continued my

> dabbling with glsl, still the same one from the orange book.

> I’ve started anew and so far came up with nothing much except for trying to

> fit the code into the .jxs format. In the end I’m trying to find figure out

> how the examples in the orange book translate to jitter.

>

> Surprisingly, it’s not working ;) Any shader guru’s willing to stare into

> this mess?

>

I also copied the chromatic Aberration shader from the Orange Book and can

get a result in Jitter. However, when I copy the code from your post I get

a compilation error when I try to use it. I seem to remember trying a

shader that you posted previously (?) but had the same result. I looked at

the code and couldn’t find any difference between your version and mine but

put it down to not looking hard enough.

Whenever I copy code from a browser I get rid of hidden formatting (by

selecting zap gremlins in text wrangler), sometimes this can interfere with

the code when it gets compiled. Also, I’ve found that my graphics card

doesn’t support some shaders. You might want to check that yours supports

the gl and shading code that you use.

Anyway, here’s a version of the same shader that I did to try and understand

what was happening. I simply changed the varying variables to uniform ones

that can be altered from Jitter. If you can get it to work it might help to

demonstrate how to draw up the jxs files for Jitter.

pelado

//

// Vertex shader for chromatic aberration effect

//

// Author: Randi Rost

//

// Copyright (c) 2003-2006: 3Dlabs, Inc.

//

// See 3Dlabs-License.txt for license information

// changed original varying Eta values to uniform vec3 – pelado

uniform vec3 Eta;

uniform float FresnelPower;

varying vec3 RefractR;

varying vec3 RefractG;

varying vec3 RefractB;

varying float Ratio;

float F = float(((1.0-Eta.g) * (1.0-Eta.g)) / ((1.0+Eta.g) * (1.0+Eta.g)));

void main()

{

vec4 ecPosition = gl_ModelViewMatrix * gl_Vertex;

vec3 ecPosition3 = ecPosition.xyz / ecPosition.w;

vec3 i = normalize(ecPosition3);

vec3 n = normalize(gl_NormalMatrix * gl_Normal);

Ratio = F + (1.0 – F) * pow((1.0 – dot(-i, n)), FresnelPower);

RefractR = refract(i, n, Eta.r);

RefractR = vec3(gl_TextureMatrix[0] * vec4(RefractR, 1.0));

RefractG = refract(i, n, Eta.g);

RefractG = vec3(gl_TextureMatrix[0] * vec4(RefractG, 1.0));

RefractB = refract(i, n, Eta.b);

RefractB = vec3(gl_TextureMatrix[0] * vec4(RefractB, 1.0));

Reflect = reflect(i, n);

Reflect = vec3(gl_TextureMatrix[0] * vec4(Reflect, 1.0));

gl_Position = ftransform();

}

]]>

//

// Fragment shader for chromatic aberration effect

//

// Author: Randi Rost

//

// Copyright (c) 2003-2006: 3Dlabs, Inc.

//

// See 3Dlabs-License.txt for license information

//

varying vec3 RefractR;

varying vec3 RefractG;

varying vec3 RefractB;

varying float Ratio;

uniform samplerCube Cubemap;

void main()

{

vec3 refractColor, reflectColor;

refractColor.r = vec3(textureCube(Cubemap, RefractR)).r;

refractColor.g = vec3(textureCube(Cubemap, RefractG)).g;

refractColor.b = vec3(textureCube(Cubemap, RefractB)).b;

reflectColor = vec3(textureCube(Cubemap, Reflect));

vec3 color = mix(refractColor, reflectColor, Ratio);

gl_FragColor = vec4(color, 1.0);

}

]]>

great! I get no more errors at least with yours. I might ‘ve made

some typo’s along the way since I copied it manually from the book.

There are still some things I don’t fully understand though, since it

only seems to color my object black; the cubemap e.g. where should it

come from?

On 11 Jun 2008, at 17:27, pelado wrote:

> On Mon, Jun 9, 2008 at 12:51 PM, Brecht Debackere

>

> Apologies for digging up this old thread. I’ve finally continued my

> dabbling with glsl, still the same one from the orange book.

> I’ve started anew and so far came up with nothing much except for

> trying to fit the code into the .jxs format. In the end I’m trying

> to find figure out how the examples in the orange book translate to

> jitter.

>

> Surprisingly, it’s not working ;) Any shader guru’s willing to

> stare into this mess?

>

> I also copied the chromatic Aberration shader from the Orange Book

> and can get a result in Jitter. However, when I copy the code from

> your post I get a compilation error when I try to use it. I seem

> to remember trying a shader that you posted previously (?) but had

> the same result. I looked at the code and couldn’t find any

> difference between your version and mine but put it down to not

> looking hard enough.

>

> Whenever I copy code from a browser I get rid of hidden formatting

> (by selecting zap gremlins in text wrangler), sometimes this can

> interfere with the code when it gets compiled. Also, I’ve found

> that my graphics card doesn’t support some shaders. You might want

> to check that yours supports the gl and shading code that you use.

>

> Anyway, here’s a version of the same shader that I did to try and

> understand what was happening. I simply changed the varying

> variables to uniform ones that can be altered from Jitter. If you

> can get it to work it might help to demonstrate how to draw up the

> jxs files for Jitter.

>

> pelado

>

>

>

>

>

>

>

>

>

>

> //

> // Vertex shader for chromatic aberration effect

> //

> // Author: Randi Rost

> //

> // Copyright (c) 2003-2006: 3Dlabs, Inc.

> //

> // See 3Dlabs-License.txt for license information

> // changed original varying Eta values to uniform vec3 – pelado

>

> uniform vec3 Eta;

>

> uniform float FresnelPower;

>

> varying vec3 Reflect;

> varying vec3 RefractR;

> varying vec3 RefractG;

> varying vec3 RefractB;

> varying float Ratio;

>

> float F = float(((1.0-Eta.g) * (1.0-Eta.g)) / ((1.0+Eta.g) * (1.0

> +Eta.g)));

>

> void main()

> {

>

> vec4 ecPosition = gl_ModelViewMatrix * gl_Vertex;

> vec3 ecPosition3 = ecPosition.xyz / ecPosition.w;

>

> vec3 i = normalize(ecPosition3);

> vec3 n = normalize(gl_NormalMatrix * gl_Normal);

>

> Ratio = F + (1.0 – F) * pow((1.0 – dot(-i, n)), FresnelPower);

>

> RefractR = refract(i, n, Eta.r);

> RefractR = vec3(gl_TextureMatrix[0] * vec4(RefractR, 1.0));

>

> RefractG = refract(i, n, Eta.g);

> RefractG = vec3(gl_TextureMatrix[0] * vec4(RefractG, 1.0));

>

> RefractB = refract(i, n, Eta.b);

> RefractB = vec3(gl_TextureMatrix[0] * vec4(RefractB, 1.0));

>

> Reflect = reflect(i, n);

> Reflect = vec3(gl_TextureMatrix[0] * vec4(Reflect, 1.0));

>

> gl_Position = ftransform();

> }

> ]]>

>

> //

> // Fragment shader for chromatic aberration effect

> //

> // Author: Randi Rost

> //

> // Copyright (c) 2003-2006: 3Dlabs, Inc.

> //

> // See 3Dlabs-License.txt for license information

> //

>

> varying vec3 Reflect;

> varying vec3 RefractR;

> varying vec3 RefractG;

> varying vec3 RefractB;

> varying float Ratio;

>

> uniform samplerCube Cubemap;

>

> void main()

> {

> vec3 refractColor, reflectColor;

>

> refractColor.r = vec3(textureCube(Cubemap, RefractR)).r;

> refractColor.g = vec3(textureCube(Cubemap, RefractG)).g;

> refractColor.b = vec3(textureCube(Cubemap, RefractB)).b;

>

> reflectColor = vec3(textureCube(Cubemap, Reflect));

>

> vec3 color = mix(refractColor, reflectColor, Ratio);

>

> gl_FragColor = vec4(color, 1.0);

> }

> ]]>

>

>

>

>

you need to place a jit.gl.cubemap object in your patch and import some

textures to get a result. See the cubemap help file.

pelado

On Wed, Jun 11, 2008 at 5:35 PM, Brecht Debackere

wrote:

> great! I get no more errors at least with yours. I might ‘ve made some

> typo’s along the way since I copied it manually from the book.

> There are still some things I don’t fully understand though, since it only

> seems to color my object black; the cubemap e.g. where should it come from?

>

>

>

> On 11 Jun 2008, at 17:27, pelado wrote:

>

> On Mon, Jun 9, 2008 at 12:51 PM, Brecht Debackere

> wrote:

>

>> Apologies for digging up this old thread. I’ve finally continued my

>> dabbling with glsl, still the same one from the orange book.

>> I’ve started anew and so far came up with nothing much except for trying

>> to fit the code into the .jxs format. In the end I’m trying to find figure

>> out how the examples in the orange book translate to jitter.

>>

>> Surprisingly, it’s not working ;) Any shader guru’s willing to stare into

>> this mess?

>>

>

> I also copied the chromatic Aberration shader from the Orange Book and can

> get a result in Jitter. However, when I copy the code from your post I get

> a compilation error when I try to use it. I seem to remember trying a

> shader that you posted previously (?) but had the same result. I looked at

> the code and couldn’t find any difference between your version and mine but

> put it down to not looking hard enough.

> Whenever I copy code from a browser I get rid of hidden formatting (by

> selecting zap gremlins in text wrangler), sometimes this can interfere with

> the code when it gets compiled. Also, I’ve found that my graphics card

> doesn’t support some shaders. You might want to check that yours supports

> the gl and shading code that you use.

>

> Anyway, here’s a version of the same shader that I did to try and

> understand what was happening. I simply changed the varying variables to

> uniform ones that can be altered from Jitter. If you can get it to work it

> might help to demonstrate how to draw up the jxs files for Jitter.

>

> pelado

>

>

>

>

>

>

>

>

>

>

> //

> // Vertex shader for chromatic aberration effect

> //

> // Author: Randi Rost

> //

> // Copyright (c) 2003-2006: 3Dlabs, Inc.

> //

> // See 3Dlabs-License.txt for license information

> // changed original varying Eta values to uniform vec3 – pelado

>

> uniform vec3 Eta;

>

> uniform float FresnelPower;

>

> varying vec3 Reflect;

> varying vec3 RefractR;

> varying vec3 RefractG;

> varying vec3 RefractB;

> varying float Ratio;

>

> float F = float(((1.0-Eta.g) * (1.0-Eta.g)) / ((1.0+Eta.g) * (1.0+Eta.g)));

>

> void main()

> {

>

> vec4 ecPosition = gl_ModelViewMatrix * gl_Vertex;

> vec3 ecPosition3 = ecPosition.xyz / ecPosition.w;

>

> vec3 i = normalize(ecPosition3);

> vec3 n = normalize(gl_NormalMatrix * gl_Normal);

>

> Ratio = F + (1.0 – F) * pow((1.0 – dot(-i, n)), FresnelPower);

>

> RefractR = refract(i, n, Eta.r);

> RefractR = vec3(gl_TextureMatrix[0] * vec4(RefractR, 1.0));

>

> RefractG = refract(i, n, Eta.g);

> RefractG = vec3(gl_TextureMatrix[0] * vec4(RefractG, 1.0));

>

> RefractB = refract(i, n, Eta.b);

> RefractB = vec3(gl_TextureMatrix[0] * vec4(RefractB, 1.0));

>

> Reflect = reflect(i, n);

> Reflect = vec3(gl_TextureMatrix[0] * vec4(Reflect, 1.0));

>

> gl_Position = ftransform();

> }

> ]]>

>

> //

> // Fragment shader for chromatic aberration effect

> //

> // Author: Randi Rost

> //

> // Copyright (c) 2003-2006: 3Dlabs, Inc.

> //

> // See 3Dlabs-License.txt for license information

> //

>

> varying vec3 Reflect;

> varying vec3 RefractR;

> varying vec3 RefractG;

> varying vec3 RefractB;

> varying float Ratio;

>

> uniform samplerCube Cubemap;

>

> void main()

> {

> vec3 refractColor, reflectColor;

>

> refractColor.r = vec3(textureCube(Cubemap, RefractR)).r;

> refractColor.g = vec3(textureCube(Cubemap, RefractG)).g;

> refractColor.b = vec3(textureCube(Cubemap, RefractB)).b;

>

> reflectColor = vec3(textureCube(Cubemap, Reflect));

>

> vec3 color = mix(refractColor, reflectColor, Ratio);

>

> gl_FragColor = vec4(color, 1.0);

> }

> ]]>

>

>

>

>

>

>

>

>

>

–

wicked. Thanks a bunch

The cubemap is a texture like any other Jitter texture. In this case

though it’s specifically jit.gl.cubemap which can be used just like

jit.gl.texture but binds as a Cube Sampler instead.

wes

On Wed, Jun 11, 2008 at 8:35 AM, Brecht Debackere

> great! I get no more errors at least with yours. I might ‘ve made some

> typo’s along the way since I copied it manually from the book.

> There are still some things I don’t fully understand though, since it only

> seems to color my object black; the cubemap e.g. where should it come from?

>

>

>

> On 11 Jun 2008, at 17:27, pelado wrote:

>

> On Mon, Jun 9, 2008 at 12:51 PM, Brecht Debackere

> wrote:

>>

>> Apologies for digging up this old thread. I’ve finally continued my

>> dabbling with glsl, still the same one from the orange book.

>> I’ve started anew and so far came up with nothing much except for trying

>> to fit the code into the .jxs format. In the end I’m trying to find figure

>> out how the examples in the orange book translate to jitter.

>>

>> Surprisingly, it’s not working ;) Any shader guru’s willing to stare into

>> this mess?

>

> I also copied the chromatic Aberration shader from the Orange Book and can

> get a result in Jitter. However, when I copy the code from your post I get

> a compilation error when I try to use it. I seem to remember trying a

> shader that you posted previously (?) but had the same result. I looked at

> the code and couldn’t find any difference between your version and mine but

> put it down to not looking hard enough.

> Whenever I copy code from a browser I get rid of hidden formatting (by

> selecting zap gremlins in text wrangler), sometimes this can interfere with

> the code when it gets compiled. Also, I’ve found that my graphics card

> doesn’t support some shaders. You might want to check that yours supports

> the gl and shading code that you use.

> Anyway, here’s a version of the same shader that I did to try and understand

> what was happening. I simply changed the varying variables to uniform ones

> that can be altered from Jitter. If you can get it to work it might help to

> demonstrate how to draw up the jxs files for Jitter.

> pelado

>

>

>

>

>

>

> //

> // Vertex shader for chromatic aberration effect

> //

> // Author: Randi Rost

> //

> // Copyright (c) 2003-2006: 3Dlabs, Inc.

> //

> // See 3Dlabs-License.txt for license information

> // changed original varying Eta values to uniform vec3 – pelado

> uniform vec3 Eta;

> uniform float FresnelPower;

> varying vec3 Reflect;

> varying vec3 RefractR;

> varying vec3 RefractG;

> varying vec3 RefractB;

> varying float Ratio;

> float F = float(((1.0-Eta.g) * (1.0-Eta.g)) / ((1.0+Eta.g) * (1.0+Eta.g)));

> void main()

> {

> vec4 ecPosition = gl_ModelViewMatrix * gl_Vertex;

> vec3 ecPosition3 = ecPosition.xyz / ecPosition.w;

> vec3 i = normalize(ecPosition3);

> vec3 n = normalize(gl_NormalMatrix * gl_Normal);

> Ratio = F + (1.0 – F) * pow((1.0 – dot(-i, n)), FresnelPower);

> RefractR = refract(i, n, Eta.r);

> RefractR = vec3(gl_TextureMatrix[0] * vec4(RefractR, 1.0));

> RefractG = refract(i, n, Eta.g);

> RefractG = vec3(gl_TextureMatrix[0] * vec4(RefractG, 1.0));

> RefractB = refract(i, n, Eta.b);

> RefractB = vec3(gl_TextureMatrix[0] * vec4(RefractB, 1.0));

> Reflect = reflect(i, n);

> Reflect = vec3(gl_TextureMatrix[0] * vec4(Reflect, 1.0));

> gl_Position = ftransform();

> }

> ]]>

>

> //

> // Fragment shader for chromatic aberration effect

> //

> // Author: Randi Rost

> //

> // Copyright (c) 2003-2006: 3Dlabs, Inc.

> //

> // See 3Dlabs-License.txt for license information

> //

> varying vec3 Reflect;

> varying vec3 RefractR;

> varying vec3 RefractG;

> varying vec3 RefractB;

> varying float Ratio;

> uniform samplerCube Cubemap;

> void main()

> {

> vec3 refractColor, reflectColor;

> refractColor.r = vec3(textureCube(Cubemap, RefractR)).r;

> refractColor.g = vec3(textureCube(Cubemap, RefractG)).g;

> refractColor.b = vec3(textureCube(Cubemap, RefractB)).b;

> reflectColor = vec3(textureCube(Cubemap, Reflect));

> vec3 color = mix(refractColor, reflectColor, Ratio);

> gl_FragColor = vec4(color, 1.0);

> }

> ]]>

>

>

>

>

>

>

I’m very interested in experimenting with Chromatic Aberration effects, but I dont know much about writing/implementing shaders yet.. –

– is there any chance you could post an example patch with this CA Shader working?

thanks!

I started trying to convert the shader myself, but I know that I haven’t gotten it quite right yet, I read in this thread that theres something with the cube mapping that has to be done in jitter but I dont fully understand how to do that. Im posting the version of the shader that I have partially converted, though I know its not quite right yet. Is it possible for someone to post a proper working version and show me what it is I am doing wrong.

robtherich posted a great fixed version of my poor attempt on here:

Thanks all!

Man what a great shader! I thirst for more!!

NCRIII

Forums > Jitter