I have the following shader, see below.
For some reason the Unity Editor gives error messages that it can’t find any of the properties. How can I fix these errors? I tried restarting my computer as suggested for these errors in other posts, to no avail.
Example:
Material doesn’t have a texture property ‘_BumpMap’
UnityEditor.DockArea:OnGUI()
However sometimes I get the following error, I take it is caused by the for loop.
Shader error in ‘Voxels/VoxelizeShader’: Program ‘frag’, Temporary register limit of 32 exceeded; 69 registers needed to compile program at line 13
Shader "Voxels/VoxelizeShader" {
Properties {
_MainTex("Base (RGB)", 2D) = "white" {}
_BumpMap("Bumpmap", 2D) = "bump" {}
_StepSize("Raycast Step Size", Float) = 0.1
_VoxelTex("Empty VoxelTex", 3D) = "white" {}
}
SubShader {
Pass {
Cull Back
Lighting On
CGPROGRAM
#pragma exclude_renderers d3d11 xbox360 gles
#pragma vertex vert
#pragma fragment frag
#pragma target 3.0
#include "UnityCG.cginc"
struct a2v
{
float4 vertex : POSITION;
float3 normal : NORMAL;
float4 texcoord : TEXCOORD0;
float4 tangent : TANGENT;
};
struct v2f {
float4 pos : SV_POSITION;
float2 uv : TEXCOORD0;
float3 vertex;
float3 normal;
float3 lightDir;
};
uniform sampler3D _VoxelTex;
uniform sampler2D _MainTex;
uniform float4 _MainTex_ST;
uniform sampler2D _BumpMap;
uniform float4 _BumpMap_ST;
uniform uniform float4 _LightColor0;
uniform float _VoxelRaycasting;
uniform float _StepSize;
v2f vert( a2v v ) {
v2f o;
o.pos = mul (UNITY_MATRIX_MVP, v.vertex);
o.vertex = v.vertex;
o.normal = v.normal;
TANGENT_SPACE_ROTATION;
o.uv = v.texcoord;
// lighting from single directional light + ambient
o.lightDir = mul(rotation, ObjSpaceLightDir(v.vertex));
return o;
}
float4 getVoxel(float3 vposition) {
float4 color = tex3D(_VoxelTex, vposition);
return color;
}
bool showVoxels(float3 vposition) {
if (getVoxel(vposition).a > 0.5)
return true;
else
return false;
}
void frag(v2f IN, out float4 finalColor : COLOR) {
if (_VoxelRaycasting > 0.5 && showVoxels(IN.vertex)) {
finalColor = tex2D(_MainTex, TRANSFORM_TEX(IN.uv.xy, _MainTex));
float3 n = UnpackNormal(tex2D (_BumpMap, TRANSFORM_TEX (IN.uv.xy, _BumpMap)));
float3 lightColor = UNITY_LIGHTMODEL_AMBIENT.xyz;
float lengthSq = dot(IN.lightDir, IN.lightDir);
float atten = 1.0 / (1.0 + lengthSq * unity_LightAtten[0].z);
float diff = saturate (dot (n, normalize(IN.lightDir)));
lightColor += _LightColor0.rgb * (diff * atten);
finalColor.rgb = lightColor * finalColor.rgb * 2;
} else {
//
// float random = fract(sin(gl_FragCoord.x * 12.9898 + gl_FragCoord.y * 78.233) * 43758.5453);
float actStepSize = _StepSize;
float4 rayStart = mul(_World2Object, float4(_WorldSpaceCameraPos, 1));
float3 dir = IN.vertex - rayStart;
float startLength = length(dir);
float3 deltaDir = normalize(dir) * actStepSize;
float deltaDirLen = length(deltaDir);
float3 voxelCoord = rayStart;
float4 colorAcum;
float intensity;
float lengthAcum = 0.0;
bool solved = false;
int loopSize = 160;
for(int i = 0; i < loopSize; i++) {
colorAcum = getVoxel(voxelCoord);
if (colorAcum.a < 0.5) {
solved = true;
break;
}
voxelCoord += deltaDir;
lengthAcum += deltaDirLen;
}
if (solved) {
finalColor = colorAcum;
} else {
discard;
}
}
}
ENDCG
SetTexture [_MainTex] {
Combine texture * primary DOUBLE, texture * primary
}
SetTexture [_Bumpmap]
SetTexture [_VoxelTex]
}
}
Fallback "VertexLit"
}