Forum Discussion

🚨 This forum is archived and read-only. To submit a forum post, please visit our new Developer Forum. 🚨
rupy's avatar
rupy
Honored Guest
11 years ago

[SOLVED] Barrel + Chromatic Aberration in same shader

Hey, so I got the barrel distortion up, but now I want to integrate the chromatic aberration distortion into the same shader and I kind gotta a feeling it should be possible, but I'm a complete shader noob, can anyone help?

This is the code so far (the arrow out parts are what I'm struggling with):

SOLVED: The below code works!


String VERTEX =
"void main() {\n" +
" gl_TexCoord[0] = gl_MultiTexCoord0;\n" +
" gl_Position = gl_Vertex;\n" +
"}";

String FRAGMENT =
"uniform sampler2D tex;\n" +
"uniform vec2 LensCenter;\n" +
"uniform vec2 ScreenCenter;\n" +
"uniform vec2 Scale;\n" +
"uniform vec2 ScaleIn;\n" +
"uniform vec4 HmdWarpParam;\n" +
"void main() {\n" +
" vec2 theta = (gl_TexCoord[0].xy - LensCenter) * ScaleIn;\n" +
" float rSq = theta.x * theta.x + theta.y * theta.y;\n" +
" vec2 theta1 = theta * (HmdWarpParam.x + HmdWarpParam.y * rSq + " +
" HmdWarpParam.z * rSq * rSq + HmdWarpParam.w * rSq * rSq * rSq);\n" +
" vec2 tc = LensCenter + Scale * theta1;\n" +
" if (any(notEqual(clamp(tc, ScreenCenter - vec2(0.24, 0.49), ScreenCenter + vec2(0.24, 0.49)) - tc, vec2(0.0, 0.0))))\n" +
" gl_FragColor = vec4(0.0, 0.0, 0.0, 1.0);\n" +
" else {\n" + // 1.0, 1.017, 1.038
-> " float r = texture2D(tex, (((tc - LensCenter) / 1.0) + LensCenter)).r;\n" +
-> " float g = texture2D(tex, (((tc - LensCenter) / 0.983) + LensCenter)).g;\n" +
-> " float b = texture2D(tex, (((tc - LensCenter) / 0.962) + LensCenter)).b;\n" +
-> " gl_FragColor = vec4(r, g, b, 1.0);\n" +
" }" +
"}";
No RepliesBe the first to reply