Chromatic Aberration Shader

Sep 20, 2007 at 10:26am

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

#33748
Sep 20, 2007 at 4:42pm

Hi.

A few things

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


(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

#112829
Sep 20, 2007 at 9:04pm

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 :
>>

>
> (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

#112830
Jun 9, 2008 at 10:51am

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?


chromatic aberration shader

< ![CDATA[

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();

}
]]>

< ![CDATA[

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);

}
]]>

#112831
Jun 11, 2008 at 6:12am

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

#112832
Jun 11, 2008 at 6:36am

On Tue, Jun 10, 2008 at 11:12 PM, vade wrote:
>
> 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:


Environment Mapping with a Cube Map




< ![CDATA[

varying vec3 V;
varying vec3 N;

void main()
{
gl_Position = ftransform();
V = (gl_ModelViewMatrix * gl_Vertex).xyz;

N = gl_NormalMatrix * gl_Normal;
}
]]>

< ![CDATA[

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);
}
]]>

#112833
Jun 11, 2008 at 6:42am

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

#112834
Jun 11, 2008 at 9:18am

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

#112835
Jun 11, 2008 at 3:27pm

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




< ![CDATA[

//
// 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();
}
]]>

< ![CDATA[
//
// 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);
}
]]>

#112836
Jun 11, 2008 at 3:35pm

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
>
>
>

>

>

>
>
>
>
>
>
>

> < ![CDATA[
>
> //
> // 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();
> }
> ]]>
>
>

> < ![CDATA[
> //
> // 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);
> }
> ]]>
>
>

>
>
>

#112837
Jun 11, 2008 at 3:42pm

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
>
>
>

>

>

>
>
>
>
>
>
>

> < ![CDATA[
>
> //
> // 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();
> }
> ]]>
>
>

> < ![CDATA[
> //
> // 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);
> }
> ]]>
>
>

>
>
>
>
>
>
>
>

http://www.pelado.co.uk

#112838
Jun 11, 2008 at 3:50pm

wicked. Thanks a bunch

#112839
Jun 11, 2008 at 6:43pm

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
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
>
>

>

>

>
>
>
>
>

> < ![CDATA[
> //
> // 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();
> }
> ]]>
>
>

> < ![CDATA[
> //
> // 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);
> }
> ]]>
>
>

>
>
>
>
>

#112840
Jul 13, 2008 at 11:37pm

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!

#112841
Jan 19, 2009 at 5:15pm

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.

#112842
Jan 20, 2009 at 9:07pm

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

http://www.cycling74.com/forums/index.php?t=msg&th=37541&start=0&rid=0&S=6cd237d50d8f58e65c14a96f4a604e65

Thanks all!

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

NCRIII

#112843

You must be logged in to reply to this topic.