Fish eye pass.

This commit is contained in:
Lubos Lenco 2016-04-01 17:21:17 +02:00
parent 9de351477c
commit 1732254406
6 changed files with 116 additions and 1 deletions

View file

@ -0,0 +1,16 @@
{
"material_resources": [
{
"contexts": [
{
"bind_constants": [],
"bind_textures": [
],
"id": "fisheye_pass"
}
],
"id": "fisheye_material",
"shader": "fisheye_pass/fisheye_pass"
}
]
}

View file

@ -47,6 +47,10 @@ os.chdir('../bloom_pass')
make_resources.make('bloom_pass.shader.json')
make_variants.make('bloom_pass.shader.json')
os.chdir('../fisheye_pass')
make_resources.make('fisheye_pass.shader.json')
make_variants.make('fisheye_pass.shader.json')
# os.chdir('../ssr_pass')
# make_resources.make('ssr_pass.shader.json')
# make_variants.make('ssr_pass.shader.json')

View file

@ -0,0 +1,44 @@
// Fish eye based on Sanch implementation
// https://www.shadertoy.com/view/4s2GRR
#version 450
#ifdef GL_ES
precision mediump float;
#endif
uniform sampler2D tex;
const float PI = 3.1415926535;
const float strength = -0.01;
const vec2 m = vec2(0.5, 0.5);
in vec2 texCoord;
void main() {
vec2 d = texCoord - m;
float r = sqrt(dot(d, d));
float power = (2.0 * PI / (2.0 * sqrt(dot(m, m)))) * strength;
float bind;
if (power > 0.0) {
bind = sqrt(dot(m, m));
}
else {
bind = m.x;
}
vec2 uv;
if (power > 0.0) {
uv = m + normalize(d) * tan(r * power) * bind / tan(bind * power);
}
else {
uv = m + normalize(d) * atan(r * -power * 10.0) * bind / atan(-power * bind * 10.0);
}
vec3 col = texture(tex, uv).xyz;
gl_FragColor = vec4(col, 1.0);
// vec4 texCol = texture(tex, texCoord);
// gl_FragColor = texCol;
}

View file

@ -0,0 +1,33 @@
{
"contexts": [
{
"id": "fisheye_pass",
"params": [
{
"id": "depth_write",
"value": "true"
},
{
"id": "compare_mode",
"value": "always"
},
{
"id": "cull_mode",
"value": "none"
},
{
"id": "blend_source",
"value": "blend_one"
},
{
"id": "blend_destination",
"value": "blend_zero"
}
],
"links": [],
"texture_params": [],
"vertex_shader": "fisheye_pass.vert.glsl",
"fragment_shader": "fisheye_pass.frag.glsl"
}
]
}

View file

@ -0,0 +1,18 @@
#version 450
#ifdef GL_ES
precision highp float;
#endif
in vec2 pos;
out vec2 texCoord;
const vec2 madd = vec2(0.5, 0.5);
void main() {
// Scale vertex attribute to [0-1] range
texCoord = pos.xy * madd + madd;
gl_Position = vec4(pos.xy, 0.0, 1.0);
}

View file

@ -13,7 +13,7 @@ uniform sampler2D tex;
in vec2 texCoord;
void main() {
vec2 resolution = vec2(640.0, 480.0);
vec2 resolution = vec2(800.0, 600.0);
vec2 texStep = 1.0 / resolution.xy;
vec2 tcrgbNW = (texCoord + vec2(-1.0, -1.0) * texStep);