#ifdef GL_ES precision highp int; precision highp float; #endif #define USE_OGRE_FROM_FUTURE #include #define PI 3.14159265359 #define mixdist 0.005 SAMPLER2D(diffuseMap, 0); OGRE_UNIFORMS( uniform vec4 uvOffset; uniform float radius; uniform vec2 rotate; uniform float scale; uniform float blendingRatio; ) vec4 equirectUv(sampler2D source, vec2 uv, float radius, vec4 uvOffset, vec2 rotate, float scale) { vec2 revUV = uv; float rot = 0.0; if (uv.x <= 0.5) { rot = rotate.x; revUV.x = revUV.x * 2.0; revUV.xy += uvOffset.xy; } else { rot = rotate.y; revUV.x = (revUV.x - 0.5) * 2.0; revUV.xy += uvOffset.zw; } revUV *= vec2_splat(PI); vec3 p = vec3(cos(revUV.x), cos(revUV.y), sin(revUV.x)); p.xz *= sqrt(1.0 - p.y * p.y); float r = 1.0 - asin(p.z) / (PI / 2.0); vec2 st = vec2(p.x, p.y); st *= vec2_splat(r / sqrt(1.0 - p.z * p.z)); st *= vec2_splat(radius); rot *= PI / 180.0; float s = sin(rot); float c = cos(rot); mat2 rotTex = mtxFromCols(vec2(c, -s), vec2(s, c)); st = mul(rotTex, st); st += vec2_splat(0.5); if (uv.x <= 0.5) { st.x *= 0.5; st.x += 0.5; } else { st.x *= 0.5; } st.y = 1.0 - st.y; st.y = st.y * scale; return texture2D(source, st); } MAIN_PARAMETERS IN(vec2 oUv0, TEXCOORD0) MAIN_DECLARATION { float blending = 1.0 - clamp(blendingRatio, 0.0001, 0.99999); vec4 baseColor = equirectUv(diffuseMap, oUv0, radius, uvOffset, rotate, scale); float dist = 0.0; float offset = 0.0; if ((oUv0.x > (0.5 - mixdist)) && (oUv0.x < 0.5)) { dist = 0.5 - oUv0.x; offset = 0.5 + dist; } else if ((oUv0.x >= 0.5) && (oUv0.x < (0.5 + mixdist))) { dist = oUv0.x - 0.5; offset = (0.5 - mixdist) + dist; } else if (oUv0.x < mixdist) { dist = oUv0.x; offset = 1.0 - (mixdist - dist); } else if ((oUv0.x > (1.0 - mixdist)) && (oUv0.x < 1.0)) { dist = 1.0 - oUv0.x; offset = (mixdist - dist); } if (offset != 0.0) { if (dist < mixdist * 0.5) dist = mixdist * 0.5; vec4 blendColor = equirectUv(diffuseMap, vec2(offset, oUv0.y), radius, uvOffset, rotate, scale); baseColor = (baseColor * vec4_splat(dist / mixdist)) + (blendColor * vec4_splat(1.0 - (dist / mixdist))); } gl_FragColor = baseColor; }