No announcement yet.

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

  • Filter
  • Time
  • Show
Clear All
new posts

    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.

    Note you don't need to include all the out arguments, just the mip. The rest are optional.
    Last edited by RyanB; 10-26-2016, 12:33 PM.
    Ryan Brucks
    Principal Technical Artist, Epic Games