Evgenii Golubev
8 年前
当前提交
62d91392
共有 6 个文件被更改,包括 218 次插入 和 39 次删除
-
24Assets/ScriptableRenderLoop/common/ShaderBase.h
-
137Assets/ScriptableRenderLoop/common/TextureCache.cs
-
4Assets/ScriptableRenderLoop/fptl/LightingTemplate.hlsl
-
10Assets/ScriptableRenderLoop/fptl/ReflectionTemplate.hlsl
-
2README.md
-
80Assets/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; |
|||
|
|||
|
|||
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