Jump to content
  • Advertisement
Sign in to follow this  

[dx10] strange shader error

This topic is 4136 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

i get the following error when trying to compile my shader which isnt complete yet: "cannot have divergent gradient operations inside loops" effect/volumecloud.fx(163,30): error X4014: cannot have divergent gradient operations inside loops effect/volumecloud.fx(224,38): There was an error compiling expression
	// calculate depth
	// We need to determine the distance between the value stored in the depth buffer
    // and the value that came in from the GS
    // Because the depth values aren't linear, we need to transform the depthsample back into view space
    // in order for the comparison to give us an accurate distance
	float2 screenTex = 0.5 * ((IN.uvScreen.xy / IN.uvScreen.w) + float2(1,1));
	screenTex.y = 1.0 - screenTex.y;

	float depthSample = depthTexture.Sample(samPointClamp, screenTex).r;
	//float4 depthViewSample = mul(float4(IN.uvScreen.xy, depthSample, 1), projInv);
	//float4 depthViewFront = mul(float4(IN.uvScreen.xy, (IN.uvScreen.z / IN.uvScreen.w), 1), projInv);

	// we also need to convert the above too local/object space, to convert to light space
	float4 oBack = mul(float4(IN.uvScreen.xy, depthSample, 1), worldViewProjInv);
	float4 oFront = mul(float4(IN.uvScreen.xy, (IN.uvScreen.z / IN.uvScreen.w), 1), worldViewProjInv);

	float4 hLightBack = mul(oBack, projector.worldViewProj);
	float4 hLightFront = mul(oFront, projector.worldViewProj);

	// now convert to projective texture look up
	float2 lightScreenTexBack = 0.5 * ((hLightBack.xy / hLightBack.w) + float2(1,1));
	lightScreenTexBack.y = 1.0 - lightScreenTexBack.y;

	float2 lightScreenTexFront = 0.5 * ((hLightFront.xy / hLightFront.w) + float2(1,1));
	lightScreenTexFront.y = 1.0 - lightScreenTexFront.y;

	//float depthDiff = depthViewFront.z / depthViewFront.w - depthViewSample.z / depthViewSample.w; // cant we just do length(uvw1 - uvw2) ?
	float depthDiff = length(IN.uvw - colourTexture.Sample(samPointClamp, screenTex).rgb);
	depthDiff = saturate(depthDiff);

	float3 frontUVW = IN.uvw;
	float3 backUVW = colourTexture.Sample(samLinearClamp, screenTex).rgb;

	float4 volumeSample = 0;
	int numSamples = 64 * depthDiff;
	float invNumSamples = 1.0 / float(numSamples);
	for (int i = 0; i < numSamples; ++i)
		float percent = float(i) * invNumSamples;
		float3 currentUVW = lerp(backUVW, frontUVW, percent);
		float4 currentVolumeSample = volumeTexture.SampleLevel(samLinearClamp, currentUVW, 0);
		currentVolumeSample.a = currentVolumeSample.r * 0.1f;
		volumeSample.rgb += currentVolumeSample.rgb * currentVolumeSample.a * (1.0f - volumeSample.a);
		volumeSample.a += currentVolumeSample.a * (1.0 - volumeSample.a);

		// ray cast to the light to calculate lighting
		// we need to calulate the distance from the current sample to where we intersect the box towards the light
		float3 lightColour = float3(1.0, 1.0, 1.0);
		float2 lightScreenPos = lerp(lightScreenTexBack, lightScreenTexFront, percent);
		float4 currentVolumeLightSample = lightTexture.Sample(samLinearClamp, lightScreenPos, 0);

		float lightDepthDiff = length(currentUVW - currentVolumeLightSample.rgb);
		lightDepthDiff = saturate(lightDepthDiff);
		//float lightDepth = lightDepthTexture.Sample(samPointClamp, lightScreenPos).r;
		//float4 lightDepthView = mul(float4(lightScreenPos, depthSample, 1), projector.projInv); // NOTE: HERE, does this need to be in object space? or world space?

		//float lightDepthDiff = depthViewFront.z / depthViewFront.w - depthViewSample.z / depthViewSample.w;
		int numLightSamples = 8 * lightDepthDiff;
		float invNumLightSamples = 1.0 / float(numSamples);
		for (int l = 0; l < numLightSamples; ++l)
			float lightPercent = float(l) * invNumLightSamples;
			float4 currentLightVolumeSample = volumeTexture.SampleLevel(samLinearClamp, lerp(currentUVW, currentVolumeLightSample, percent), 0);
			lightColour *= (1.0 - (currentLightVolumeSample.r * 0.1f));

		// apply lighting. the more dense it is, the less light we receive
		volumeSample.rgb *= lightColour;

the line the compiles fails on is this - 163: float percent = float(i) * invNumSamples; but if i comment out the line: volumeSample.rgb *= lightColour; it compiles fine o.0 googling returns no results, nothing in the dx10 sdk about it either. any ideas what this error means?

Share this post

Link to post
Share on other sites
try to use different sample instrunction to read texture.
I didn't have the directX help here but I think that you are using sample instruction with gradient and probably you can use them 2 in the same shader. (if you comment that line the compiler remove all unusefull instruction)

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!