浏览代码
prep work for high-end mobile support
prep work for high-end mobile support
prep work for high-end mobile support. Most mobile doesn't support textureCubeArray so built-in to TextureCacheCubemap we allow a special path which converts to panorama on the fly upon texture cache population (only at the very moment when the cube map is injected and cached)./main
mmikk
8 年前
当前提交
c9bc3369
共有 2 个文件被更改,包括 194 次插入 和 31 次删除
-
143Assets/ScriptableRenderLoop/common/TextureCache.cs
-
82Assets/ScriptableRenderLoop/common/CubeToSpherical.shader
|
|||
Shader "Hidden/CubeToPano" { |
|||
Properties { |
|||
_SrcBlend ("", Float) = 1 |
|||
_DstBlend ("", Float) = 1 |
|||
} |
|||
SubShader { |
|||
|
|||
|
|||
|
|||
|
|||
Pass |
|||
{ |
|||
ZWrite Off |
|||
ZTest Always |
|||
Cull Off |
|||
Blend Off |
|||
|
|||
|
|||
CGPROGRAM |
|||
#pragma target 4.5 |
|||
#pragma vertex vert |
|||
#pragma fragment frag |
|||
|
|||
#include "UnityCG.cginc" |
|||
|
|||
UNITY_DECLARE_TEXCUBE(_srcCubeTexture); |
|||
|
|||
uniform int _cubeMipLvl; |
|||
uniform int _dstPanoWidth; |
|||
uniform int _dstPanoHeight; |
|||
|
|||
|
|||
struct v2f { |
|||
float4 vertex : SV_POSITION; |
|||
float2 texcoord : TEXCOORD0; |
|||
}; |
|||
|
|||
v2f vert (float4 vertex : POSITION, float2 texcoord : TEXCOORD0) |
|||
{ |
|||
v2f o; |
|||
o.vertex = UnityObjectToClipPos(vertex); |
|||
o.texcoord = texcoord.xy; |
|||
return o; |
|||
} |
|||
|
|||
half2 DirectionToSphericalTexCoordinate(half3 dir) // use this for the lookup |
|||
{ |
|||
// coordinate frame is (-Z,X) meaning negative Z is primary axis and X is secondary axis. |
|||
float recipPi = 1.0/3.1415926535897932384626433832795; |
|||
return half2( 1.0-0.5*recipPi*atan2(dir.x, -dir.z), asin(dir.y)*recipPi+0.5 ); |
|||
} |
|||
|
|||
half3 SphericalTexCoordinateToDirection(half2 sphTexCoord) |
|||
{ |
|||
float pi = 3.1415926535897932384626433832795; |
|||
float theta = (1-sphTexCoord.x) * (pi*2); |
|||
float phi = (sphTexCoord.y-0.5) * pi; |
|||
|
|||
float csTh, siTh, csPh, siPh; |
|||
sincos(theta, siTh, csTh); |
|||
sincos(phi, siPh, csPh); |
|||
|
|||
// theta is 0 at negative Z (backwards). Coordinate frame is (-Z,X) meaning negative Z is primary axis and X is secondary axis. |
|||
return float3(siTh*csPh, siPh, -csTh*csPh); |
|||
} |
|||
|
|||
half4 frag (v2f i) : SV_Target |
|||
{ |
|||
uint2 pixCoord = ((uint2) i.vertex.xy); |
|||
|
|||
half3 dir = SphericalTexCoordinateToDirection(i.texcoord.xy); |
|||
half3 res = UNITY_SAMPLE_TEXCUBE_LOD(_srcCubeTexture, dir, (float) _cubeMipLvl).xyz; |
|||
|
|||
return half4(res,1.0); |
|||
} |
|||
|
|||
ENDCG |
|||
} |
|||
|
|||
} |
|||
Fallback Off |
|||
} |
撰写
预览
正在加载...
取消
保存
Reference in new issue