first commit
This commit is contained in:
139
project/fm_viewer/fav/shaders/defish2d.fsh
Normal file
139
project/fm_viewer/fav/shaders/defish2d.fsh
Normal file
@@ -0,0 +1,139 @@
|
||||
uniform sampler2D u_Texture0;
|
||||
uniform sampler2D u_Texture1;
|
||||
uniform sampler2D u_Texture2;
|
||||
// TOP DOWN 360 MODEL
|
||||
// https://github.com/tokoik/fisheye ...
|
||||
// https://stackoverflow.com/questions/39352533/android-opengl-es-textured-half-sphere ???
|
||||
varying vec2 v_TexCoords0;
|
||||
varying vec2 v_TexCoords1;
|
||||
varying vec2 v_TexCoords2;
|
||||
|
||||
#define v_TexCoords1 v_TexCoords0
|
||||
#define v_TexCoords2 v_TexCoords0
|
||||
#define v_TexCoords3 v_TexCoords0
|
||||
|
||||
uniform float u_opacity;
|
||||
uniform mat4 u_colorMatrix;
|
||||
|
||||
uniform int u_mode;
|
||||
uniform float u_angle;
|
||||
uniform int u_flip;
|
||||
uniform float u_effectiveWidth;
|
||||
uniform float u_clipBound;
|
||||
uniform float u_whratio;
|
||||
void main(void)
|
||||
{
|
||||
vec2 fc = v_TexCoords0.st;
|
||||
float PI = 3.141592;
|
||||
|
||||
// FLIP 반전
|
||||
// if(u_mode != 2 && u_flip == 1) {
|
||||
// fc.y = 1.0 - fc.y;
|
||||
// }
|
||||
|
||||
// VR + PANORAMA
|
||||
// #if (REMOVE_360_WIDE_SINGLE)
|
||||
//if(u_mode == 3 || u_mode == 1)
|
||||
if(u_mode == 2 || u_mode == 3)
|
||||
{
|
||||
float R = u_effectiveWidth / 2.0 * 0.99;//0.5;
|
||||
float Cfx = u_effectiveWidth / 2.0;
|
||||
float Cfy = 0.5;
|
||||
|
||||
float He = 1.0;
|
||||
float We = u_effectiveWidth;
|
||||
|
||||
float Xe = 1.0-fc.x; // flip h
|
||||
float Ye = 1.0-fc.y; // upside down
|
||||
|
||||
// if(u_mode == 3){
|
||||
// if(Ye > 0.62) {
|
||||
// gl_FragColor = vec4(0.0,0.0,0.0,1.0);
|
||||
// return;
|
||||
// }
|
||||
// Ye = (Ye / 0.62);
|
||||
// }
|
||||
|
||||
float r = Ye/He*R;
|
||||
float theta = Xe/We*2.0*PI - (u_angle * 3.0); // TOP_DOWN_2D_360
|
||||
|
||||
theta = theta * 0.2 * u_whratio;
|
||||
|
||||
float Xf = Cfx+r*sin(theta);
|
||||
float Yf = Cfy+r*cos(theta);
|
||||
|
||||
fc = vec2(Xf,Yf);
|
||||
}
|
||||
else if(u_mode == 1) // PANORAMA 2CH
|
||||
{
|
||||
fc.y = 1.0 - fc.y;
|
||||
|
||||
float Hf = 1.0;
|
||||
float R = u_effectiveWidth / 2.0 * 0.99;
|
||||
float Cfx = u_effectiveWidth / 2.0;
|
||||
float Cfy = 0.5;
|
||||
|
||||
float He = 1.0;
|
||||
float We = u_effectiveWidth;
|
||||
|
||||
float Xe = 1.0-fc.x; // flip h
|
||||
float Ye = 1.0-fc.y; // upside down
|
||||
|
||||
if(fc.y < 0.5) // top (0~180 -> bottom
|
||||
{
|
||||
Ye = 1.0-Ye;
|
||||
|
||||
float scale = (Ye + 0.5) * 2.0; // 0.0~0.5 = 1.0~2.0
|
||||
float r = ((Ye/He*R)+0.25) / scale;
|
||||
float theta = Xe/We*PI+(PI/2.0); // 1/2
|
||||
theta += PI;
|
||||
float Xf = Cfx+r*sin(theta) * scale * 1.0;
|
||||
float Yf = Cfy+r*cos(theta) * scale;
|
||||
|
||||
fc = vec2(Xf,Yf);
|
||||
}
|
||||
else // bottom 180 ~ 360
|
||||
{
|
||||
Ye = 1.0-Ye-0.5;
|
||||
float scale = (Ye + 0.5) * 2.0; // 0.0~0.5 = 1.0~2.0
|
||||
float r = ((Ye/He*R)+0.25) / scale;
|
||||
float theta = Xe/We*PI+(PI/2.0); // 1/2
|
||||
float Xf = Cfx+r*sin(theta) * scale;
|
||||
float Yf = Cfy+r*cos(theta) * scale;
|
||||
|
||||
fc = vec2(Xf,Yf);
|
||||
}
|
||||
|
||||
if(u_clipBound > 0.0) {
|
||||
//if(v_TexCoords0.st.x < u_clipBound || v_TexCoords0.st.x > (1.0 - u_clipBound))
|
||||
if(v_TexCoords0.st.x < 0.0 || v_TexCoords0.st.x > 1.0)
|
||||
{
|
||||
gl_FragColor = clamp(u_colorMatrix
|
||||
* vec4(texture2D(u_Texture0, fc).r,
|
||||
texture2D(u_Texture1, fc).r,
|
||||
texture2D(u_Texture2, fc).r,
|
||||
1.0) * 0.9, 0.0, 1.0);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
else // CLIP ZOOM
|
||||
{
|
||||
// ZOOM CLIP
|
||||
if (fc.x < 0.0 || fc.x > 1.0) {
|
||||
gl_FragColor = vec4(0.0,0.0,0.0,1.0);
|
||||
return;
|
||||
}
|
||||
fc.x *= u_effectiveWidth;
|
||||
}
|
||||
|
||||
|
||||
|
||||
gl_FragColor = clamp(u_colorMatrix
|
||||
* vec4(texture2D(u_Texture0, fc).r,
|
||||
texture2D(u_Texture1, fc).r,
|
||||
texture2D(u_Texture2, fc).r,
|
||||
1.0), 0.0, 1.0);
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user