New autoconstant request

What it says on the tin: a place to discuss proposed new features.
Post Reply
User avatar
Red5_StandingBy
Greenskin
Posts: 109
Joined: Mon Jun 26, 2006 1:06 pm
Location: Turkey

New autoconstant request

Post by Red5_StandingBy »

Hi,

Could we have two new GPU program autoconstants:

ACT_TEXTURE_VIEWPROJ_MATRIX_ARRAY,
ACT_TEXTURE_WORLDVIEWPROJ_MATRIX_ARRAY,

Setting them would be straightforward in OgreGPUProgram.cpp. Ex :

First:

Code: Select all

AutoConstantDefinition(ACT_TEXTURE_VIEWPROJ_MATRIX_ARRAY,       "texture_viewproj_matrix_array",     16, ET_REAL, ACDT_INT),
And then:

Code: Select all

case ACT_TEXTURE_VIEWPROJ_MATRIX_ARRAY:
 for (size_t l = 0; l < i->data; ++l)
 {
	_writeRawConstant(i->physicalIndex + l*i->elementCount, source->getTextureViewProjMatrix(l) );
 }
 break;
User avatar
Praetor
OGRE Retired Team Member
OGRE Retired Team Member
Posts: 3335
Joined: Tue Jun 21, 2005 8:26 pm
Location: Rochester, New York, US
x 3
Contact:

Post by Praetor »

These constants already exist for 1.5. They are called ACT_TEXTURE_VIEWPROJ_MATRIX and ACT_TEXTURE_WORLDVIEWPROJ_MATRIX. You'll have to grab HEAD to get them or wait for Shoggoth to hit release.
User avatar
Red5_StandingBy
Greenskin
Posts: 109
Joined: Mon Jun 26, 2006 1:06 pm
Location: Turkey

Post by Red5_StandingBy »

I need the array versions of these constants. We have a configurable shadow-casting light setup for material/shaders where we have loops for shadows. So, using ACT_TEXTURE_VIEWPROJ_MATRIX with light indices is not very flexible. Ex:

Code: Select all

Material:
param_named_auto lightShadowTransform texture_viewproj_matrix_array 4 


Pixel Shader:
...
static const int numLights = 4;
float4x4 lightShadowTransform[numLights];
...
for (i = 0; i < numLights; i ++)
 {          
       ...
       float4 shadowCoord = mul(lightShadowTransform[i], input.wPos);
 }
...
By the way, is there any way to define variables in material scripts. For the example above, I would like to define a variable as:

Code: Select all

#define NUM_LIGHTS 4
param_named_auto lightShadowTransform texture_viewproj_matrix_array NUM_LIGHTS
User avatar
xavier
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 9481
Joined: Fri Feb 18, 2005 2:03 am
Location: Dublin, CA, US
x 22

Post by xavier »

You can use whatever parameter you want with param_named. In fact, you can perform what you need without having to change Ogre at all to do it. You'll just have to do the updating of your custom parameters yourself, is all.
Do you need help? What have you tried?

Image

Angels can fly because they take themselves lightly.
User avatar
Red5_StandingBy
Greenskin
Posts: 109
Joined: Mon Jun 26, 2006 1:06 pm
Location: Turkey

Post by Red5_StandingBy »

Hi,

Yes, I do use param_named in other cases, but in this case the array of matrices are not custom, they are updated by Ogre and available as auto constants anyway. Only presentation in array form is missing and would be nice to have (maybe for other developers too).
User avatar
Praetor
OGRE Retired Team Member
OGRE Retired Team Member
Posts: 3335
Joined: Tue Jun 21, 2005 8:26 pm
Location: Rochester, New York, US
x 3
Contact:

Post by Praetor »

Define a variable just in the material scripts, or one which is also set in the shader? You can define a constant in some shader languages and Ogre can pass values into the preprocessor. If you want just variables in the material script itself, again, this is part of Shoggoth. If you get HEAD you'll need to make sure OGRE_USE_NEW_COMPILERS is set to 1 in OgreConfig.h. Then you can do something like this:

Code: Select all

set $NUM_LIGHTS 4

fragment_program ...{
    ...
    default_params{
        ...
        param_named_auto lightShadowTransform texture_viewproj_matrix_array $NUM_LIGHTS
    }
}
User avatar
sinbad
OGRE Retired Team Member
OGRE Retired Team Member
Posts: 19269
Joined: Sun Oct 06, 2002 11:19 pm
Location: Guernsey, Channel Islands
x 67
Contact:

Post by sinbad »

I'll add the 'array' variants to Shoggoth, they will just follow the same pattern as the light parameter variants.
User avatar
Red5_StandingBy
Greenskin
Posts: 109
Joined: Mon Jun 26, 2006 1:06 pm
Location: Turkey

Post by Red5_StandingBy »

@sinbad: Thanks a lot.

@Praetor: The "set" command is what I was looking for. Thanks for the info.
Post Reply