Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 0ecf468

Browse filesBrowse files
committed
Chromatic Aberration and Vignette
1 parent dae126e commit 0ecf468
Copy full SHA for 0ecf468

File tree

Expand file treeCollapse file tree

3 files changed

+200
-0
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

3 files changed

+200
-0
lines changed
Open diff view settings
Collapse file

‎bin/CoreData/RenderPaths/Default.renderpath‎

Copy file name to clipboardExpand all lines: bin/CoreData/RenderPaths/Default.renderpath
+106Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,112 @@
222222
}
223223
]
224224
}
225+
},
226+
{
227+
"type": "FullScreenShaderPass",
228+
"value": {
229+
"attributes": [
230+
{
231+
"name": "Pass Name",
232+
"type": "String",
233+
"value": "Postprocess: Chromatic Aberration"
234+
},
235+
{
236+
"name": "Is Enabled By Default",
237+
"type": "Bool",
238+
"value": false
239+
},
240+
{
241+
"name": "Comment",
242+
"type": "String",
243+
"value": "Simulates the optical effect known as chromatic aberration, which occurs when a lens fails to focus all colors to the same point."
244+
},
245+
{
246+
"name": "Shader Name",
247+
"type": "String",
248+
"value": "v2/P_ChromaticAberration"
249+
},
250+
{
251+
"name": "Read+Write Color Output",
252+
"type": "Bool",
253+
"value": true
254+
},
255+
{
256+
"name": "Parameters Prefix",
257+
"type": "String",
258+
"value": "Chromatic Aberration: "
259+
},
260+
{
261+
"name": "Parameters",
262+
"type": "StringVariantMap",
263+
"value": [
264+
{
265+
"key": "Amount",
266+
"type": "Float",
267+
"value": 0.4
268+
}
269+
]
270+
}
271+
]
272+
}
273+
},
274+
{
275+
"type": "FullScreenShaderPass",
276+
"value": {
277+
"attributes": [
278+
{
279+
"name": "Pass Name",
280+
"type": "String",
281+
"value": "Postprocess: Vignette"
282+
},
283+
{
284+
"name": "Is Enabled By Default",
285+
"type": "Bool",
286+
"value": false
287+
},
288+
{
289+
"name": "Comment",
290+
"type": "String",
291+
"value": "Creates a darkening effect around the edges of the screen."
292+
},
293+
{
294+
"name": "Shader Name",
295+
"type": "String",
296+
"value": "v2/P_Vignette"
297+
},
298+
{
299+
"name": "Read+Write Color Output",
300+
"type": "Bool",
301+
"value": true
302+
},
303+
{
304+
"name": "Parameters Prefix",
305+
"type": "String",
306+
"value": "Vignette: "
307+
},
308+
{
309+
"name": "Parameters",
310+
"type": "StringVariantMap",
311+
"value": [
312+
{
313+
"key": "Intensity",
314+
"type": "Float",
315+
"value": 0.4
316+
},
317+
{
318+
"key": "Radius",
319+
"type": "Float",
320+
"value": 0.5
321+
},
322+
{
323+
"key": "Color",
324+
"type": "Color",
325+
"value": "0 0 0 0.4"
326+
}
327+
]
328+
}
329+
]
330+
}
225331
}
226332
]
227333
}
Collapse file
+48Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#include "_Config.glsl"
2+
#include "_Uniforms.glsl"
3+
#include "_VertexLayout.glsl"
4+
#include "_VertexTransform.glsl"
5+
#include "_VertexScreenPos.glsl"
6+
#include "_DefaultSamplers.glsl"
7+
#include "_SamplerUtils.glsl"
8+
9+
VERTEX_OUTPUT_HIGHP(vec2 vScreenPos)
10+
11+
#ifdef URHO3D_PIXEL_SHADER
12+
UNIFORM_BUFFER_BEGIN(6, Custom)
13+
UNIFORM(mediump float cAmount)
14+
UNIFORM_BUFFER_END(6, Custom)
15+
#endif
16+
17+
#ifdef URHO3D_VERTEX_SHADER
18+
void main()
19+
{
20+
VertexTransform vertexTransform = GetVertexTransform();
21+
gl_Position = WorldToClipSpace(vertexTransform.position.xyz);
22+
vScreenPos = GetScreenPosPreDiv(gl_Position);
23+
}
24+
#endif
25+
26+
#ifdef URHO3D_PIXEL_SHADER
27+
28+
void main()
29+
{
30+
// Calculate scale for screen UV coordinates to preserve shape of the circle
31+
vec2 aspectRatioCorrection = min(vec2(1.0, 1.0), vec2(cGBufferInvSize.y/cGBufferInvSize.x, cGBufferInvSize.x/cGBufferInvSize.y));
32+
33+
// Calculate screen coordinates in range -1 .. +1
34+
vec2 screenPos = (vScreenPos.xy * 2.0 - 1.0) * aspectRatioCorrection;
35+
36+
float distanceToCenter = dot(screenPos, screenPos);
37+
38+
// Calculate the offset for each color channel
39+
vec2 offset = cGBufferInvSize.xy * cAmount * screenPos * distanceToCenter;
40+
41+
// Sample the texture at the offset positions
42+
float red = texture(sAlbedo, vScreenPos - offset).r;
43+
vec2 greenAlpha = texture(sAlbedo, vScreenPos).ga;
44+
float blue = texture(sAlbedo, vScreenPos + offset).b;
45+
46+
gl_FragColor = vec4(red, greenAlpha.x, blue, greenAlpha.y);
47+
}
48+
#endif
Collapse file
+46Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#include "_Config.glsl"
2+
#include "_Uniforms.glsl"
3+
#include "_VertexLayout.glsl"
4+
#include "_VertexTransform.glsl"
5+
#include "_VertexScreenPos.glsl"
6+
#include "_DefaultSamplers.glsl"
7+
#include "_SamplerUtils.glsl"
8+
9+
VERTEX_OUTPUT_HIGHP(vec2 vScreenPos)
10+
11+
#ifdef URHO3D_PIXEL_SHADER
12+
UNIFORM_BUFFER_BEGIN(6, Custom)
13+
UNIFORM(mediump float cIntensity)
14+
UNIFORM(mediump float cRadius)
15+
UNIFORM(mediump vec4 cColor)
16+
UNIFORM_BUFFER_END(6, Custom)
17+
#endif
18+
19+
#ifdef URHO3D_VERTEX_SHADER
20+
void main()
21+
{
22+
VertexTransform vertexTransform = GetVertexTransform();
23+
gl_Position = WorldToClipSpace(vertexTransform.position.xyz);
24+
vScreenPos = GetScreenPosPreDiv(gl_Position);
25+
}
26+
#endif
27+
28+
#ifdef URHO3D_PIXEL_SHADER
29+
30+
void main()
31+
{
32+
// Sample screen buffer
33+
half4 rgb = texture(sAlbedo, vScreenPos);
34+
35+
// Calculate scale for screen UV coordinates to preserve shape of the circle
36+
vec2 aspectRatioCorrection = min(vec2(1.0, 1.0), vec2(cGBufferInvSize.y/cGBufferInvSize.x, cGBufferInvSize.x/cGBufferInvSize.y));
37+
38+
// Calculate screen coordinates in range -1 .. +1
39+
vec2 screenPos = (vScreenPos.xy * 2.0 - 1.0) * aspectRatioCorrection;
40+
41+
// Calculate distance from screen center to the current pixel in range 0 .. +1
42+
float len = length(screenPos);
43+
float vignette = mix(1.0-cColor.a, 1.0, smoothstep(cRadius, cRadius - max(0.0, cIntensity), len));
44+
gl_FragColor = vec4(mix(rgb.rgb * cColor.rgb, rgb.rgb, vignette), rgb.a);
45+
}
46+
#endif

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.