【发布时间】:2020-03-12 14:22:55
【问题描述】:
第 82 行未声明的标识符“sphereHit”(在 d3d11 上)
(shader noob sorry)我需要一些帮助来解决这些错误,谢谢...
Shader "Unlit/VolSDFOne"
{
Properties
{
_MainTex ("Texture", 2D) = "white" {}
}
SubShader
{
Tags { "RenderType"="Opaque" }
LOD 100
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
// make fog work
#pragma multi_compile_fog
#include "UnityCG.cginc"
struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};
struct v2f
{
float2 uv : TEXCOORD0;
UNITY_FOG_COORDS(1)
float4 vertex : SV_POSITION;
float4 pos : SV_POSITION; // Clip space
float3 wPos : TEXCOORD1; // World position
};
sampler2D _MainTex;
float4 _MainTex_ST;
v2f vert (appdata v)
{
v2f o;
o.pos = UnityObjectToClipPos(v.vertex);
o.wPos = mul(unity_ObjectToWorld, v.vertex).xyz;
return o;
}
float3 _Centre;
float _Radius;
fixed4 frag (v2f i) : SV_Target
{
// sample the texture
fixed4 col = tex2D(_MainTex, i.uv);
// apply fog
UNITY_APPLY_FOG(i.fogCoord, col);
return col;
float3 worldPosition = i.wPos;
float3 viewDirection = normalize(i.wPos - _WorldSpaceCameraPos);
bool sphereHit (float3 p)
{
return distance(p,_Centre) < _Radius;
}
#define STEP_SIZE 0.01
#define STEPS 35
bool raymarchHit (float3 position, float3 direction)
{
for (int i = 0; i < STEPS; i++)
{
if ( sphereHit(position) )
return true;
position += direction * STEP_SIZE;
}
return false;
}
if ( raymarchHit(worldPosition, viewDirection) )
return fixed4(1,0,0,1); // Red if hit the ball
else
return fixed4(1,1,1,1); // White otherwise
}
ENDCG
}
}
}
【问题讨论】:
-
尝试在你的问题中多加一点努力。不要在标题中添加不必要的信息,例如您的经历或寻求帮助的信息,也不要在您的问题中填写很多 a 以达到问题的最少字符数。您本可以利用该空间告诉我们您到目前为止所做的尝试。
-
从例如开始至少告诉我们哪一行是 82 .. 没有人想数他们...
-
对不起,我很沮丧
标签: unity3d shader fragment-shader