Custom Node, for loop, read pixels of an input texture

Hi everyone,

I’m trying to write a “simple” cel shaded material. I’m struggling with the possibility of having a varying number of lights that all work with the material.

The best thing I came up with until now is creating a Custom Node that takes the VertexNormalWS, the 1D texture with the cel shade’s gradient and a texture that contains in its pixels the data of the lights that I have in the scene and does his things in a for loop (for every light I have) and outputs a sort of a lightmap.

The texture with the lights data is generated in real time and is 2 x nLights pixels and contains in his pixels every lights’ direction and color.
**
Actually my problem is that I can’t figure out how to read the texture’s dimensions and the single pixel value inside my custom node.**

Maybe this is a dumb question but I never programmed a custom node. If you came up with a simpler way to do this thing, like putting in my material editor directly an array with that data would be awesome.

You can use the Texture Property node to get the dimensions. I think it also has texelsize which is just 1/dimensions.

You can turn off texture filtering to guarantee you are reading exact texel without blending.

Also look at the material function ‘1d to 2d index’ for tips on how you can convert between spaces which might be useful since you will likely end up laying out your texels in a 2d grid.

The texture property node won’t work with texture parameters at least last time I checked. For that you can use the hlsl GetDimensions function but be aware it costs like doing a sample.

https://msdn.microsoft.com/en-us/library/windows/desktop/bb509693%28v=vs.85%29.aspx

Note you don’t need to include all the out arguments, just the mip. The rest are optional.

1 Like