Simple square OSL shader help !

Sub forum for help and tutorials.

Moderators: ChrisHekman, aoktar

Post Reply
User avatar
pxlntwrk
Licensed Customer
Posts: 445
Joined: Sat Mar 23, 2013 2:21 pm
Location: France
Contact:

Hello I would like to draw a simple square with the language osl.
I found this piece of code (source: http://www.fundza.com/rfm/osl/repeats/index.html)

Code: Select all

// Returns a value in the range 0 to 1.
// 0 indicates the x,y point is outside the square, and
// 1 indicates the x,y point is fully within the squere. 
float pntInSquare(float x,
                  float y,
                  float x_center,
                  float y_center,
                  float x_width,
                  float y_width,
                  float blur)
{
float minx = x_center - x_width/2;
float maxx = x_center + x_width/2;
float miny = y_center - y_width/2;
float maxy = y_center + y_width/2;
  
return smoothstep(minx, minx + blur, x) * (1 - smoothstep(maxx, maxx + blur, x)) *
       smoothstep(miny, miny + blur, y) * (1 - smoothstep(maxy, maxy + blur, y));
}
//----------------------------------------------------        
shader 
square(float   s_center = 0.5, 
       float   t_center = 0.5,
       float   s_width = 0.4, 
       float   t_width = 0.4,
       float   blur = 0.01,
       color   bakcolor = 1,
       color   patcolor = 0,
       float   s = 0 [[int lockgeom = 0]],
       float   t = 0 [[int lockgeom = 0]],
    output color resultRGB = 0)
{
float blend = pntInSquare(s, t, s_center, t_center, s_width, t_width, blur);
resultRGB = mix(bakcolor, patcolor, blend);
}
but I can't get it to work with Octane.
Could someone guide me on what needs to change for Octane to make it work.
Many thanks in advance
:::::::::::::::::
pxlntwrk.net
User avatar
aoktar
Octane Plugin Developer
Posts: 16066
Joined: Tue Mar 23, 2010 8:28 pm
Location: Türkiye
Contact:

You wish math help not octane. Take a look to presets. For example grid1.osl, you can obtain a square with that.
Octane For Cinema 4D developer / 3d generalist

3930k / 16gb / 780ti + 1070/1080 / psu 1600w / numerous hw
User avatar
pxlntwrk
Licensed Customer
Posts: 445
Joined: Sat Mar 23, 2013 2:21 pm
Location: France
Contact:

aoktar wrote:You wish math help not octane. .
yes i agree with that!
aoktar wrote:Take a look to presets. For example grid1.osl.
yes , you are right again,
my problem with grid1.osl is that once configured, when i change projection for perspective for example, the square becomes a grid again,
so how to restrict repetition?

Image
:::::::::::::::::
pxlntwrk.net
User avatar
aoktar
Octane Plugin Developer
Posts: 16066
Joined: Tue Mar 23, 2010 8:28 pm
Location: Türkiye
Contact:

This script may be hard to manage, I can give very simple one if your need is just to draw a simple grid.
Octane For Cinema 4D developer / 3d generalist

3930k / 16gb / 780ti + 1070/1080 / psu 1600w / numerous hw
User avatar
pxlntwrk
Licensed Customer
Posts: 445
Joined: Sat Mar 23, 2013 2:21 pm
Location: France
Contact:

aoktar wrote:This script may be hard to manage, I can give very simple one if your need is just to draw a simple grid.
If you have time, that would be really nice!
just one square :D

thanks
:::::::::::::::::
pxlntwrk.net
Post Reply

Return to “Help / Tutorials”