On 16/12/2014 at 00:43, xxxxxxxx wrote:
Hi,
this topic is also somehow related to another one by me in the C++ section of this forum:
Custom Tile Shader problem with previews
I tried to translate my test shader that you can find in the link above to Python.
Just because it makes prototyping such stuff more comfortable that you can simply reload registered Python plugins in C4D after source code changes.
But unfortunately I run into a problem here too.
Any manipulations I try to make to "cd.p" are ignored.
Here is the source code:
#############################################################
## CINEMA 4D Python Tile Shader Test ##
#############################################################
## by Thomas Chen (2014) ##
#############################################################
## Py-TileShaderTest.pyp ##
#############################################################
import c4d
from c4d import plugins
#warning Please obtain your own plugin ID from http://www.plugincafe.com
PLUGIN_ID = 1000010
class TileShaderTest(plugins.ShaderData) :
tiles = 1
texture = None
def __init__(self) :
#if a Python exception occurs during the calculation
#of a pixel colorize this one in red for debugging purposes
self.SetExceptionColor(c4d.Vector(1.0, 0.0, 0.0))
def Init(self, node) :
#Called when a new instance of the node plugin has been allocated.
node[c4d.TILESHADERTEST_TILES] = self.tiles
node[c4d.TILESHADERTEST_TEXTURE] = self.texture
return True
def InitRender(self, sh, irs) :
#Precalculate any data for rendering.
self.tiles = sh[c4d.TILESHADERTEST_TILES]
self.texture = sh[c4d.TILESHADERTEST_TEXTURE]
if self.texture:
self.texture.InitRender(irs)
return 0
def FreeRender(self, sh) :
#Free any resources used for the precalculated data from InitRender()
if (self.texture) :
self.texture.FreeRender()
self.texture = None
def Output(self, sh, cd) :
#Called for each point of the visible surface of a shaded object. Here you should calculate and return the channel color for the point cd.p.
cd.p.x = cd.p.x * self.tiles
cd.p.y = cd.p.y * self.tiles
col = c4d.Vector(0.0, 0.0, 0.0)
if self.texture:
col = self.texture.Sample(cd)
return col
def RegisterTileShaderTest() :
return plugins.RegisterShaderPlugin(PLUGIN_ID, "Py-TileShaderTest", 0, TileShaderTest, "xtileshadertest", 0)
if __name__ == '__main__':
RegisterTileShaderTest()
That seams to have no effect at all:
cd.p.x = cd.p.x \* self.tiles
cd.p.y = cd.p.y \* self.tiles
I also tried to hardcode different values for "tiles" and to assign different formulas and hardcoded values to "cd.p" too.
The output is always the complete texture at the whole uv area when I return:
self.texture.Sample(cd)
Any idea what I miss here?
Kind regards,
Tom