Passing parameters to CG shader via COLOR parameter

A place for users of OGRE to discuss ideas and experiences of utilitising OGRE in their games / demos / applications.
Post Reply
kubatp
Gnome
Posts: 342
Joined: Tue Jan 06, 2009 1:12 pm
x 7

Passing parameters to CG shader via COLOR parameter

Post by kubatp » Wed Dec 06, 2017 10:19 pm

I am having problems with passing parameter as COLOR component between vertex and fragment shader (in CG).

The problem is simple - I am out of TEXCOORDS used for passing parameters between vertex and fragment shader (I have all of them float4 and using all 8 texcoords). I need to pass to fragment shader one more float4 and I was wondering if it is possible to do it via COLOR component (which I dont use).
I have the param

Code: Select all

float4 color : COLOR;
in my input vertex shader parameters, I set it as an output parameter

Code: Select all

oColor = color;
and I want to use it in the fragment shader, which has oColor input. Unfortunately it doesn't work. I am not sure if it is even possible...? Maybe I am trying to find an issue in something what cannot be used like that?

Thank you for any advice:)
0 x

User avatar
areay
Bugbear
Posts: 818
Joined: Wed May 05, 2010 4:59 am
Location: Auckland, NZ

Re: Passing parameters to CG shader via COLOR parameter

Post by areay » Wed Dec 20, 2017 10:31 pm

Hi Kubatp,

Late reply but hopefully still useful to you.

I do the same thing in Cg for the same reason that you do. One thing I noticed that's different between my vp declaration and yours is that your param type doesn't have a trailing zero, not sure if that will make a difference but worth a shot.

So my shaders look like this

VP

Code: Select all

float4 colour        : COLOR0, //the input
out float4 oColour    : COLOR0, //the output
FP

Code: Select all

float4 colour    : COLOR0,
Out of interest what isn't working? Shader compilation or just doesn't take effect?
0 x

kubatp
Gnome
Posts: 342
Joined: Tue Jan 06, 2009 1:12 pm
x 7

Re: Passing parameters to CG shader via COLOR parameter

Post by kubatp » Thu Dec 21, 2017 10:48 am

areay wrote:
Wed Dec 20, 2017 10:31 pm
Out of interest what isn't working? Shader compilation or just doesn't take effect?
Hi Areay,
thank you for replying.

I also noticed the difference with other shaders (COlOR vs COLOR0), however I found out in help section that this semantic should be the same.
It was simply not working (but with no errors).

My problem was a bit more complicated, because I was creating manual object (with the colour information), converting it to mesh and expecting something out of the COLOR vector, but it was always zero in shader (even in VS shader). I suspect that there is somewhing wrong with the ConvertToMesh function. I also found similar problem here https://forums.ogre3d.org/viewtopic.php?t=75536.

I was able to managed it in different way.
My problem was that I was not able to use anymore TEXCOORDs between my vertex and fragment shader (all UVs were already float4), but I was able to pass more information via TEXCOORDs to the vertex shader. Basically I precalculate some stuff in VS and pass it via TEXCOORDs to the FS to increase performance. That is why my number of TEXCOORDs to VS is lower than to FS and I still had some "free" VS TEXCOORDs. So I used some of the free slots to pass data to VS and I pass the data from VS to FS via COLOR semantic and this works fine.
0 x

Post Reply