I've been stuck on this problem for just too long. Long story short, the compiler returns "syntax error: unexpected token" for break, continue, [loop], [unroll] and pretty much every other attribute.
I am using DirectX SDK June 2010 on Windows 10, and compiling shaders for Source Engine 2013.
Microsoft Docs says these statements should be supported for pixel shader 3.0, so I absolutely have no idea what's wrong.
The entire code can be found here:
#include "common_vertexlitgeneric_dx9.h"
// front sampler and back samplers are used to calculate ray starting and ending points and direction.
sampler2D frontSampler : register(s0);
sampler2D backSampler : register(s1);
sampler3D volSampler : register(s2);
const float3 nPasses : register(c0);
const float3 nAlphaCorrection : register(c1);
const float3 nClip : register(c2);
struct PS_INPUT
{
float4 FragPos : TEXCOORD0;
float4 vPos : TEXCOORD1;
};
float4 raymarch(float4 p)
{
float2 texC = p.xy /= p.w;
texC.x = 0.5f*texC.x + 0.5f;
texC.y = -0.5f*texC.y + 0.5f;
float3 front = tex2D(frontSampler, texC ).xyz;
float3 back = tex2D(backSampler,texC).xyz;
float3 dir = normalize(back - front);
float4 pos = float4(front, 0);
float4 dst = float4(0, 0, 0, 0);
float4 src = 0;
float value = 0;
float3 Step = dir * (1/nPasses.x);
// loop doesn't work, nor does unroll in this step
// if loop then syntax error unexpected token 'for'
// if unroll then undeclared identifier 'unroll'
[loop]
for(int i = 0; i < nPasses.x; i++)
{
pos.w = 0;
value = tex3Dlod(volSampler, pos).r;
src = (float4)value;
src.x = src.x * 2 * step(pos.z, nClip.x);
src.y = pow(src.y*2,2)* step(pos.z, nClip.x);
src.z = pow(src.z*2,2)* step(pos.z, nClip.x);
src.a = src.a * step(pos.z, nClip.x);
src.a *= nAlphaCorrection.x; //reduce the alpha to have a more transparent result
//Front to back blending
// dst.rgb = dst.rgb + (1 - dst.a) * src.a * src.rgb
// dst.a = dst.a + (1 - dst.a) * src.a
src.rgb *= src.a;
dst = (1.0f - dst.a)*src + dst;
//break from the loop when alpha gets high enough
if (dst.a > 1.0f)
break;
//advance the current position
//break if the position is greater than <1, 1, 1>
if (pos.x > 1.0f | pos.y > 1.0f | pos.z > 1.0f)
continue;
pos.xyz += Step;
}
return dst;
}
float4 main( PS_INPUT i ) : COLOR
{
return FinalOutput( raymarch(i.vPos).rgba, 0, PIXEL_FOG_TYPE_NONE, TONEMAP_SCALE_LINEAR );
}
fx.exeis located that you are invoking? \$\endgroup\$