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: 368
Joined: Tue Jan 06, 2009 1:12 pm
x 43

Passing parameters to CG shader via COLOR parameter

Post by kubatp »

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:)
User avatar
areay
Bugbear
Posts: 819
Joined: Wed May 05, 2010 4:59 am
Location: Auckland, NZ
x 69

Re: Passing parameters to CG shader via COLOR parameter

Post by areay »

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?
kubatp
Gnome
Posts: 368
Joined: Tue Jan 06, 2009 1:12 pm
x 43

Re: Passing parameters to CG shader via COLOR parameter

Post by kubatp »

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.
Post Reply