How to write GpuProgramParameters via code?

Problems building or running the engine, queries about how to use features etc.
Post Reply
User avatar
KungFooMasta
OGRE Contributor
OGRE Contributor
Posts: 2087
Joined: Thu Mar 03, 2005 7:11 am
Location: WA, USA
x 16
Contact:

How to write GpuProgramParameters via code?

Post by KungFooMasta »

I'm trying to write the following portion of a material via code:

Code: Select all

pass
    {
      // splatting pass
      
      lighting off
      
      vertex_program_ref ET/Programs/VSLodMorph2
      {
      }
      
      fragment_program_ref ET/Programs/PSSplat2
      {
        param_named splatScaleX float 20
	param_named splatScaleZ float 20
      }
      
      texture_unit
      {
        // first coverage map, dynamically managed
	texture ETSplatting0
      }
...
So far this is what I have:

Code: Select all

// creates a coverage map in memory - name + "0"
		mSplattingManager->setNumTextures(1);
		mTerrainMaterial = Ogre::MaterialManager::getSingleton().create(name,"Terrain");

		Ogre::Technique* t = mTerrainMaterial->getTechnique(0);
		Ogre::Pass* p = t->getPass(0);
		p->setLightingEnabled(false);
		p->setVertexProgram("ET/Programs/VSLodMorph2");
		p->setFragmentProgram("ET/Programs/PSSplat2");
		//p->setFragmentProgramParameters(
		Ogre::GpuProgramParameters

		// add coverage map
		p->createTextureUnitState(name+"0");

		// add splatting texture
		p->createTextureUnitState(baseTexture);
How do I write the following as GpuProgramParameters?

Code: Select all

param_named splatScaleX float 20
param_named splatScaleZ float 20
Thanks for any help,

KungFooMasta
tgraupmann
Gnoll
Posts: 696
Joined: Sun Feb 20, 2005 5:28 am
Contact:

Post by tgraupmann »

Where is your vertex program definition? This goes at the top of your material script:

Code: Select all

vertex_program ET/Programs/VSLodMorph2 cg
{
    source VSLodMorph2.cg
    entry_point main
    profiles vs_1_1 arbvp1

    default_params
    {
        param_named splatScaleX float 20
        param_named splatScaleZ float 20 
    }
}

Code: Select all

fragment_program ET/Programs/PSSplat2 cg
{
    source PSSplat2.cg
    entry_point main
    profiles ps_1_1 arbvp1

    default_params
    {
        param_named splatScaleX float 20
        param_named splatScaleZ float 20 
    }
}
User avatar
KungFooMasta
OGRE Contributor
OGRE Contributor
Posts: 2087
Joined: Thu Mar 03, 2005 7:11 am
Location: WA, USA
x 16
Contact:

Post by KungFooMasta »

PSSplat2:

Code: Select all

void main
(
  float2 iTexCoord0 : TEXCOORD0,
 
  out float4 oColor : COLOR,
 
  uniform sampler2D covMap1,
  uniform sampler2D covMap2,
  uniform sampler2D splat1,
  uniform sampler2D splat2,
  uniform sampler2D splat3,
  uniform sampler2D splat4,
  uniform sampler2D splat5,
  uniform sampler2D splat6,

  uniform float splatScaleX,
  uniform float splatScaleZ
) 
{
  float3 cov1 = tex2D(covMap1, iTexCoord0).rgb;
  float3 cov2 = tex2D(covMap2, iTexCoord0).rgb;
  
  iTexCoord0.x *= splatScaleX;
  iTexCoord0.y *= splatScaleZ;
  
  oColor = tex2D(splat1, iTexCoord0) * cov1.x
           + tex2D(splat2, iTexCoord0) * cov1.y
           + tex2D(splat3, iTexCoord0) * cov1.z
           + tex2D(splat4, iTexCoord0) * cov2.x
           + tex2D(splat5, iTexCoord0) * cov2.y
           + tex2D(splat6, iTexCoord0) * cov2.z;

}

Code: Select all

fragment_program ET/Programs/PSSplat2 cg
{
  source PSSplat2.cg
  entry_point main
  profiles ps_2_0 arbfp1
}
This is the function with arguements. Is this what you're looking for?

This is taken from CABAListic's Editable Terrain Manager.
psquare
Hobgoblin
Posts: 554
Joined: Tue Nov 14, 2006 3:26 pm
x 7

Post by psquare »

Code: Select all

GpuProgramParametersSharedPtr fpParams = 
		p->getFragmentProgramParameters();

Real val = 20.0;
if (fpParams->_findNamedConstantDefinition("splatScaleX"))
{
	fpParams->setNamedConstant("splatScaleX", val);
}
	
if (fpParams->_findNamedConstantDefinition("splatScaleY"))
{
	fpParams->setNamedConstant("splatScaleY", val);
}
tgraupmann
Gnoll
Posts: 696
Joined: Sun Feb 20, 2005 5:28 am
Contact:

Post by tgraupmann »

That's right but it could look like this:

Code: Select all

fragment_program ET/Programs/PSSplat2 cg
{
  source PSSplat2.cg
  entry_point main
  profiles ps_2_0 arbfp1
    default_params
    {
        param_named splatScaleX float 20
        param_named splatScaleZ float 20
    } 
} 
psquare
Hobgoblin
Posts: 554
Joined: Tue Nov 14, 2006 3:26 pm
x 7

Post by psquare »

Sure, but I think KungFooMasta wants to do it via code.
User avatar
KungFooMasta
OGRE Contributor
OGRE Contributor
Posts: 2087
Joined: Thu Mar 03, 2005 7:11 am
Location: WA, USA
x 16
Contact:

Post by KungFooMasta »

Thanks tgraupmann and jimmiemalone! I'm still having issues, but I don't think it's related to setting the parameters. Or is it? haha.

Thanks again!

KungFooMasta
User avatar
KungFooMasta
OGRE Contributor
OGRE Contributor
Posts: 2087
Joined: Thu Mar 03, 2005 7:11 am
Location: WA, USA
x 16
Contact:

Post by KungFooMasta »

The code I have seems to be displaying fine, but when I serialize it out to file, it seems different than what I would expect:

Code: Select all


material test
{
	technique
	{
		pass
		{

			vertex_program_ref ET/Programs/VSLodMorph2
			{
			}

			fragment_program_ref ET/Programs/PSSplat2
			{
				param_named splatScaleX float4 20 0 0 0
				param_named splatScaleZ float4 20 0 0 0
			}

			texture_unit
			{
				texture test0 -1
			}

			texture_unit
			{
				texture test1 -1
			}

			texture_unit
			{
				texture splatting2.png -1
			}
		}

	}

}
The fragment program args went from float to float 4. Also, there are "-1" after the texture names. Has anybody else seen this?

KungFooMasta
Post Reply