Chromatic Aberration Shader
Sep 20, 2007 at 10:26am
Chromatic Aberration ShaderHi all, I’ve finally started looking into glsl, and intrigued by the
< ![CDATA[ varying vec3 Reflect; void main() vec4 ecPosition = gl_ModelViewMatrix * gl_Vertex; vec3 i = normalize(ecPosition3); Ratio = F + (1.0 – F) * pow((1.0 – dot(i, n)), FresnelPower); RefractR = refract(i, n, EtaR); RefractG = refract(i, n, EtaG); RefractB = refract(i, n, EtaB); Reflect = reflect(i, n); gl_Position = ftransform();
Brecht Debackere 

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, On Sep 20, 2007, at 6:26 AM, Brecht Debackere wrote: > Hi all, > > > > > > > < ![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 

Sep 20, 2007 at 9:04pm
right. back to the drawing board :) > Hi. > (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 

Jun 9, 2008 at 10:51am
Apologies for digging up this old thread. I’ve finally continued my Surprisingly, it’s not working ;) Any shader guru’s willing to stare
const float EtaR = 0.65; const float F = ((1.0EtaG)*(1.0EtaG))/((1.0+EtaG)*(1.0+EtaG)); varying vec3 Reflect;
void main() vec3 i = normalize(ecPosition3); Ratio = F + (1.0 – F) * pow((1.0 – dot(i, n)), FresnelPower); RefractR = refract(i, n, EtaR); RefractG = refract(i, n, EtaG); RefractB = refract(i, n, EtaB); Reflect = reflect(i,n); gl_Position = ftransform(); } varying vec3 Reflect; uniform samplerCube Cubemap; void main() refractColor.r = vec3(textureCube(Cubemap, RefractR)).r; reflectColor = vec3(textureCube(Cubemap, Reflect)); vec3 color = mix(refractColor, reflectColor, Reflect)); gl_FragColor = vec4(color, 1.0); } 

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. 

Jun 11, 2008 at 6:36am
On Tue, Jun 10, 2008 at 11:12 PM, vade Actually, one of the new things in Jitter 1.7 is cubemap support. See
varying vec3 V;
void main() N = gl_NormalMatrix * gl_Normal; varying vec3 V; uniform samplerCube environmentMap; void main() float etaRatio = 0.75; vec3 R = reflect(I, Nn); float reflectionCoeff = max(0., min(1., fresnelTerms.x + fresnelTerms.y * vec4 reflectedColor = textureCube(environmentMap, R); gl_FragColor = mix(reflectedColor, refractedColor, reflectionCoeff); 

Jun 11, 2008 at 6:42am
I’m not sure why you’re multiplying the refractino vector by the wes 

Jun 11, 2008 at 9:18am
Thanks guys. I’ll scrutinize that shader. On 11 Jun 2008, at 08:42, Wesley Smith wrote: > I’m not sure why you’re multiplying the refractino vector by the 

Jun 11, 2008 at 3:27pm
On Mon, Jun 9, 2008 at 12:51 PM, Brecht Debackere > Apologies for digging up this old thread. I’ve finally continued my I also copied the chromatic Aberration shader from the Orange Book and can Anyway, here’s a version of the same shader that I did to try and understand pelado
// uniform vec3 Eta; uniform float FresnelPower; varying vec3 Reflect; float F = float(((1.0Eta.g) * (1.0Eta.g)) / ((1.0+Eta.g) * (1.0+Eta.g))); void main() vec4 ecPosition = gl_ModelViewMatrix * gl_Vertex; vec3 i = normalize(ecPosition3); Ratio = F + (1.0 – F) * pow((1.0 – dot(i, n)), FresnelPower); RefractR = refract(i, n, Eta.r); RefractG = refract(i, n, Eta.g); RefractB = refract(i, n, Eta.b); Reflect = reflect(i, n); gl_Position = ftransform(); // // Fragment shader for chromatic aberration effect // // Author: Randi Rost // // Copyright (c) 20032006: 3Dlabs, Inc. // // See 3DlabsLicense.txt for license information // varying vec3 Reflect; uniform samplerCube Cubemap; void main() refractColor.r = vec3(textureCube(Cubemap, RefractR)).r; reflectColor = vec3(textureCube(Cubemap, Reflect)); vec3 color = mix(refractColor, reflectColor, Ratio); gl_FragColor = vec4(color, 1.0); 

Jun 11, 2008 at 3:35pm
great! I get no more errors at least with yours. I might ‘ve made On 11 Jun 2008, at 17:27, pelado wrote: > On Mon, Jun 9, 2008 at 12:51 PM, Brecht Debackere > > > > > > > > // > // Vertex shader for chromatic aberration effect > // > // Author: Randi Rost > // > // Copyright (c) 20032006: 3Dlabs, Inc. > // > // See 3DlabsLicense.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.0Eta.g) * (1.0Eta.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) 20032006: 3Dlabs, Inc. > // > // See 3DlabsLicense.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); > } > ]]> > > > > 

Jun 11, 2008 at 3:42pm
you need to place a jit.gl.cubemap object in your patch and import some On Wed, Jun 11, 2008 at 5:35 PM, Brecht Debackere > great! I get no more errors at least with yours. I might ‘ve made some > > > > > > > > // > // Vertex shader for chromatic aberration effect > // > // Author: Randi Rost > // > // Copyright (c) 20032006: 3Dlabs, Inc. > // > // See 3DlabsLicense.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.0Eta.g) * (1.0Eta.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) 20032006: 3Dlabs, Inc. > // > // See 3DlabsLicense.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); > } > ]]> > > > > > > > > > – 

Jun 11, 2008 at 3:50pm
wicked. Thanks a bunch 

Jun 11, 2008 at 6:43pm
The cubemap is a texture like any other Jitter texture. In this case wes On Wed, Jun 11, 2008 at 8:35 AM, Brecht Debackere > > > > > // > // Vertex shader for chromatic aberration effect > // > // Author: Randi Rost > // > // Copyright (c) 20032006: 3Dlabs, Inc. > // > // See 3DlabsLicense.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.0Eta.g) * (1.0Eta.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) 20032006: 3Dlabs, Inc. > // > // See 3DlabsLicense.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); > } > ]]> > > > > > > 

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? 

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. 

Jan 20, 2009 at 9:07pm
robtherich posted a great fixed version of my poor attempt on here: Thanks all! Man what a great shader! I thirst for more!! NCRIII 
You must be logged in to reply to this topic.