QUOTE(oweber @ 04/29/08, 12:15 PM) [snapback]284880[/snapback]
Should I derive from MPxHwShaderNode? Remember that is some sort of a deformer and not regular pixel shader.
Also, MPxHwShaderNode uses vertex arrays which I wants to avoid.
MPxHardwareShader might be a better option.
QUOTE
I want to use vbo's since performance is paramount.
If rendering speed is paramount, then your best bet is to simply not use maya. If you want a well designed and efficient framework for computation, then write a node in the DG.
QUOTE(oweber @ 04/29/08, 12:15 PM) [snapback]284880[/snapback]
The VBO's should reside in Graphics card memory. Where is the right place to allocate the memory and keep the pointers?
Where maya puts it's rendering data is up to maya, not you. Manually keeping track of vbo's for each geometry object that has the shader applied sounds like a very bad idea. MPxHardwareShader::populateRequirements() would probably be a better idea. Not sure about how that works in practice though, not played around with it.
QUOTE(oweber @ 04/29/08, 12:15 PM) [snapback]284880[/snapback]
The HW shader has two tasks. One is to actualy render the deformed surface...
should be trivial. MPxHwShaderNode or MPxHardwareShader....
QUOTE(oweber @ 04/29/08, 12:15 PM) [snapback]284880[/snapback]
and the second is to compute the new vertices locations (deformation). The second task should be performed only when the cage vertices are manipolated.
then don't use a vertex shader for it. If you want it to work well with the maya api, do it in software within the compute function of a poly modifier node. You could use cuda to do that, but that sounds a bit like a bull in a china shop to me.
QUOTE
I need to create a trigger between the manipolation of the cage vertices and the computation of the new vertex locations. How this should be done? Should I use comute() / geometry() or something else?
That's what the compute function does already.
QUOTE
Can someone point me to an example of implementing HW deformers?
Maya's twist deformer as a vertex shader.....
CODE
//-------------------------------------------------------------------------
// Effect Region and Amount parameters
//-------------------------------------------------------------------------
uniform float gNLT_Envelope; ///describes the amount of effect the deformation has
uniform float gNLT_LowBound; ///describes how low in Y the effect has influence
uniform float gNLT_HighBound; ///describes how high in Y the effect has influence
//-------------------------------------------------------------------------
// Effect Region and Amount parameters
//-------------------------------------------------------------------------
uniform float gNLT_StartAngle; /// start angle of twist
uniform float gNLT_EndAngle; /// end angle of twist
//-------------------------------------------------------------------------
// transforms to move point into local space of deformer and back
//-------------------------------------------------------------------------
uniform mat4 gNLT_GeomToDeformerSpace;
uniform mat4 gNLT_DeformerToGeomSpace;
//-------------------------------------------------------------------------
// useful consts
//-------------------------------------------------------------------------
const float effect_range = gNLT_HighBound - gNLT_LowBound;
//-------------------------------------------------------------------------
/// \brief computes a non linear twist deformation
/// \param position - the input and output vertex position
/// \param normal - the input and output normal values.
///
void calcNonLinearTwist(inout vec4 position,inout vec3 normal)
{
position = gNLT_GeomToDeformerSpace * position;
//
// if outside of the deformed region... ignore
//
if( position.y > gNLT_HighBound ||
position.y < gNLT_LowBound )
{
}
else
if(gNLT_Envelope>0.001)
{
//
// find the Y position based on it's distance from low band in the range of 0 to 1
//
float scaled_height = (position.y-gNLT_HighBound) /
effect_range;
//
// determine twist amount based on height
//
float twist_amount = gNLT_StartAngle + scaled_height*effect_range;
//
// take since and cosine of twist amount
//
float ca = cos( twist_amount );
float sa = sin( twist_amount );
//
// compute deformation matrix
//
mat4 m = mat4( ca, 0.0, -sa, 0.0,
0.0, 1.0, 0.0, 0.0,
sa, 0.0, ca, 0.0,
0.0, 0.0, 0.0, 1.0);
//
// transform the normal and position
//
position = (m * position);
normal = vec3(m*vec4(normal,0));
}
position = gNLT_DeformerToGeomSpace * position;
}
void calcFinalLighting(in vec3 normal)
{
vec3 lightDir;
vec4 diffuse;
float NdotL;
lightDir = normalize(vec3(gl_LightSource[0].position));
NdotL = max(dot(normal, lightDir), 0.0);
diffuse = gl_FrontMaterial.diffuse * gl_LightSource[0].diffuse;
gl_FrontColor = NdotL * diffuse;
}
void main()
{
vec4 pos = gl_Vertex;
vec3 normal = gl_Normal;
calcNonLinearTwist(pos,normal);
normal = normalize(gl_NormalMatrix * normal);
gl_Position = gl_ModelViewProjectionMatrix * pos;
calcFinalLighting(normal);
}
QUOTE
Can someone point me to an example of Maya plugin that uses CUDA?
you'll probably have to write one before i could point you to one.
QUOTE
1) I know that I am allowed to call opengl / Cuda from MPxHwShaderNode::geometry but is it allowed from compute or anywhere else?
Not really, you have no guarentee that you even have an openGL context. (since it could be rendering or running in batch mode).
QUOTE
2) I want to trigger the compute method whever the controll mesh geometry is changing. The control mesh worldMesh[0] attribute is connected to a custom input attribute in the the MPxHwShaderNode node but in fact it is not true that this attribute has influence on the output color of the MPxHwShaderNode node. How can I trigger the compute without the hack of setting attributeAffects(inputAttribute, outColor)?
sounds like a poly modifier node is required?