From: Open Shading Language — OSL

Tiles Texture

This texture allows to create tiles with a joint.

Square version

Code

tiles_basic.osl
// Licenses: GNU GENERAL PUBLIC LICENSE Version 3 (GNU GPLv3) and GNU GENERAL PUBLIC LICENSE Version 2 (GNU GPLv2)
// author: Olivier Vandecasteele
// web site: http://www.ngon-paradise.com/wiki/
 
shader tiles_basic(
    vector Coordinates = 0,
    color Color1 = 1,
    color Color2 = 0,
    float Scale = 5.0,
    float Joint = 0.1,
    output color Color = 0)
{
    Color=Color2;
    if ( abs(0.5-mod(Coordinates[0]*Scale,1.))<((1.-Joint)/2.) & abs(0.5-mod(Coordinates[1]*Scale,1.))<((1.-Joint)/2.) )
        {Color=Color1;}
}

Download

Clic on the name of the shader in the code section to download it.

Licenses

This software is an OSL shader published under the double license:

Extract of the GNU GPLv3 licence:

tiles_basic.osl is a shader OSL
Copyright (C) 2013  Vandecasteele Olivier D. V.

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as
published by the Free Software Foundation, either version 3 of
the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty
of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.

Examples with nodes

By default, this shader products regular tiles:

With a noise in the parameter Joint you obtain more irregular tiles:
osl-tiles-advanced2.q85.jpg

With the same principle, you can obtain damaged and dirty tiles:

Rounded corners version

This version add the ability to round the corners.

Code Source

tiles_roundedcorners.osl
// Licenses: GNU GENERAL PUBLIC LICENSE Version 3 (GNU GPLv3) and GNU GENERAL PUBLIC LICENSE Version 2 (GNU GPLv2)
// author: Olivier Vandecasteele
// web site: http://www.ngon-paradise.com/wiki/
 
shader tiles_roundedcorners(
    vector Coordinates = 0,
    color Color1 = 1,
    color Color2 = 0,
    float Scale = 2.0,
    float Joint = 0.05,
    float Corners = 0.5,
    int Rounded = 0,
    output color Color = 0)
{
    Color=Color2;
    float width=1.-Joint;
    float cu=mod(Coordinates[0]*Scale,1.);
    float cv=mod(Coordinates[1]*Scale,1.);
    float co=Corners*width; // corner is relative, co is absolute
    if ( abs(0.5-cu)<(width/2.) & abs(0.5-cv)<(width/2.) ) {
        if ( abs(0.5-cu)<((width-co)/2.) | abs(0.5-cv)<((width-co)/2.) ) { Color=Color1; }
        else {
            if ( Rounded==1 | Rounded==2 ) {
                float djo=Joint/2.;
                float dco=co/2.;
                float pu, pv;
                if (cu<.5) { if (cv>.5) { cv=1.-cv; } } else { if (cv<.5) { cu=1.-cu; } else { cu=1.-cu; cv=1.-cv; } } // changing the coordinates is easier than to calculate the 4 corners separately
                if (Rounded==1) { pu=(cu-djo)/dco; pv=(cv-djo)/dco; if ( pu<(1.-pv) ) { Color=Color2; } else { Color=Color1; } }
                if (Rounded==2) { pu=(cu-djo-dco)/(-dco); pv=(cv-djo-dco)/(-dco); if ( acos(pu)<asin(pv) ) { Color=Color2; } else { Color=Color1; } }
                }
            else { Color=Color1; }
            }
    }
}

Download

Clic on the name of the shader in the code section to download it.

Licenses

This software is an OSL shader published under the double license:

Extract of the GNU GPLv3 licence:

tiles_roundedcorners.osl is a shader OSL
Copyright (C) 2013  Vandecasteele Olivier D. V.

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as
published by the Free Software Foundation, either version 3 of
the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty
of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.

Examples with nodes

Rounded corners (Rounded = 2):

Beveled corners (Rounded = 1):

prog/osl/osl-tiles-texture-en.txt · Last modified: 2013/07/20 20:22 by arketip
 
PDF Export Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki