Permalink
Browse files

Some non-photoreal shaders

  • Loading branch information...
Zap Andersson
Zap Andersson committed Sep 19, 2018
1 parent 019c709 commit 61b0e7647b3fee5473eabab88ccf6d981557c631
@@ -0,0 +1,35 @@
// A simple Halftone shader
// Halftone.osl, by Zap Andersson
// Modified: 2018-06-28
// Copyright 2018 Autodesk Inc, All rights reserved. This file is licensed under Apache 2.0 license
// https://github.com/ADN-DevTech/3dsMax-OSL-Shaders/blob/master/LICENSE.txt
shader HalftoneDots
[[ string help="Halftone Dots" ]]
(
// Inputs
vector UVW = transform("raster", P),
vector Scale = vector(8.0,8.0,8.0),
float Angle = 45.0,
color InputValue = 0.5,
float Fuzz = 0.1 [[ float min = 0.0, float max = 2.0 ]],
color BlackDots = 0.0,
color WhiteDots = 1.0,
// Outputs
output color Out = 0.0
)
{
vector pos = rotate(UVW, radians(Angle), 0.0, vector(0.0,0.0,1.0));
pos = vector(pos[0] / Scale[0], pos[1] / Scale[1], 0.0);
if (Scale[0] == 0.0)
pos[0] = 0.5;
if (Scale[1] == 0.0)
pos[1] = 0.5;
pos = pos - floor(pos);
float dist = 1.0 - (distance(vector(0.5,0.5,0.0), pos) / (sqrt(2.0) / 2.5));
color factor = smoothstep(-Fuzz, 0.0, InputValue - sqrt(dist));
Out = mix(BlackDots, WhiteDots, factor);
}
@@ -0,0 +1,63 @@
float endCapTest(vector d1, point r2, vector d2)
{
// Compute point on vector d1 perpendicular to point r2
point px = d1 * dot(d1, r2);
// The vector to the line
vector diff = r2 - px;
// Point is hither
if (dot(diff, d2) > 0.0)
return length(diff);
return 0.0;
}
float rayDistance(point r1, vector d1, point r2, vector d2)
{
// Vector perpendicular to both is the connection direction
vector n = cross(d1, d2);
// TODO: Deal with parallell lines
// Compute closest point, which is ridiculously easy
n = normalize(n);
float closest = dot(n,(r1-r2));
// ...but now we need to deal with the endcaps
vector d2n = normalize(d2);
// Line 2 start point relative line 1 - all we care about
point rr = r2 - r1;
float c = endCapTest(d1, rr, d2n);
float d = endCapTest(d1, rr+d2, -d2n);
if (c > 0.0) closest = c;
if (d > 0.0) closest = d;
return closest;
}
shader FrikkinLazerbeams
[[ string help="Fake 3d Laser Lines! ",
string URL ="http://zapsrenderingtips.blogspot.com" ]]
(
// Inputs
point StartPoint = point(0.2,0.5,0.0),
point EndPoint = point(0.8,0.5,0.0),
color Color = color(1,0.02,0.01),
// Outputs
output color Out = 0.0)
{
// The vec
vector delta = EndPoint - StartPoint;
float f = rayDistance(P, I, StartPoint, delta);
Out = max(0, (Color / (fabs(f * 1.0) + 0.01)) - 0.03);
}
@@ -0,0 +1,46 @@
// Simple Gradient Shader with six inputs
// SimpleGradient.osl, by Zap Andersson
// Modified: 2018-05-09
// Copyright 2018 Autodesk Inc, All rights reserved. This file is licensed under Apache 2.0 license
// https://github.com/ADN-DevTech/3dsMax-OSL-Shaders/blob/master/LICENSE.txt
shader SimpleGradient
[[ string help="A Simple Gradient" ]]
(
float Input = u,
float Hardness = 0.0 [[ float min = 0.0, float max = 0.999 ]],
#define PAR(x, val, col) \
color x = col [[ string label = #x " Color Value" ]], \
float x##_Value = val [[ string label = #x " Position" ]],
// Add more lines like this if you need more inputs
PAR(A, 0.0, color(1,0,0))
PAR(B, 0.2, color(1,1,0))
PAR(C, 0.4, color(0,1,0))
PAR(D, 0.6, color(0,1,1))
PAR(E, 0.8, color(0,0,1))
PAR(F, 1.0, color(1,0,1))
// Inputs
output color Out = 0.0)
{
Out = F;
#define INT(x,y) \
if (Input >= x##_Value && Input < y##_Value) \
{ \
float where = (Input - x##_Value) / (y##_Value - x##_Value); \
where = smoothstep(Hardness, 1.0, where); \
Out = mix(x, y, where); \
}
// Add more lines like this if you need more inputs
// Note: One line less than the number of inputs
INT(A,B)
INT(B,C)
INT(C,D)
INT(D,E)
INT(E,F)
}
@@ -0,0 +1,23 @@
// Toon Width Modifier Shader
// ToonWidth.osl, by Zap Andersson
// Modified: 2018-06-28
// Copyright 2018 Autodesk Inc, All rights reserved. This file is licensed under Apache 2.0 license
// https://github.com/ADN-DevTech/3dsMax-OSL-Shaders/blob/master/LICENSE.txt
shader ToonWidth
[[ string help="Toon Edge Width based on how close the surface normal (when converted to screen space) is to the given direction.",
string URL ="http://zapsrenderingtips.blogspot.com" ]]
(
// Inputs
vector ThickDirection = vector(-0.6,-0.6,0.0)
[[ string label = "Thick Direction", string help="The closer the Normal - converted to screen space - is to this vector, the thicker the contour" ]],
float Base = 0.5 [[ string help="The base width" ]],
float Amt = 0.4 [[ string help="How much the width varies depends on the cloeness to the above screen space normal direction" ]],
// Outputs
output float Out = 0.0,
output float Out2 = 0.0)
{
vector camN = transform("camera", N);
Out = Base + Amt * dot(ThickDirection, camN);
}

0 comments on commit 61b0e76

Please sign in to comment.