Hey Guys,
Somehow I’m unable to use the SDK forum so I’m quickly putting it here in public.
Probably picked up the wrong account or something.
Anyway…
I’m trying to create my own shader that samples an image at a specified UV point and figured I needed to use the bitmap interface.
But it keeps on crashing on me and I don’t really understand why. I took most of the source code from the bitmap example and the checker.
Here’s my code:
//**************************************************
// File: tex_AColor.cpp
// Description: this file is an implementation of a simple AColor texture for VRay
// Notes: used when exporting data - to do a conversion from AColor to Texture.
// it can also work with textures as input and will leave them unchanged.
// (file created from tex_invert.cpp)
//**************************************************
#include "vrayplugins.h"
#include "vrayinterface.h"
#include "vrayrenderer.h"
#include "vraytexutils.h"
#include <math.h>
#include "globalnewdelete.cpp"
using namespace VR;
// Parameters
struct SphereMapTex_Params: VRayParameterListDesc {
SphereMapTex_Params(void) {
// Add the parameters
addParamPlugin("uvwgen", EXT_UVWGEN);
//addParamTexture("texture");
addParamTexture("bitmap", EXT_BITMAP);
}
};
struct SphereMapTex: VRayTexture, RTTexInterface {
SphereMapTex(VRayPluginDesc *pluginDesc):VRayTexture(pluginDesc) {
// Set parameter caches
paramList->setParamCache("uvwgen", &uvwgen_plugin);
paramList->setParamCache("bitmap", &bitmap_plugin);
//paramList->setParamCache("texture", &texture);
}
void renderBegin(VR::VRayRenderer *vray);
void renderEnd(VR::VRayRenderer *vray);
void frameBegin(VR::VRayRenderer *vray);
void frameEnd(VR::VRayRenderer *vray);
AColor getTexColor(const VRayContext &rc);
void getTexColorBounds(AColor &cmin, AColor &cmax);
Vector getColorBumpGradient(const VRayContext &rc);
private:
// Cached parameters
PluginBase* uvwgen_plugin;
UVWGenInterface* uvwgen;
//TextureInterface *texture;
PluginBase* bitmap_plugin;
BitmapInterface *bitmap;
BitmapInterface2 *bitmap2;
// The color cache
ShadeCache<AColor, true, false> shadeCache;
public:
// From RTTexInterface
PluginBase* getPlugin(void) { return this; }
int getDataSize(void) { return 0; }
void getData(float *fdata) { }
PluginInterface *newInterface( InterfaceID id ) {
if (EXT_RTTEX==id) return static_cast<PluginInterface*>( (RTTexInterface*)this );
return VRayTexture::newInterface(id);
}
virtual int getSource(const char *part,const char *outParam,const char *lang,VUtils::ShaderSource &shaderSrc, OCLData &mtlData)
{
return 0;
}
};
#define SphereMapTex_PluginID PluginID(LARGE_CONST(20141228000))
SIMPLE_PLUGIN_LIBRARY(SphereMapTex_PluginID, EXT_TEXTURE, "SphereMapTex", "SphereMap texture for VRay", SphereMapTex, SphereMapTex_Params);
void SphereMapTex::renderBegin(VR::VRayRenderer *vray) {
VRayTexture::renderBegin(vray);
shadeCache.renderBegin(vray);
}
void SphereMapTex::renderEnd(VR::VRayRenderer *vray) {
VRayTexture::renderEnd(vray);
shadeCache.renderEnd(vray);
}
void SphereMapTex::frameBegin(VR::VRayRenderer *vray) {
// Call the base class to update the parameter caches
VRayTexture::frameBegin(vray);
// Call frameBegin on the shade cache
shadeCache.frameBegin(vray);
// Get the uvw gen
uvwgen=(UVWGenInterface*) GET_INTERFACE(uvwgen_plugin, EXT_UVWGEN);
// Get bitmap data
bitmap=(BitmapInterface*) GET_INTERFACE(bitmap_plugin, EXT_BITMAP);
bitmap2=static_cast<BitmapInterface2*>(GET_INTERFACE(bitmap_plugin, EXT_BITMAP2));
const VRaySequenceData &sdata=vray->getSequenceData();
if (!bitmap && sdata.progress) sdata.progress->warning("[TexBitmap] No bitmap buffer specified.\n");
}
void SphereMapTex::frameEnd(VR::VRayRenderer *vray) {
VRayTexture::frameEnd(vray);
shadeCache.frameEnd(vray);
}
AColor SphereMapTex::getTexColor(const VRayContext &rc) {
if (!bitmap) return AColor(0.5, 0.5, 0.5, 1.0);
double u = 0.5;
double v = 0.5;
//return AColor(1.0, 0.0, 0.0, 1.0); // test with red (keeping this avoids the crash and render it red as expected)
// !!!!!!!!!!!!!!!!!!!!!CRASH!!!!!!!!!!!!!!!!!!
bitmap->getInterpolatedColor(Vector2(u, v), 1); // THIS LINE CRASHES MAYA & RENDERER
}
void SphereMapTex::getTexColorBounds(AColor &cmin, AColor &cmax) {
//if (texture==NULL) cmin=cmax=AColor(0.5f, 0.5f, 0.5f, 1.0f);
//else texture->getTexColorBounds(cmin, cmax);
if (!bitmap) return;
bitmap->getColorBounds(cmin, cmax);
}
Vector SphereMapTex::getColorBumpGradient(const VRayContext &rc) {
return Vector(0.0f, 0.0f, 0.0f);
//if (texture==NULL) return Vector(0.0f, 0.0f, 0.0f);
//return texture->getColorBumpGradient(rc);
}
Any help is greatly appreciated! ![]()
Cheers,
Roy