幾個 shader

uniform sampler2D av_texture;
varying highp vec3 v_position;
varying highp vec2 v_texcoord;

void main(void){
    gl_FragColor = texture2D(av_texture, v_texcoord);
}

uniform sampler2D av_texture;
varying highp vec3 v_position;
varying highp vec2 v_texcoord;
varying highp vec2 v_blenduv;
uniform float uBlendAngle;
uniform float uPlaneWidth;
uniform float uPlaneHeight;
uniform mat4 uTransformMat;

highp float alphaNormalized(float x) {
    float lamda = 5.2;
    float gamma = 1.0;
    float a= 0.5;
    if(x <= 0.5) {
        x = a * pow(2.0 * x,lamda);
    } else {
        x = 1.0 - (1.0 - a) * pow(2.0 * (1.0 - x),lamda);
    }
    x = pow(x,gamma);
    return x;
}

void main(void){
    float pi = 3.1415926535898;
    float phi,angle,alpha1,alpha2;
    //在xz平面
    phi = pi * (v_position.z/ uPlaneHeight + 0.5);
    float z = cos(phi);
    float ringradius = sin(phi);
    float theta = pi * 2.0 * ((v_position.x / uPlaneWidth + 0.5));
    float x = ringradius * cos(theta);
    float y = ringradius * sin(theta);

    vec4 pos = uTransformMat * vec4(x,y,z,1.0);
    x = pos.x;
    y = pos.y;
    z = pos.z ;

    if(z > 0.0) {
        phi = atan(sqrt(y * y + z * z),x);
    } else {
        phi = atan(abs(y),x);
    }
    phi = phi/pi * 180.0;
    angle = (90.0 + uBlendAngle/2.0) - phi;
    alpha1 = angle/uBlendAngle;
    alpha1 = clamp(alpha1,0.0,1.0);
    alpha1 = alphaNormalized(alpha1);

    vec4 color1 = texture2D(av_texture,v_texcoord);
    vec4 color2 = texture2D(av_texture,v_blenduv);
    gl_FragColor = color2 * alpha1 + color1 * (1.0 - alpha1);
    gl_FragColor.a = 1.0;
}

uniform sampler2D av_texture;
varying highp vec3 v_position;
varying highp vec2 v_texcoord;
uniform mat4 uTransformMat;
uniform float uPlaneWidth;
uniform float uPlaneHeight;

void main(void){
    float pi = 3.141592653589793238462643383279502884;
    //在xz平面
    float phi = pi * (v_position.z/ uPlaneHeight + 0.5);
    float theta = pi * 2.0 * ((v_position.x / uPlaneWidth + 0.5));

    float z = cos(phi);
    float ringradius = sin(phi);
    float x = ringradius * cos(theta);
    float y = ringradius * sin(theta);

    vec4 pos = uTransformMat * vec4(x,y,z,1.0);

    //can not use -pos.z,bug.
    phi = atan(sqrt(pos.x * pos.x + pos.y * pos.y),pos.z);
    theta = atan(pos.y,pos.x);
    theta += 2.0 * pi;
    theta = mod(theta,2.0 * pi);

    float u = clamp(theta/(2.0 * pi),0.0,1.0);
    float v = clamp(1.0 - phi/pi,0.0,1.0);
    gl_FragColor = texture2D(av_texture, vec2(u,v));
}

uniform sampler2D av_texture;
varying highp vec3 v_position;
varying highp vec2 v_texcoord;
uniform float uClipAngle;
uniform float uPlaneWidth;
uniform float uPlaneHeight;
uniform mat4 uRotMat;
uniform float uFov;

void main(void){
    gl_FragColor = texture2D(av_texture, v_texcoord);
    float pi = 3.14159265358979323846;
    float xi = v_position.x/uPlaneWidth + 0.5;
    float yi = (v_position.z)/uPlaneHeight + 0.5;
    float phi = pi * yi;
    float z = cos(phi);
    float ringradius = sin(phi);
    float clipAngle = uFov/180.0*pi;
    float theta = (pi * 2.0 - clipAngle)/2.0 + clipAngle * xi;
    float x = ringradius * cos(theta);
    float y = ringradius * sin(theta);
    vec4 vec = uRotMat * vec4(x,y,z,1.0);
    phi = atan(sqrt(vec.x * vec.x + vec.y * vec.y),vec.z);
    phi = phi/pi * 180.0;
    float blendAngle = 5.0/180.0 * pi;
    //sbs no blend
    if(uClipAngle/180.0 * pi - blendAngle < pi) {
        blendAngle = 0.0;
    }
    if(phi > uClipAngle/2.0 - blendAngle) {
        gl_FragColor.a = (uClipAngle/2.0 - phi)/blendAngle;
    }
}

attribute highp vec3 av_vertex;
attribute highp vec2 av_texcoord;
attribute highp vec2 av_blenduv;
varying highp vec3 v_position;
varying highp vec2 v_texcoord;
varying highp vec2 v_blenduv;
uniform mediump mat4 modelviewprojectionMat;

void main(void){
    gl_Position = modelviewprojectionMat * vec4(av_vertex.xyz,1.0);
    v_position = av_vertex;
    v_texcoord = av_texcoord;
    v_blenduv = av_blenduv;
}

attribute highp vec3 av_vertex;
attribute highp vec2 av_texcoord;
varying highp vec3 v_position;
varying highp vec2 v_texcoord;
uniform mediump mat4 modelviewprojectionMat;

void main(void){
    gl_Position = modelviewprojectionMat * vec4(av_vertex.xyz,1.0);
    v_position = av_vertex;
    v_texcoord = av_texcoord;
}

attribute highp vec3 av_vertex;
attribute highp vec2 av_texcoord;
attribute highp vec2 av_blenduv;
varying highp vec3 v_position;
varying highp vec2 v_texcoord;
varying highp vec2 v_blenduv;
uniform mediump mat4 modelviewprojectionMat;
uniform float uPlaneWidth;
uniform float uPlaneHeight;
void main(void){
    gl_Position = modelviewprojectionMat * vec4(av_vertex.xyz,1.0);
    v_position = av_vertex;
    v_texcoord = av_texcoord;
    v_blenduv = av_blenduv;
}

uniform sampler2D av_texture;
varying highp vec3 v_position;
varying highp vec2 v_texcoord;
uniform mat4 uTransformMat;
uniform float uPanoHeight;
uniform float uChartletWidth;
uniform float uChartletHeight;
uniform float uChartletAngle;
void main(void){
    float pi = 3.1415926535898;
    //在xz平面
    float phi = pi * (v_position.z/ uPanoHeight + 0.5);
    float z = cos(phi);
    float ringradius = sin(phi);
    float theta = pi * 2.0 * ((v_position.x / (uPanoHeight * 2.0) + 0.5));
    float x = ringradius * cos(theta);
    float y = ringradius * sin(theta);

    vec4 pos = uTransformMat * vec4(x,y,z,1.0);
    //can not use -pos.z,bug.
    phi = atan(sqrt(pos.x * pos.x + pos.y * pos.y),pos.z);
    theta = atan(pos.y,pos.x);
    theta -= pi/2.0;
    while(theta < 0.0) {
        theta += pi * 2.0;
    }

    float chartletRadius = sqrt(uChartletWidth/2.0 * uChartletWidth/2.0 + uChartletHeight/2.0 * uChartletHeight/2.0);
    float angle = uChartletAngle/180.0 * pi;
    float r = (pi - phi)/angle * chartletRadius;
    float u = r * cos(theta) + uChartletWidth/2.0;
    float v = r * sin(theta) + uChartletHeight/2.0;
    u /= uChartletWidth;
    v /= uChartletHeight;

//    hflip
    u = 1.0 - u;

//    float u = v_texcoord.x;
//    float v = v_texcoord.y;
    if(u < 0.0 || v < 0.0
        || u > 1.0 || v > 1.0) {
        gl_FragColor = vec4(0.0,0.0,0.0,0.0);
    } else {
        gl_FragColor = texture2D(av_texture, vec2(u,v));
    }
}

uniform sampler2D av_texture;
varying highp vec3 v_position;
varying highp vec2 v_texcoord;
varying highp vec2 v_blenduv;
uniform float uBlendAngle;
uniform mat4 uTransformMat;

highp float alphaNormalized(float x) {
    float lamda = 5.2;

    float gamma = 1.0;
    float a= 0.5;
    if(x <= 0.5) {
        x = a * pow(2.0 * x,lamda);
    } else {
        x = 1.0 - (1.0 - a) * pow(2.0 * (1.0 - x),lamda);
    }
    x = pow(x,gamma);
    return x;
}

vec4 transformPosition() {
    //transform from vertex to pos corresponding to uv
    //cos(theta) = cos(2pi - theta)
    //sin(theta) = -sin(2pi - theta)
    //v(x,y,z) => uvpos(x,-z,-y)
    vec4 pos = uTransformMat * vec4(v_position.x,-v_position.z,-v_position.y,1.0);
    return pos;
}

void main(void)
{
    float pi = 3.1415926535898;
    float phi,angle,alpha1,alpha2;
    vec4 pos = transformPosition();
    if(pos.x > 0.0) {
        phi = atan(sqrt(pos.y * pos.y + pos.z * pos.z),pos.x);
    } else {
        phi = atan(abs(pos.y),pos.x);
    }
    phi = phi/pi * 180.0;
    angle = phi - (90.0 - uBlendAngle/2.0);
    alpha1 = angle/uBlendAngle;
    alpha1 = clamp(alpha1,0.0,1.0);
    alpha1 = alphaNormalized(alpha1);

    vec4 color1 = texture2D(av_texture,v_texcoord);
    vec4 color2 = texture2D(av_texture,v_blenduv);
    gl_FragColor = color1 * alpha1 + color2 * (1.0 - alpha1);
    gl_FragColor.a = 1.0;
}
{
	"version":	1,
	"info":	{
		"gps":	{
			"altitude":	0,
			"longitude":	0,
			"latitude":	0
		},
		"gyro":	{
			
"gy":	0.949728,
			
"az":	0.006412,
			
"gx":	-0.032753,
			
"ay":	0.003080,
			
"gz":	-0.311359,
			
"ax":	0.004583
		
},
		"offset":	"2_744.201_765.480_755.949
_0.000_0.000_90.000
_744.261_2275.801_753.489
_-0.510_-0.300_90.690_3040_1520_1026",
		
"serialNumber":	"",
		
"orientation":	{
			"x":	0.232000,
			"y":	0,
			"z":	0,
			"w":	0
		}
	}
}?  


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章