Per pixel lighting shader problem

Problems building or running the engine, queries about how to use features etc.
Post Reply
Ogra
Goblin
Posts: 268
Joined: Mon Feb 04, 2013 1:34 pm

Per pixel lighting shader problem

Post by Ogra »

Hello guys,

I try the following per pixel lighting shader from this page : http://www.ogre3d.org/tikiwiki/tiki-ind ... l+Lighting

I save the ARNOLD.material and the ARNOLD.cg file. I set in my code

Code: Select all

pass->setVertexProgram("Simple_Perpixel_Vert");
pass->setFragmentProgram("Simple_PerPixel_Frag");
If I run I get this ogre.log errors :


08:14:07: Parsing script ARNOLD.material
08:14:07: Compiler error: unknown error in ARNOLD.material(97): token class, uniform, unrecognized.
08:14:07: OGRE EXCEPTION(7:InternalErrorException): Unable to compile Cg program Simple_PerPixel_Frag: CG ERROR : "The compile returned an error."
(79) : warning C7011: implicit cast from "float4" to "float3"
(89) : error C1115: unable to find compatible overloaded function "expand(float3)"
in CgProgram::compileMicrocode at ..\..\..\ogre_src_v1-8-0\PlugIns\CgProgramManager\src\OgreCgProgramManagerDll.cpp (line 67)
08:14:07: High-level program Simple_PerPixel_Frag encountered an error during loading and is thus not supported.
OGRE EXCEPTION(7:InternalErrorException): Unable to compile Cg program Simple_PerPixel_Frag: CG ERROR : "The compile returned an error."
(79) : warning C7011: implicit cast from "float4" to "float3"
(89) : error C1115: unable to find compatible overloaded function "expand(float3)"
in CgProgram::compileMicrocode at ..\..\..\ogre_src_v1-8-0\PlugIns\CgProgramManager\src\OgreCgProgramManagerDll.cpp (line 67)
08:14:07: OGRE EXCEPTION(2:InvalidParametersException): Named constants have not been initialised, perhaps a compile error. in GpuProgramParameters::_findNamedConstantDefinition at ..\..\ogre_src_v1-8-0\OgreMain\src\OgreGpuProgramParams.cpp (line 1441)
08:14:07: Compiler error: invalid parameters in ARNOLD.material(45): setting of constant failed
08:14:07: OGRE EXCEPTION(2:InvalidParametersException): Named constants have not been initialised, perhaps a compile error. in GpuProgramParameters::_findNamedConstantDefinition at ..\..\ogre_src_v1-8-0\OgreMain\src\OgreGpuProgramParams.cpp (line 1441)
08:14:07: Compiler error: invalid parameters in ARNOLD.material(47): setting of constant failed
08:14:07: OGRE EXCEPTION(2:InvalidParametersException): Named constants have not been initialised, perhaps a compile error. in GpuProgramParameters::_findNamedConstantDefinition at ..\..\ogre_src_v1-8-0\OgreMain\src\OgreGpuProgramParams.cpp (line 1441)
08:14:07: Compiler error: invalid parameters in ARNOLD.material(51): setting of constant failed
08:14:07: OGRE EXCEPTION(2:InvalidParametersException): Named constants have not been initialised, perhaps a compile error. in GpuProgramParameters::_findNamedConstantDefinition at ..\..\ogre_src_v1-8-0\OgreMain\src\OgreGpuProgramParams.cpp (line 1441)
08:14:07: Compiler error: invalid parameters in ARNOLD.material(57): setting of constant failed
08:14:07: OGRE EXCEPTION(7:InternalErrorException): Unable to compile Cg program Ambient: CG ERROR : "The compile returned an error."
(79) : warning C7011: implicit cast from "float4" to "float3"
(0) : error C3001: no program defined
in CgProgram::compileMicrocode at ..\..\..\ogre_src_v1-8-0\PlugIns\CgProgramManager\src\OgreCgProgramManagerDll.cpp (line 67)
08:14:07: High-level program Ambient encountered an error during loading and is thus not supported.
OGRE EXCEPTION(7:InternalErrorException): Unable to compile Cg program Ambient: CG ERROR : "The compile returned an error."
(79) : warning C7011: implicit cast from "float4" to "float3"
(0) : error C3001: no program defined
in CgProgram::compileMicrocode at ..\..\..\ogre_src_v1-8-0\PlugIns\CgProgramManager\src\OgreCgProgramManagerDll.cpp (line 67)
08:14:07: OGRE EXCEPTION(2:InvalidParametersException): Named constants have not been initialised, perhaps a compile error. in GpuProgramParameters::_findNamedConstantDefinition at ..\..\ogre_src_v1-8-0\OgreMain\src\OgreGpuProgramParams.cpp (line 1441)
08:14:07: Compiler error: invalid parameters in ARNOLD.material(121): setting of constant failed
08:14:07: OGRE EXCEPTION(2:InvalidParametersException): Named constants have not been initialised, perhaps a compile error. in GpuProgramParameters::_findNamedConstantDefinition at ..\..\ogre_src_v1-8-0\OgreMain\src\OgreGpuProgramParams.cpp (line 1441)
08:14:07: Compiler error: invalid parameters in ARNOLD.material(123): setting of constant failed
08:14:07: Finished parsing scripts for resource group PerPixelLightingShader


What can I do to solve?
User avatar
Kojack
OGRE Moderator
OGRE Moderator
Posts: 7157
Joined: Sun Jan 25, 2004 7:35 am
Location: Brisbane, Australia
x 534

Re: Per pixel lighting shader problem

Post by Kojack »

Hmm, that tutorial needs a little fixing.
Everything in ARNOLD.material from the "void Ambient_vp(" bit down should be removed. That's cg code, it can't work in a material file (it needs to be in a cg file).
It's apparently optional code you can include into the other files if you want to enable multipass multilight support.
Ogra
Goblin
Posts: 268
Joined: Mon Feb 04, 2013 1:34 pm

Re: Per pixel lighting shader problem

Post by Ogra »

Thanks so far. Now in my error log the first error with the ambient part is away. But the rest is still there :


09:11:08: Parsing script ARNOLD.material
09:11:08: OGRE EXCEPTION(7:InternalErrorException): Unable to compile Cg program Simple_PerPixel_Frag: CG ERROR : "The compile returned an error."
(79) : warning C7011: implicit cast from "float4" to "float3"
(89) : error C1115: unable to find compatible overloaded function "expand(float3)"
in CgProgram::compileMicrocode at ..\..\..\ogre_src_v1-8-0\PlugIns\CgProgramManager\src\OgreCgProgramManagerDll.cpp (line 67)
09:11:08: High-level program Simple_PerPixel_Frag encountered an error during loading and is thus not supported.
OGRE EXCEPTION(7:InternalErrorException): Unable to compile Cg program Simple_PerPixel_Frag: CG ERROR : "The compile returned an error."
(79) : warning C7011: implicit cast from "float4" to "float3"
(89) : error C1115: unable to find compatible overloaded function "expand(float3)"
in CgProgram::compileMicrocode at ..\..\..\ogre_src_v1-8-0\PlugIns\CgProgramManager\src\OgreCgProgramManagerDll.cpp (line 67)
09:11:08: OGRE EXCEPTION(2:InvalidParametersException): Named constants have not been initialised, perhaps a compile error. in GpuProgramParameters::_findNamedConstantDefinition at ..\..\ogre_src_v1-8-0\OgreMain\src\OgreGpuProgramParams.cpp (line 1441)
09:11:08: Compiler error: invalid parameters in ARNOLD.material(45): setting of constant failed
09:11:08: OGRE EXCEPTION(2:InvalidParametersException): Named constants have not been initialised, perhaps a compile error. in GpuProgramParameters::_findNamedConstantDefinition at ..\..\ogre_src_v1-8-0\OgreMain\src\OgreGpuProgramParams.cpp (line 1441)
09:11:08: Compiler error: invalid parameters in ARNOLD.material(47): setting of constant failed
09:11:08: OGRE EXCEPTION(2:InvalidParametersException): Named constants have not been initialised, perhaps a compile error. in GpuProgramParameters::_findNamedConstantDefinition at ..\..\ogre_src_v1-8-0\OgreMain\src\OgreGpuProgramParams.cpp (line 1441)
09:11:08: Compiler error: invalid parameters in ARNOLD.material(51): setting of constant failed
09:11:08: OGRE EXCEPTION(2:InvalidParametersException): Named constants have not been initialised, perhaps a compile error. in GpuProgramParameters::_findNamedConstantDefinition at ..\..\ogre_src_v1-8-0\OgreMain\src\OgreGpuProgramParams.cpp (line 1441)
09:11:08: Compiler error: invalid parameters in ARNOLD.material(57): setting of constant failed
User avatar
Kojack
OGRE Moderator
OGRE Moderator
Posts: 7157
Joined: Sun Jan 25, 2004 7:35 am
Location: Brisbane, Australia
x 534

Re: Per pixel lighting shader problem

Post by Kojack »

Hmm, that expand function in the shader isn't part of CG.
Stick this at the top of the cg file and that error should go away:

Code: Select all

float3 expand(float3 v)
{
   return (v - 0.5) * 2;
}
Ogra
Goblin
Posts: 268
Joined: Mon Feb 04, 2013 1:34 pm

Re: Per pixel lighting shader problem

Post by Ogra »

Thank you very very much. I don´t why this is not in the tutorial? Perhaps somebody (ARNOLD?) should add this?

Now it runs without errors, but I don´t see any aesthetic advancement. I want to use the per-pixel lighting shader to smooth the edges of my objects, but they look like without per-pixel lighting.... I understand the use wrong or must I set something else in the code?
User avatar
Kojack
OGRE Moderator
OGRE Moderator
Posts: 7157
Joined: Sun Jan 25, 2004 7:35 am
Location: Brisbane, Australia
x 534

Re: Per pixel lighting shader problem

Post by Kojack »

Have you applied the Simple_Perpixel material to an entity?
I want to use the per-pixel lighting shader to smooth the edges of my objects, but they look like without per-pixel lighting
Per pixel lighting won't smooth edges. It provides more accurate lighting values within a triangle.
(This does have a side effect of making low poly regions have smoother lighting, but it has nothing to do with edges)
A model with small triangles (in ratio to the distance of the lights) will look virtually identical with vertex or per pixel lighting.
Ogra
Goblin
Posts: 268
Joined: Mon Feb 04, 2013 1:34 pm

Re: Per pixel lighting shader problem

Post by Ogra »

But you said (http://www.ogre3d.org/forums/viewtopic.php?f=2&t=76447)
Is it possible to interpolate normals in ogre?
If you use a "per pixel lighting" shader.
because of that I tried the per-pixel lighting shader...
Have you applied the Simple_Perpixel material to an entity?
I delete this part from the ARNOLD.material and set :

Code: Select all

pass->setVertexProgram("Simple_Perpixel_Vert");
pass->setFragmentProgram("Simple_PerPixel_Frag");
by myself.
AusSkiller
Gremlin
Posts: 158
Joined: Wed Nov 28, 2012 1:38 am
x 13

Re: Per pixel lighting shader problem

Post by AusSkiller »

Ogra wrote:
Is it possible to interpolate normals in ogre?
If you use a "per pixel lighting" shader.
because of that I tried the per-pixel lighting shader...
The normals are interpolated across a triangle so the only place you can notice the difference of per-pixel lighting is as Kojack said when the light is affecting the inside of a triangle, so per-pixel lighting is only really noticeable on really low poly models with large triangles... unless you add normal mapping into the mix but that's a whole different issue and it doesn't sound like it applies to your situation.

If you are having troubles with normals not looking smooth it is most likely an issue with the model. It might be easier to help if you post a screenshot and explain what exactly in it isn't what you want.
Ogra
Goblin
Posts: 268
Joined: Mon Feb 04, 2013 1:34 pm

Re: Per pixel lighting shader problem

Post by Ogra »

Okay, then I hadn´t understand it correctly.

I posted a screenshot here : http://www.ogre3d.org/forums/viewtopic.php?f=2&t=76447
User avatar
Kojack
OGRE Moderator
OGRE Moderator
Posts: 7157
Joined: Sun Jan 25, 2004 7:35 am
Location: Brisbane, Australia
x 534

Re: Per pixel lighting shader problem

Post by Kojack »

Nope, that pic didn't have any problems with smooth lighting or normals.
Jagged edges are caused by running your program in low resolution without turning on a form of anti aliasing.
Ogra
Goblin
Posts: 268
Joined: Mon Feb 04, 2013 1:34 pm

Re: Per pixel lighting shader problem

Post by Ogra »

Here is another picture (a part of one scene object) which shows the problematic more detailed.

This shows the surface not smooth. You see the single polygons and that is not what I want.
Attachments
Unbenannt.PNG
Unbenannt.PNG (2 KiB) Viewed 1363 times
bstone
OGRE Expert User
OGRE Expert User
Posts: 1920
Joined: Sun Feb 19, 2012 9:24 pm
Location: Russia
x 201

Re: Per pixel lighting shader problem

Post by bstone »

You need to set your faces to smooth shading in whatever app you create them. That will eliminate duplicate vertices and the faceted look.
Ogra
Goblin
Posts: 268
Joined: Mon Feb 04, 2013 1:34 pm

Re: Per pixel lighting shader problem

Post by Ogra »

I used blender. There I should smooth, ok. Is there no way to change this later (after blender) with ogre?
bstone
OGRE Expert User
OGRE Expert User
Posts: 1920
Joined: Sun Feb 19, 2012 9:24 pm
Location: Russia
x 201

Re: Per pixel lighting shader problem

Post by bstone »

Have you found one?
Ogra
Goblin
Posts: 268
Joined: Mon Feb 04, 2013 1:34 pm

Re: Per pixel lighting shader problem

Post by Ogra »

No and because of that I had asked you. :(
bstone
OGRE Expert User
OGRE Expert User
Posts: 1920
Joined: Sun Feb 19, 2012 9:24 pm
Location: Russia
x 201

Re: Per pixel lighting shader problem

Post by bstone »

Why wouldn't you just follow my advice then?
Ogra
Goblin
Posts: 268
Joined: Mon Feb 04, 2013 1:34 pm

Re: Per pixel lighting shader problem

Post by Ogra »

I will follow, but is it forbidden to ask after other possibilities?
bstone
OGRE Expert User
OGRE Expert User
Posts: 1920
Joined: Sun Feb 19, 2012 9:24 pm
Location: Russia
x 201

Re: Per pixel lighting shader problem

Post by bstone »

No, it's not forbidden. But you have an interesting way of thinking. How did you end up in the 3D graphics field?
Post Reply