On 04/12/2014 at 07:49, xxxxxxxx wrote:
User Information:
Cinema 4D Version: R12+
Platform: Windows ;
Language(s) : C++ ;
---------
Hello,
currently I'm working on a channel shader plugin that will do some fancy tiling stuff internally.
And that even works so far, at least regarding to the final rendering.
But unfortunately it's dependent on the right tiling settings in the texture tag.
And that have to be fixed.
The shader output itself should be treated like a single texture without touching the shader internal tiling at all and the texture tag tiling settings should only affect the texture tag tiling alone if the "Tiles U/V" and "Repetitions U/V" settings are used for some additional tiling.
But first of all I mainly have some trouble with the different previews (editor preview, shader preview, channel preview).
To illustrate my problems I made a very simplified demo shader and did some screenshots.
First the code:
//////////////////////////////////////////////////////////////
// CINEMA 4D Tile Shader Test //
//////////////////////////////////////////////////////////////
// (c) 2014 Thomas Chen, all rights reserved //
//////////////////////////////////////////////////////////////
// tileshadertest.cpp //
//////////////////////////////////////////////////////////////
// example for a channel shader with access to basechannel
// using standard GUI elements
#include "c4d.h"
#include "c4d_symbols.h"
#include "xtileshadertest.h"
// be sure to use a unique ID obtained from www.plugincafe.com
#define ID_TILESHADERTEST 1000010 //Plugin IDs 1000001-1000010 are reserved for development!
class BitmapData : public ShaderData
{
public:
// NodeData
virtual Bool Init(GeListNode *node);
virtual Bool Read(GeListNode *node, HyperFile *hf, LONG level);
virtual Bool Message(GeListNode *node, LONG type, void *data);
// ShaderData
virtual INITRENDERRESULT InitRender(BaseShader *chn, const InitRenderStruct &irs);
virtual void FreeRender(BaseShader *chn);
virtual Vector Output(BaseShader *chn, ChannelData *cd);
static NodeData *Alloc(void) { return gNew BitmapData; }
private:
LONG tiles;
BaseShader *texture;
};
Bool BitmapData::Init(GeListNode *node)
{
BaseContainer *data = ((BaseShader* )node)->GetDataInstance();
data->SetLong(TILESHADERTEST_TILES, 1);
data->SetLink(TILESHADERTEST_TEXTURE, NULL);
return TRUE;
}
Bool BitmapData::Read(GeListNode *node, HyperFile *hf, LONG level)
{
// GePrint("HyperFile Version: " + RealToString(hf->GetFileVersion()));
if (hf->GetFileVersion() < 8300)
{
if (!hf->ReadChannelConvert(node, TILESHADERTEST_TEXTURE)) return FALSE; // convert old basechannel
}
return TRUE;
}
Bool BitmapData::Message(GeListNode *node, LONG type, void *msgdat)
{
BaseContainer *data = ((BaseShader* )node)->GetDataInstance();
HandleInitialChannel(node, TILESHADERTEST_TEXTURE, type, msgdat);
HandleShaderMessage(node, (BaseShader* )data->GetLink(TILESHADERTEST_TEXTURE, node->GetDocument(), Xbase), type, msgdat);
return TRUE;
}
INITRENDERRESULT BitmapData::InitRender(BaseShader *chn, const InitRenderStruct &irs)
{
BaseContainer *data = chn->GetDataInstance();
// cache values for fast access
tiles = data->GetLong(TILESHADERTEST_TILES);
texture = (BaseShader* )data->GetLink(TILESHADERTEST_TEXTURE, irs.doc, Xbase);
if (texture)
{
texture->InitRender(irs);
}
return INITRENDERRESULT_OK;
}
void BitmapData::FreeRender(BaseShader *chn)
{
if (texture)
{
texture->FreeRender();
}
texture = NULL;
}
Vector BitmapData::Output(BaseShader *chn, ChannelData *cd)
{
cd->p.x = cd->p.x * tiles;
cd->p.y = cd->p.y * tiles;
Vector col = 0.0;
if (texture)
{
col = texture->Sample(cd);
}
return col;
}
Bool RegisterTileShaderTest(void)
{
return RegisterShaderPlugin(ID_TILESHADERTEST, GeLoadString(IDS_TILESHADERTEST), 0, BitmapData::Alloc, "Xtileshadertest", 0);
}
And now the screenshots:
(What I termed here as small shader preview I would also call the channel preview.)
And some more pictures to compare the previews and the render with different settings for the tiling and seamless mirroring in the texture tag attributes.
Klick on the small pictures to show them in full size.
1. (default)
Tile = on
Seamless = off
Shader internal tiling = 2 x 2
Teture Tag tiling = 1 x 1
Here the rendering is correct but the bigger shader preview and the editor preview have a mirrored tiling and the smaller channel preview has no tiling at all.
2. (here "Seamless" is also switched on)
Tile = on
Seamless = on
Shader internal tiling = 2 x 2
Teture Tag tiling = 1 x 1
With seamless on my shader output also get a mirrored tiling (but it shouldn't).
3. (here "Tile" is switched off)
Tile = off
Seamless = NA (it is switched off here but the state is not important at all without "Tile")
Shader internal tiling = 2 x 2
Teture Tag tiling = 1 x 1
Now the rendert shader lacks in tiling (it is not supposed to do so by what I want to achieve either) but the previews are still the same like always.
4. (now with some additional tiling from the texture tag settings)
Tile = on
Seamless = off
Shader internal tiling = 2 x 2
Teture Tag tiling = 2 x 2
5. (same as before but "Seamless" is activated too)
Tile = on
Seamless = on
Shader internal tiling = 2 x 2
Teture Tag tiling = 2 x 2
And here is how I'd want it to be in this case:
Tile = off
Seamless = NA (same as at 3. )
Shader internal tiling = 2 x 2
Teture Tag tiling = 2 x 2
This is what I get now and here comes what I want to have in this case:
(only shader output related here, the previews are of course also not what they should be here)
Ignore the "Tile" and "Repetitions U/V" settings here in the texture tag attributes.
They are just a quick workaround to force the desired result for the settings above!
I guess all of this have to do with the TexData and/or ChannelData texflags: TEX_TILE and ``TEX_MIRROR
.
And I probably have to use the CALC_TEXINFO function somehow to make it work.
But I couldn't figure out how exactly that have to be done.
And the available informations about that toppic are very rare (or very hard to find).
What I found in the SDK docu and the "c4d_shader.h" doesn't help me too much.
And the best finds I had in this forum are on the one hand:
https://plugincafe.maxon.net/topic/8270/10779_custom-materialdata-uv--parameter-bugs-solved&PID=42600#42600
And on the other a very old post related to the C4D R8.5 SDK:
https://plugincafe.maxon.net/topic/1582/924_85-sdk
So any concrete help here is highly appreciated!
Kind regards,
Tom