Hello there,
I've taken my first leap into the C++ SDK and experienced some early triumphs and defeats. I'm working slowly on a shader starting from the Xbitmapdistortion SDK example. I have the SDK documentation open in about 20 tabs but still feel unsure about how I'm approaching what I'd like to accomplish.
I'm hoping to write a bare bones Ptex shader. I don't need to deal with most of the issues that surround Ptex as my only goal is to get a shader that I can bake into UDIMs I figured I'd start the effort by generating per-polygon UV coordinates. It took me a while but I came up with a working solution which exists mostly in the Output method of my young shader:
Vector PtexData::Output(BaseShader* chn, ChannelData* cd)
{
if (cd->vd == nullptr) // It took me a while to realize I needed this here :)
return Vector(0.0);
RayPolyWeight weight;
RayHitID hit = cd->vd->lhit;
Int32 faceid = hit.GetPolygon();
/* I'm not currently using the faceid, but I will need it to index into the sub-images
of the Ptex file; is this a bad idea? Is there another way?*/
cd->vd->GetWeights(hit, cd->vd->p, &weight);
Vector coord = Vector(weight.wa + weight.wb, weight.wb + weight.wc, 0.0);
return coord;
}
So first off I suppose I'm wondering: have I done anything horribly wrong or inefficient in the above code? That leads me to my next question: what is the best practice for loading an external texture (in this case Ptex)? I was not planning to build a Ptex file handler but instead to 'brute force' this and load the required Ptex images into a PtexCache in my InitRender() and use Ptex's getPixel() method to 'sample' directly using the coordinates I've generated. I have several concerns with this approach (do I need to consider MIP levels? even if my only goal is to bake the shader?). Unfortunately I don't even know enough to know whether they're valid concerns or not
Does anyone have a suggestion for an acceptable (not necessarily best) approach for doing this?
Finally, could anyone recommend additional avenues for getting up to speed on modern C++ more generally (this is the first time I've touched C++ since 2001) and the Cinema 4D SDK in particular?