2011-09-16 13:14:02 +00:00
|
|
|
/*
|
2013-08-18 14:16:15 +00:00
|
|
|
* Copyright 2011-2013 Blender Foundation
|
2011-09-16 13:14:02 +00:00
|
|
|
*
|
2013-08-18 14:16:15 +00:00
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
2011-09-16 13:14:02 +00:00
|
|
|
*
|
2013-08-18 14:16:15 +00:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2011-09-16 13:14:02 +00:00
|
|
|
*
|
2013-08-18 14:16:15 +00:00
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License
|
2011-09-16 13:14:02 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "stdosl.h"
|
|
|
|
#include "node_fresnel.h"
|
|
|
|
|
2012-10-17 16:16:35 +00:00
|
|
|
shader node_layer_weight(
|
|
|
|
float Blend = 0.5,
|
2011-09-16 13:14:02 +00:00
|
|
|
normal Normal = N,
|
|
|
|
output float Fresnel = 0.0,
|
|
|
|
output float Facing = 0.0)
|
|
|
|
{
|
2012-10-17 16:16:35 +00:00
|
|
|
float blend = Blend;
|
2013-05-26 17:10:22 +00:00
|
|
|
float cosi = dot(I, Normal);
|
2011-09-16 13:14:02 +00:00
|
|
|
|
2012-10-17 16:16:35 +00:00
|
|
|
/* Fresnel */
|
|
|
|
float eta = max(1.0 - Blend, 1e-5);
|
2012-10-18 04:51:37 +00:00
|
|
|
eta = backfacing() ? eta : 1.0 / eta;
|
2013-05-26 17:10:22 +00:00
|
|
|
Fresnel = fresnel_dielectric_cos(cosi, eta);
|
2012-10-17 16:16:35 +00:00
|
|
|
|
|
|
|
/* Facing */
|
2013-05-26 17:10:22 +00:00
|
|
|
Facing = fabs(cosi);
|
2011-09-16 13:14:02 +00:00
|
|
|
|
2012-10-17 16:16:35 +00:00
|
|
|
if (blend != 0.5) {
|
2012-10-20 08:02:18 +00:00
|
|
|
blend = clamp(blend, 0.0, 1.0 - 1e-5);
|
2012-10-18 04:51:37 +00:00
|
|
|
blend = (blend < 0.5) ? 2.0 * blend : 0.5 / (1.0 - blend);
|
2011-09-16 13:14:02 +00:00
|
|
|
|
2012-10-17 16:16:35 +00:00
|
|
|
Facing = pow(Facing, blend);
|
2011-09-16 13:14:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Facing = 1.0 - Facing;
|
|
|
|
}
|