#Hi I need some help optimizing this
1 messages · Page 1 of 1 (latest)
I can't send the code?
half3 n = 0;
float height_start = -1;
float height_sum = 0;
TriplanarUV uv = GetTriplanarUV(IN.localCoord, IN.localNormal, _TextureScale);
StochasticValue valX = tex2DStochasticValues(uv.x);
StochasticValue valY = tex2DStochasticValues(uv.y);
StochasticValue valZ = tex2DStochasticValues(uv.z);
int validIndice = 0;
for(int a = 0; a < layerCount; a++)
{
float layerWeight = clamp(UNITY_SAMPLE_TEX2DARRAY(biomeMasks, fixed3(IN.textcoord, a)).r*_Strength,0,1);
if(layerWeight > _ValidityTreshold)
{
float hx = tex2DStochastic(valX, slopeTextureHeights, sampler_slopeTextureHeights, a);
float hy = tex2DStochastic(valY, textureHeights, sampler_textureHeights, a);
float hz = tex2DStochastic(valZ, slopeTextureHeights, sampler_slopeTextureHeights, a);
fixed3 blendAxes = GetWeights(IN.localNormal, float3(hx, hy, hz), BlendOffset[a], BlendHeightStrength[a], Power[a]);
float h = hx*blendAxes.x+hy*blendAxes.y+hz*blendAxes.z;
h *= layerWeight;
height_start = max(height_start, h);
Heights[validIndice] = h;
BlendAxes[validIndice] = blendAxes;
ValidIndices[validIndice] = a;
validIndice ++;
}
}
height_start -= _HeightBlendRange;
for(int b = 0; b < validIndice; b++)
{
Heights[b] = max(Heights[b]-height_start, 0);
height_sum += Heights[b];
}
for(int d = 0; d < validIndice; d++)
{
// Albedo comes from a texture tinted by color
int i = ValidIndices[d];
fixed3 blendAxes = BlendAxes[d];
float layerWeight = Heights[d]/height_sum;
c += triplanarTexture(slopeTextures, sampler_slopeTextures, baseTextures, sampler_baseTextures, valX, valY, valZ, blendAxes, i)*layerWeight;
//float4 normal = triplanarTexture(slopeTextureNormals, sampler_slopeTextureNormals, textureNormals, sampler_textureNormals, uv, blendAxes, i);
float3 normalX = UnpackScaleNormal(tex2DStochastic(valX, slopeTextureNormals, sampler_slopeTextureNormals, i), NormalStrength[i])*blendAxes.x;
float3 normalY = UnpackScaleNormal(tex2DStochastic(valY, textureNormals, sampler_textureNormals, i), NormalStrength[i])*blendAxes.y;
float3 normalZ = UnpackScaleNormal(tex2DStochastic(valZ, slopeTextureNormals, sampler_slopeTextureNormals, i), NormalStrength[i])*blendAxes.z;
n += (normalX+normalY+normalZ)*layerWeight;
}
But it cannot unroll the loop, not sure why