Community
Arnold for Cinema 4D Forum
Rendering with Arnold in CINEMA 4D using the C4DtoA plug-in.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

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

9 REPLIES 9
SOLVED
Reply
Message 1 of 10
war72
268 Views, 9 Replies

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

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. 

9 REPLIES 9
Message 2 of 10
war72
in reply to: war72

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

Message 3 of 10
madsd
in reply to: war72

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

Message 4 of 10
lee_griggs
in reply to: war72

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
Message 5 of 10
war72
in reply to: lee_griggs

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.  

Message 6 of 10
war72
in reply to: madsd

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! 

Message 7 of 10
war72
in reply to: war72

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. 

Message 8 of 10
peter_horvath
in reply to: war72

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
Message 9 of 10
war72
in reply to: peter_horvath

My heroes - thanks all!

Message 10 of 10
madsd
in reply to: war72

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

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report