I am getting the same problem with a tech demo I am trying to create. Currently I am taking the deferred shading demo and translating it in to cg instead of using HLSL and GLSL. I would rather just use cg so I only have to learn the syntax for the one language. One problem I am running in to however is the ambient lighting pixel shader outputs depth and I am getting the same error from it. I enabled logging on the cg program manager plugin and it is showing that cg is compiling the depth output as a float3 instead of a plain float like it should. I am still working on seeing if I can try to get cg to compile depth as a single float scalar but figured I would post here and let everyone know what I had found. Also here is a snippet from the log of the plugin compiling the ambient lighting shader I was using along with the actual cg code.
Cg Code
Code: Select all
struct AMBIENTOUTPUT
{
float4 Color : COLOR;
float Depth : DEPTH;
};
AMBIENTOUTPUT AmbientLightingP( float2 TexCoord: TEXCOORD0,
float3 ProjCoord: TEXCOORD1,
uniform float4x4 Proj,
uniform float4 AmbientColor,
uniform sampler2D Tex0 : register(s0),
uniform sampler2D Tex1 : register(s1),
uniform sampler2D Tex2 : register(s2),
uniform sampler2D Tex3 : register(s3) )
{
// Load GBuffer in to structure;
GBUFFER In;
LoadGBuffer( In, TexCoord, Tex0, Tex1, Tex2, Tex3 );
// Clip fragment if depth is too close, so the skybox can be rendered on the background
float Depth = GetDepth( In );
clip( Depth - 5.0f );
AMBIENTOUTPUT Out;
// Calculate ambient colour of fragment
Out.Color = float4(AmbientColor * GetDiffuse( In ), 0.0f);
// Calculate depth of fragment;
Out.Depth = ProjCoord.z * Proj[2][2] + Proj[2][3] / Depth;
return Out;
}
Log output
Code: Select all
16:08:24: ps_3_0
// cgc version 2.0.0010, build date Dec 12 2007
// command line args: -q -profile ps_3_0 -entry AmbientLightingP
//vendor NVIDIA Corporation
//version 2.0.0.10
//profile ps_3_0
//program AmbientLightingP
//semantic AmbientLightingP.Proj
//semantic AmbientLightingP.AmbientColor
//semantic AmbientLightingP.Tex0 : TEXUNIT0
//semantic AmbientLightingP.Tex1 : TEXUNIT1
//semantic AmbientLightingP.Tex2 : TEXUNIT2
//semantic AmbientLightingP.Tex3 : TEXUNIT3
//var float2 TexCoord : $vin.TEXCOORD0 : ATTR0 : 0 : 1
//var float3 ProjCoord : $vin.TEXCOORD1 : ATTR1 : 1 : 1
//var float4x4 Proj : : c[0], 4 : 2 : 1
//var float4 AmbientColor : : c[4] : 3 : 1
//var sampler2D Tex0 : TEXUNIT0 : texunit 0 : 4 : 1
//var sampler2D Tex1 : TEXUNIT1 : texunit 1 : 5 : 0
//var sampler2D Tex2 : TEXUNIT2 : texunit 2 : 6 : 0
//var sampler2D Tex3 : TEXUNIT3 : texunit 3 : 7 : 1
//var float4 AmbientLightingP.Color : $vout.COLOR : COL : -1 : 1
//var float3 AmbientLightingP.Depth : $vout.DEPTH : DEPR : -1 : 1
//var <none>4 $kill_0000 : $vout.$kill : $kill : -1 : 0
//const c[5] = 65536 0.00390625 256 -1
//const c[6] = 1.5258789e-005 -5 0 1
dcl_2d s0
dcl_2d s3
def c5, 65536.00000000, 0.00390625, 256.00000000, -1.00000000
def c6, 0.00001526, -5.00000000, 0.00000000, 1.00000000
dcl_texcoord0 v0.xy
dcl_texcoord1 v1.xyz
texld r0.xy, v0, s0
mul r0.z, r0.y, c5.x
mul r0.w, r0.z, c5.y
abs r0.w, r0
frc r0.w, r0
mul r0.w, r0, c5.z
cmp r0.z, r0, r0.w, -r0.w
mad r0.y, -r0.z, c6.x, r0
add r0.w, r0.z, c5
mul r0.w, r0, r0
rcp r0.z, r0.w
mad r0.x, r0.y, c6, r0
mul r0.x, r0, r0.z
add r0.y, r0.x, c6
cmp r0.y, r0, c6.z, c6.w
mov_pp r1, -r0.y
rcp r0.x, r0.x
mul r0.w, r0.x, c2
texld r0.xyz, v0, s3
texkill r1.xyzw
mad oDepth.z, v1.z, c2.z, r0.w
mul oC0.xyz, r0, c4
mov oC0.w, c6.z