Auphim
24-06-2007 12:46:22
I'm trying to implement a Mogre-based example using a Cg vertex and a Cg fragment programs from Chapter 3 of "The Cg Tutorial".
My first idea was to create a manual object which uses a material with a custom parameter, but for some reason, I can´t set the paramenter.
My code is more or less this one:
The material is defined as:
The function C3E1v_anycolor is quite simple:
My problem is that "SetCustomParameter" doesn't work. I obtain a black star.
I have no errors on the Ogre.log, and if I change the material definition with "param_name constantColor vector4 0.2 0.8 0.3 1.0" the star has a beautiful green.
Any idea what I'm doing wrong??
My first idea was to create a manual object which uses a material with a custom parameter, but for some reason, I can´t set the paramenter.
My code is more or less this one:
class C3E1Tutorial : Mogre.Demo.ExampleApplication.Example
{
static void DrawStar(ManualObject obj, float x, float y, int starPoints, float R, float r)
{
int i;
float piOverStarPoints = 3.14159f / starPoints,
angle = 0.0f;
RenderOperation.OperationTypes operation = RenderOperation.OperationTypes.OT_TRIANGLE_FAN;
obj.Begin("CgTutorials/C3E1_Material", operation);
obj.Position(x, y, 0.0f); /* Center of star */
/* Emit exterior vertices for star's points. */
for (i = 0; i < starPoints; i++)
{
obj.Position(x + R * Math.Cos(angle), y + R * Math.Sin(angle), 0.0f);
angle += piOverStarPoints;
obj.Position(x + r * Math.Cos(angle), y + r * Math.Sin(angle), 0.0f);
angle += piOverStarPoints;
}
/* End by repeating first exterior vertex of star. */
angle = 0;
obj.Position(x + R * Math.Cos(angle), y + R * Math.Sin(angle), 0.0f);
obj.End();
}
public override void CreateScene()
{
const uint constantColor = 123;
SceneNode node1 = base.sceneMgr.RootSceneNode.CreateChildSceneNode("Tutorial03Node1");
ManualObject manualObj1 = sceneMgr.CreateManualObject("Tutorial03Object1");
/* star outer inner */
/* x y Points radius radius */
/* ===== ===== ====== ====== ====== */
node1.SetCustomParameter(constantColor, new Vector4(0.2f, 0.8f, 0.3f, 1.0f)); // Green
DrawStar(manualObj1, -0.1f, 0.0f, 5, 0.5f, 0.2f);
node1.AttachObject(manualObj1);
}
public override void CreateCamera()
{
// Create the camera
camera = sceneMgr.CreateCamera("PlayerCam");
// Position it at 30 in Z direction
camera.Position = new Vector3(0, 0, 5);
// Look at our triangle
camera.LookAt(new Vector3(0.0f, 0.0f, 0.0f));
camera.NearClipDistance = 1;
}
}
The material is defined as:
vertex_program CgTutorials/C3E1v_anycolor cg
{
source C3E1v_anycolor.cg
entry_point C3E1v_anycolor
profiles vs_1_1 arbvp1
}
material CgTutorials/C3E1_Material
{
technique
{
pass
{
vertex_program_ref CgTutorials/C3E1v_anycolor
{
param_named_auto worldViewProj worldviewproj_matrix
param_named_auto constantColor custom 123
}
}
}
}
The function C3E1v_anycolor is quite simple:
// This is C2E2f_passthru from "The Cg Tutorial" (Addison-Wesley, ISBN
// 0321194969) by Randima Fernando and Mark J. Kilgard. See page 62.
struct C3E1v_Output {
float4 position : POSITION;
float4 color : COLOR;
};
C3E1v_Output C3E1v_anycolor(float3 position : POSITION,
uniform float4x4 worldViewProj,
uniform float4 constantColor)
{
C3E1v_Output OUT;
OUT.position = mul(worldViewProj, float4(position,1));
OUT.color = constantColor; // some RGB color
return OUT;
}
My problem is that "SetCustomParameter" doesn't work. I obtain a black star.
I have no errors on the Ogre.log, and if I change the material definition with "param_name constantColor vector4 0.2 0.8 0.3 1.0" the star has a beautiful green.
Any idea what I'm doing wrong??