Page 1 of 1

Help me understand HLSL2GLSL errors in logs please?

Posted: Thu Feb 20, 2014 1:03 pm
by simedj
I have a Cg VS/PS pair which is not converting to GLSL for some reason, and I'm having problems understanding the logging output...

Code: Select all

//lighting.phong.perpixel.program
vertex_program lighting_phong_perpixel_VP cg
{
	profiles vs_2_0 arbvp1
	source lighting.phong.pixel.cg
	entry_point lighting_phong_perpixel_VP
	
	default_params
	{
		param_named_auto worldViewProj worldviewproj_matrix
	} 
}
fragment_program lighting_phong_perpixel_FP cg
{
	profiles ps_2_0 arbfp1 
	source lighting.phong.pixel.cg
	entry_point lighting_phong_perpixel_FP

	default_params
	{
		param_named_auto shininess surface_shininess
		param_named_auto lightAmbient derived_scene_colour
		param_named_auto lightDiffuse derived_light_diffuse_colour 0
		param_named_auto lightSpecular derived_light_specular_colour 0
		param_named_auto lightPosition light_position_object_space 0
		
		param_named_auto eyePosition camera_position_object_space
	} 
}

Code: Select all

//lighting.phong.pixel.cg
uniform float4x4 worldViewProj;

void lighting_phong_perpixel_VP(
	in float4 position		: POSITION,
	in float3 normal		: NORMAL,
	in float2 texCoord0	: TEXCOORD0,
	
	out float4 oPosition : POSITION,
	out float4 objectPos : TEXCOORD0,
	out float3 oNormal   : TEXCOORD1,
	out float2 oTexCoord0: TEXCOORD2)
{
  oPosition = mul(worldViewProj, position);
  objectPos = position;
  oNormal = normal;
  oTexCoord0 = texCoord0;
}

uniform float3 lightAmbient;
uniform float3 lightDiffuse;
uniform float3 lightSpecular;
uniform float  shininess;
uniform float4 lightPosition;
uniform float3 eyePosition;

float4 lighting_phong_perpixel_FP(
	in float4 position  : TEXCOORD0,
	in float3 normal    : TEXCOORD1,
	in float2 uv0	    : TEXCOORD2,
	uniform sampler2D texture)
{
  float3 texColor = tex2D(texture, uv0).xyz;
  
  // calculate diffuse & specular lighting coefficients
  float3 N = normalize(normal);
  float3 L = normalize(lightPosition.xyz - (position * lightPosition.w));
  float3 V = normalize(eyePosition - position.xyz);
  float3 H = normalize(L + V);
  float4 lighting = lit(dot(N,L),dot(N,H),shininess);

  float3 ambient = texColor * lightAmbient;
  float3 diffuse = texColor * lightDiffuse * lighting.y;
  float3 specular = lightSpecular * lighting.z;

  float4 color = float4(0,0,0,1);
  color.rgb = ambient + diffuse + specular;
  return color;
}
Here is the reelvant section from the Ogre log.
11:44:05: Parsing script lighting.phong.perpixel.program
11:44:05: File:lighting.phong.pixel.cg failed to convert from Cg to glsl with the following errors:
34: ERROR: 'texture' : syntax error syntax error
ERROR: 1 compilation errors. No code generated.

11:44:05: OGRE EXCEPTION(2:InvalidParametersException): Parameter called worldViewProj does not exist. in GpuProgramParameters::_findNamedConstantDefinition at /usr/local/ogre/ogre1.8/src/OgreMain/src/OgreGpuProgramParams.cpp (line 1719)
11:44:05: Compiler error: invalid parameters in lighting.phong.perpixel.program(12): setting of constant failed
11:44:05: File:lighting.phong.pixel.cg failed to convert from Cg to glsl with the following errors:
34: ERROR: 'texture' : syntax error syntax error
ERROR: 1 compilation errors. No code generated.


11:44:05: OGRE EXCEPTION(2:InvalidParametersException): Parameter called shininess does not exist. in GpuProgramParameters::_findNamedConstantDefinition at /usr/local/ogre/ogre1.8/src/OgreMain/src/OgreGpuProgramParams.cpp (line 1719)
11:44:05: Compiler error: invalid parameters in lighting.phong.perpixel.program(23): setting of constant failed
11:44:05: OGRE EXCEPTION(2:InvalidParametersException): Parameter called lightAmbient does not exist. in GpuProgramParameters::_findNamedConstantDefinition at /usr/local/ogre/ogre1.8/src/OgreMain/src/OgreGpuProgramParams.cpp (line 1719)
11:44:05: Compiler error: invalid parameters in lighting.phong.perpixel.program(24): setting of constant failed
11:44:05: OGRE EXCEPTION(2:InvalidParametersException): Parameter called lightDiffuse does not exist. in GpuProgramParameters::_findNamedConstantDefinition at /usr/local/ogre/ogre1.8/src/OgreMain/src/OgreGpuProgramParams.cpp (line 1719)
11:44:05: Compiler error: invalid parameters in lighting.phong.perpixel.program(25): setting of constant failed
11:44:05: OGRE EXCEPTION(2:InvalidParametersException): Parameter called lightSpecular does not exist. in GpuProgramParameters::_findNamedConstantDefinition at /usr/local/ogre/ogre1.8/src/OgreMain/src/OgreGpuProgramParams.cpp (line 1719)
11:44:05: Compiler error: invalid parameters in lighting.phong.perpixel.program(26): setting of constant failed
11:44:05: OGRE EXCEPTION(2:InvalidParametersException): Parameter called lightPosition does not exist. in GpuProgramParameters::_findNamedConstantDefinition at /usr/local/ogre/ogre1.8/src/OgreMain/src/OgreGpuProgramParams.cpp (line 1719)
11:44:05: Compiler error: invalid parameters in lighting.phong.perpixel.program(27): setting of constant failed
11:44:05: OGRE EXCEPTION(2:InvalidParametersException): Parameter called eyePosition does not exist. in GpuProgramParameters::_findNamedConstantDefinition at /usr/local/ogre/ogre1.8/src/OgreMain/src/OgreGpuProgramParams.cpp (line 1719)
11:44:05: Compiler error: invalid parameters in lighting.phong.perpixel.program(29): setting of constant failed
My main confusion is whether the "OGRE EXCEPTION: Parameter called X does not exist" are problems with the .cg file, or if these are just secondary errors... the shader conversion failed and as a result there are loads of errors because there is no shader on which to set the parameters?

Thanks for any help interpreting what this log is telling me exactly.

Re: Help me understand HLSL2GLSL errors in logs please?

Posted: Thu Feb 20, 2014 5:01 pm
by c6burns
It looks like the shader compilation fails, and all the rest of the errors are merely a result of the shader not being compiled. You are not going to be able to set named constants on an uncompiled shader, which is the string of errors below the true error "34: ERROR: 'texture' : syntax error syntax error"

Re: Help me understand HLSL2GLSL errors in logs please?

Posted: Thu Feb 20, 2014 5:10 pm
by scrawl
I'm guessing hlsl2glsl might choke on your uniform sampler being named "texture", since that is actually a function name in GLSL. Try if renaming that solves it.

Re: Help me understand HLSL2GLSL errors in logs please?

Posted: Thu Feb 20, 2014 6:57 pm
by simedj
scrawl wrote:I'm guessing hlsl2glsl might choke on your uniform sampler being named "texture", since that is actually a function name in GLSL. Try if renaming that solves it.
Bingo! That is indeed the root cause - there were a couple of other errors to fix but that was what it was telling me if I'd understood.

Thanks :)