Jump to content
  • Advertisement
Sign in to follow this  
maxest

OpenGL Bug in Cg compiler?

This topic is 3414 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

Yeah, I know that mostly when people suspect there might be a bug in such a serious tool, they must be wrong :) Yet I have a really strange problem. Look at this shader code:
PS_OUTPUT main(PS_INPUT input)
{
	PS_OUTPUT output;

	input.texCoord0 *= texCoordSize_normalMapSamplingOffset.xy;

	float3 pixelNormal = 2.0 * (0.5*tex2D(normalMap, input.texCoord0) + 0.5*tex2D(normalMap, input.texCoord0 + texCoordSize_normalMapSamplingOffset.zw)).xyz - 1.0;

	input.projSceneTexCoord.xy += rippliness * pixelNormal.xy * input.projSceneTexCoord.w; // here we multiply by .w, because it's not equal to 1.0 (due to perspective projection; see source projection matrix)
	input.projShadowMapTexCoord.xy += 0.5 * rippliness * pixelNormal.xy; // here we don't multiply by .w because shadow projection matrix is orthogonal

	float shadow = 1.0;
	if (receiveShadow)
		shadow = tex2Dproj(shadowMap, input.projShadowMapTexCoord).r;

	float3 sceneReflectedColor = reflectivness * tex2Dproj(sceneReflected, input.projSceneTexCoord).xyz;
	float3 diffuseMapColor = (1.0 - reflectivness) * tex2D(diffuseMap, input.texCoord0 + rippliness*pixelNormal.xy).xyz;

	output.color = color * (lightAmbient + shadow*lightDiffuse) * (float4(sceneReflectedColor + diffuseMapColor, 1.0));

	return output;
}
It just "shades" water plane. Look at the line where I check if it is meant to receive shadows. If so, I do a tex2dproj lookup. And it's fine... for my OpenGL renderer which uses NV40 profile. But when I compile *the same* shader for PS3.0 for my D3D renderer I get a "black water" with such debugger's hints:
D3D9 Helper: IDirect3DDevice9::DrawPrimitive failed: D3DERR_INVALIDCALL
Direct3D9: VS->PS Linker: X138: (Error) The current pixel shader expects input semantic 'texcoord3' including component(s): 'xyz', however the current vertex shader does not output 'texcoord3' at all.
Direct3D9: VS->PS Linker: X138: (Error) The current pixel shader expects input semantic 'texcoord4' including component(s): 'xyzw', however the current vertex shader does not output 'texcoord4' at all.
First-chance exception at 0x7c812afb in BlossomEngine_D3D9.exe: Microsoft C++ exception: long at memory location 0x0012eff4..
Direct3D9: (ERROR) :DrawPrimitive failed.
Which is a total rubbish! I don't even use such a semantic. But when I change the code to:
	float shadow = tex2Dproj(shadowMap, input.projShadowMapTexCoord).r;
	if (!receiveShadow)
		shadow = 1.0;
It works! I've also noticed, that the first version of code works, if I don't alter input.projShadowMapTexCoord.xy in the one line above. Is this some compiler bug?

Share this post


Link to post
Share on other sites
Advertisement
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!