ywwynm / unity-eac-shader Goto Github PK
View Code? Open in Web Editor NEWEqui-Angular Cubemap shader for Unity
Equi-Angular Cubemap shader for Unity
Hello, thanks for the shader, it saved me a lot of time.
I had some troubles (half the cubemap needed flip) when I downloaded in 2K (with 4K Video Downloader) that video:
https://www.youtube.com/watch?v=YAABA-Ri0YI&t=219s
in unity 2019.3.a3 it's now perfect (still the line problem on some edges, but I'll work on it soon)
modified shader here (lines 60/62/65/73/74):
_MainTex ("Texture", 2D) = "white" {}
// No culling or depth
Cull Front ZWrite Off ZTest Always // Cull front will flip normals
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
struct appdata
{
float4 vertex : POSITION;
float3 normal : NORMAL;
};
struct v2f
{
float4 vertex : SV_POSITION;
float3 coord : TEXCOORD0;
};
v2f vert (appdata v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.coord = v.normal;
return o;
}
sampler2D _MainTex;
float4 frag (v2f i) : SV_Target {
float pi = UNITY_PI;
float3 xyz = normalize(i.coord);
float x = xyz.x, y = xyz.y, z = xyz.z;
float u = 0, v = 0;
float scale; // sphere coordinates to cube coordinates according to similar-triangle
if (abs(x) >= abs(y) && abs(x) >= abs(z)) {
scale = 1.0 / abs(x); // let's assume that radius of sphere is 1, which means u is 6.0 and v is 4.0
if (x >= 0) { // right
u = 5.0 - 4.0 * atan(z * scale) / pi;
v = 3.0 + 4.0 * atan(y * scale) / pi;
} else { // left
u = 1.0 + 4.0 * atan(z * scale) / pi;
v = 3.0 + 4.0 * atan(y * scale) / pi;
}
} else if (abs(y) >= abs(x) && abs(y) >= abs(z)) {
scale = 1.0 / abs(y);
if (y < 0) { // top // < instead of >=
u = 5.0 + 4.0 * atan(z * scale) / pi;
v = 1.0 - 4.0 * atan(x * scale) / pi; // - instead of +
} else { // down
u = 1.0 - 4.0 * atan(z * scale) / pi;
v = 1.0 - 4.0 * atan(x * scale) / pi; // - instead of +
}
} else if (abs(z) >= abs(x) && abs(z) >= abs(y)) {
scale = 1.0 / abs(z);
if (z >= 0) { // front
u = 3.0 + 4.0 * atan(x * scale) / pi;
v = 3.0 + 4.0 * atan(y * scale) / pi;
} else { // end
u = 3.0 - 4.0 * atan(y * scale) / pi; // - instead of +
v = 1.0 - 4.0 * atan(x * scale) / pi; // - instead of +
}
}
return tex2D(_MainTex, float2(u / 6.0, 1.0 - v / 4.0));
}
ENDCG
}
}
Hello. I have some problems. When I use this shader on sphere, video play fine, but I see some edges like a cube edges. Then I "play" with scale variable (0.99) on u and v and some edges disappear (I dont see them) but not all.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.