Arnold Texture/Utility Shader to create a custom procedural grid?

Arnold Texture/Utility Shader to create a custom procedural grid?

war72
Participant Participant
921 Views
13 Replies
Message 1 of 14

Arnold Texture/Utility Shader to create a custom procedural grid?

war72
Participant
Participant

Is it possible to manipulate any of the native Arnold texture/utility nodes to create a procedural grid where the line thickness and spacing can be customized? 

download.png

 

I found an OSL shader that could do this, though I'm hoping for a simpler way to quickly generate this on the fly. 

0 Likes
Accepted solutions (1)
922 Views
13 Replies
Replies (13)
Message 2 of 14

war72
Participant
Participant

Any thoughts? Might this question be better answered in another thread? Thanks!

0 Likes
Message 3 of 14

madsd
Advisor
Advisor

OSL was born for this kinda job, what prevents you from using the version you found?

0 Likes
Message 4 of 14

lee_griggs
Autodesk
Autodesk

You could use a wireframe shader (set to polygons). Subdivide the model if you want more grid lines.

 

lee_griggs_0-1660109208592.png

 

Lee Griggs
Arnold rendering specialist
AUTODESK
0 Likes
Message 5 of 14

war72
Participant
Participant

Thanks Lee - I considered this but I'm looking to create a map that will serve as an opacity cutout for a window screen (very small-scale grid across several windows in the scene). Creating that many subdivisions would not be optimal.  

0 Likes
Message 6 of 14

war72
Participant
Participant

This is the OSL material I have been trying attempting to use:

 

/*
  Grid Lines
  : Author Dealga McArdle, 2013
  : modified from Sine Stripes by Thomas Dinges
  example shaders:
  http://www.openshading.com/osl/example-shaders/

*/

#include "stdosl.h"

shader GridShaderUV(

    // input and output parameters
    vector Vector = P,
    color GridColor = color(0.8),
    float Intensity = 1.0,
    float Distance_U = 0.02,
    float Distance_V = 0.02,
    int Stripes_U = 10,
    int Stripes_V = 10,
    output float Fac = 1.0,
    output color Color = color(0.8),
    float World_X = 1.0,
    float World_Y = 1.0
    )
{

    // shader code
    point Pos = Vector;
    Pos[0] -= World_X;
    float pattern_col = 0.0;

    for(int i = 0; i < Stripes_U; ++i ) {
        Pos[0] += Distance_U;
        pattern_col += abs(Intensity / Pos[0] / 1000.0);
    }

    Pos = Vector;
    Pos[1] -= World_Y;
    for(int i = 0; i < Stripes_V; ++i ) {
        Pos[1] += Distance_V;
        pattern_col += abs(Intensity / Pos[1] / 1000.0);
    }

    color C = transformc("hsv", GridColor);

    Fac = pattern_col;
    Color = color("hsv", C[0], C[1], (Fac*C[2]));
}

After some more messing around I think I was able to solve the issue I was having - thanks all! 

0 Likes
Message 7 of 14

war72
Participant
Participant

So I'm still having one issue - I set up my OSL shader to create a grid on this plane, which works great:

Screeen_DefaultPos.jpg

 

but as soon as I move the plane, it's as though the OSL shader is locked in world space, and does not move with the object:

Screen_Moved.jpg

 

Is there a way to lock the OSL texture to the object instead of phasing behind it in world space? I've attached a very simple scene file that shows this. 

0 Likes
Message 8 of 14

peter_horvath
Autodesk
Autodesk
Accepted solution

You can read the object space shading point (Po) via a state_vector shader and connect it to the Vector input of the osl shader.


// Peter Horvath
// C4DtoA developer
0 Likes
Message 9 of 14

war72
Participant
Participant

My heroes - thanks all!

0 Likes
Message 10 of 14

madsd
Advisor
Advisor

If you change line 15 to:

vector Vector = transform("object",P),

You will locked the position to object space.

One thing to note, the data set is not signed, so you are dealing with compressed gradients, this is why the construct "glows" when you have a lot of lines in a dense area, that is not going to make a clean alpha, a hard cut.

I don't know if this is fine, but it can be fixed as well

0 Likes
Message 11 of 14

darioOrtisi
Collaborator
Collaborator

Hi everyone. I have some problem with this osl shader. When i change parameters maya Hard crash. Is there any stable version? Maya 2025 MtoA 5.4.8

0 Likes
Message 12 of 14

maxtarpini
Collaborator
Collaborator
Message 13 of 14

darioOrtisi
Collaborator
Collaborator

Wow Max. Thank you very much. Very stable.

Message 14 of 14

wernienst
Collaborator
Collaborator

Here is another attempt using Arnold shaders only (I'm using 3ds max):

Create a Ramp Float map, Type: u, Interpolation: Constant. Add 2 points. Set values as follows:

Point Nr     Position     Value

0                  0.0              0.0

1                   0.05            1.0

2                   0.95            0.0

3                   1.0               1.0

wernienst_0-1750968981955.png

Make a copy and set its Type to v. Wire both to a Multiply node and this to a UV Transform node's Passthrough input.

Set Transform/Repeat to your liking, and finally wire its output to your Material channel of choice.

wernienst_1-1750969324134.png

By carefully setting Ramp points you can create grids like this:

wernienst_2-1750969490367.png