2011-04-27 11:58:34 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2011, Blender Foundation.
|
|
|
|
*
|
|
|
|
* 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 2
|
|
|
|
* 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, write to the Free Software Foundation,
|
|
|
|
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "stdosl.h"
|
|
|
|
#include "node_fresnel.h"
|
|
|
|
|
|
|
|
shader node_glass_bsdf(
|
2012-12-11 16:06:03 +00:00
|
|
|
color Color = 0.8,
|
2011-04-27 11:58:34 +00:00
|
|
|
string distribution = "Sharp",
|
|
|
|
float Roughness = 0.2,
|
2011-09-16 13:14:02 +00:00
|
|
|
float IOR = 1.45,
|
2011-04-27 11:58:34 +00:00
|
|
|
normal Normal = N,
|
2012-12-11 16:06:03 +00:00
|
|
|
output closure color BSDF = 0)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
2011-09-16 13:14:02 +00:00
|
|
|
float f = max(IOR, 1.0 + 1e-5);
|
2012-10-18 04:51:37 +00:00
|
|
|
float eta = backfacing() ? 1.0 / f: f;
|
2011-04-27 11:58:34 +00:00
|
|
|
float Fr = fresnel_dielectric(I, Normal, eta);
|
|
|
|
|
2012-10-17 01:47:37 +00:00
|
|
|
if (distribution == "Sharp")
|
|
|
|
BSDF = Color * (Fr * reflection(Normal) + (1.0 - Fr) * refraction(Normal, eta));
|
|
|
|
else if (distribution == "Beckmann")
|
2012-11-03 14:32:13 +00:00
|
|
|
BSDF = Color * (Fr * microfacet_beckmann(Normal, Roughness) +
|
2012-10-17 01:47:37 +00:00
|
|
|
(1.0 - Fr) * microfacet_beckmann_refraction(Normal, Roughness, eta));
|
|
|
|
else if (distribution == "GGX")
|
2012-11-03 14:32:13 +00:00
|
|
|
BSDF = Color * (Fr * microfacet_ggx(Normal, Roughness) +
|
2012-10-17 01:47:37 +00:00
|
|
|
(1.0 - Fr) * microfacet_ggx_refraction(Normal, Roughness, eta));
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|