Wintermute eccolo lo script di test fixato
Shader "Custom/SphericalTest" {
Properties {
}
SubShader {
Tags { "RenderType"="Opaque" }
LOD 200
CGPROGRAM
#pragma surface surf Lambert
#pragma target 3.0
struct Input {
float2 uv_MainTex;
};
static const float EPSILON = 1e-10;
static const float PI = 3.14159274;
float3 CartesianToSpherical(float3 cartesianCoordinates) {
if (cartesianCoordinates.x == 0) {
cartesianCoordinates.x = EPSILON;
}
float radius = length(cartesianCoordinates);
float polar = atan2(cartesianCoordinates.z, cartesianCoordinates.x);
float elevation = asin(cartesianCoordinates.y / radius);
return float3(radius, polar, elevation);
}
float3 SphericalToCartesian(float3 sphericalCoordinates) {
float a = sphericalCoordinates.x * cos(sphericalCoordinates.z);
return float3(
a * cos(sphericalCoordinates.y),
sphericalCoordinates.x * sin(sphericalCoordinates.z),
a * sin(sphericalCoordinates.y));
}
void surf (Input IN, inout SurfaceOutput o) {
float3 start = float3(10, -20, 125);
float3 spherical = CartesianToSpherical(start);
float3 end = SphericalToCartesian(spherical);
if (distance(start.xyz, end.xyz) < 0.01) {
o.Albedo = half3(0.0, 1.0, 1.0);
} else {
o.Albedo = half3(1.0, 0.0, 0.0);
}
//o.Albedo = half3(1.0, 1.0, 1.0) * distance(start, end);
o.Alpha = 1;
}
ENDCG
}
FallBack "Diffuse"
}