2023-06-14 16:52:36 +10:00
|
|
|
/* SPDX-FileCopyrightText: 2009-2010 Sony Pictures Imageworks Inc., et al. All Rights Reserved.
|
|
|
|
|
* SPDX-FileCopyrightText: 2011-2022 Blender Foundation
|
2022-02-11 13:53:21 +01:00
|
|
|
*
|
2023-06-14 16:52:36 +10:00
|
|
|
* SPDX-License-Identifier: BSD-3-Clause
|
2022-02-11 13:53:21 +01:00
|
|
|
*
|
2023-06-14 16:52:36 +10:00
|
|
|
* Adapted code from Open Shading Language. */
|
2020-02-11 21:40:23 -07:00
|
|
|
|
|
|
|
|
#ifndef CCL_STDCYCLESOSL_H
|
|
|
|
|
#define CCL_STDCYCLESOSL_H
|
|
|
|
|
|
|
|
|
|
#include "stdosl.h"
|
|
|
|
|
|
2023-07-10 17:42:24 +02:00
|
|
|
// Constants
|
|
|
|
|
#define FLT_MAX 3.402823466e+38 // max value
|
|
|
|
|
|
2025-01-31 18:58:16 +01:00
|
|
|
/* Offset of coordinates for evaluating bump node. Unit in pixel.
|
|
|
|
|
* NOTE: keep the same as SVM. */
|
|
|
|
|
#define BUMP_DX 0.1
|
|
|
|
|
#define BUMP_DY BUMP_DX
|
|
|
|
|
|
2020-02-11 21:40:23 -07:00
|
|
|
// Declaration of built-in functions and closures, stdosl.h does not make
|
|
|
|
|
// these available so we have to redefine them.
|
|
|
|
|
#define BUILTIN [[int builtin = 1]]
|
|
|
|
|
#define BUILTIN_DERIV [[ int builtin = 1, int deriv = 1 ]]
|
|
|
|
|
|
|
|
|
|
closure color diffuse_ramp(normal N, color colors[8]) BUILTIN;
|
|
|
|
|
closure color phong_ramp(normal N, float exponent, color colors[8]) BUILTIN;
|
|
|
|
|
closure color diffuse_toon(normal N, float size, float smooth) BUILTIN;
|
|
|
|
|
closure color glossy_toon(normal N, float size, float smooth) BUILTIN;
|
|
|
|
|
closure color ashikhmin_velvet(normal N, float sigma) BUILTIN;
|
2023-07-24 15:36:36 +02:00
|
|
|
closure color sheen(normal N, float roughness) BUILTIN;
|
2020-02-11 21:40:23 -07:00
|
|
|
closure color ambient_occlusion() BUILTIN;
|
|
|
|
|
|
2023-09-17 01:14:51 +02:00
|
|
|
closure color microfacet_f82_tint(
|
|
|
|
|
string distribution, vector N, vector T, float ax, float ay, color f0, color f82) BUILTIN;
|
|
|
|
|
|
2023-06-07 21:45:48 +10:00
|
|
|
/* Needed to pass along the color for multi-scattering saturation adjustment,
|
Cycles: Remove MultiGGX code, replace with albedo scaling
While the multiscattering GGX code is cool and solves the darkening problem at higher roughnesses, it's also currently buggy, hard to maintain and often impractical to use due to the higher noise and render time.
In practice, though, having the exact correct directional distribution is not that important as long as the overall albedo is correct and we a) don't get the darkening effect and b) do get the saturation effect at higher roughnesses.
This can simply be achieved by adding a second lobe (https://blog.selfshadow.com/publications/s2017-shading-course/imageworks/s2017_pbs_imageworks_slides_v2.pdf) or scaling the single-scattering GGX lobe (https://blog.selfshadow.com/publications/turquin/ms_comp_final.pdf). Both approaches require the same precomputation and produce outputs of comparable quality, so I went for the simple albedo scaling since it's easier to implement and more efficient.
Overall, the results are pretty good: All scenarios that I tested (Glossy BSDF, Glass BSDF, Principled BSDF with metallic or transmissive = 1) pass the white furnace test (a material with pure-white color in front of a pure-white background should be indistinguishable from the background if it preserves energy), and the overall albedo for non-white materials matches that produced by the real multi-scattering code (with the expected saturation increase as the roughness increases).
In order to produce the precomputed tables, the PR also includes a utility that computes them. This is not built by default, since there's no reason for a user to run it (it only makes sense for documentation/reproducibility purposes and when making changes to the microfacet models).
Pull Request: https://projects.blender.org/blender/blender/pulls/107958
2023-06-05 02:20:57 +02:00
|
|
|
* otherwise could be replaced by microfacet() */
|
|
|
|
|
closure color microfacet_multi_ggx_glass(normal N, float ag, float eta, color C) BUILTIN;
|
|
|
|
|
closure color microfacet_multi_ggx_aniso(normal N, vector T, float ax, float ay, color C) BUILTIN;
|
|
|
|
|
|
2020-02-11 21:40:23 -07:00
|
|
|
// BSSRDF
|
|
|
|
|
closure color bssrdf(string method, normal N, vector radius, color albedo) BUILTIN;
|
|
|
|
|
|
|
|
|
|
// Hair
|
|
|
|
|
closure color
|
|
|
|
|
hair_reflection(normal N, float roughnessu, float roughnessv, vector T, float offset) BUILTIN;
|
|
|
|
|
closure color
|
|
|
|
|
hair_transmission(normal N, float roughnessu, float roughnessv, vector T, float offset) BUILTIN;
|
Cycles: new Principled Hair BSDF variant with elliptical cross-section support
Implements the paper [A Microfacet-based Hair Scattering
Model](https://onlinelibrary.wiley.com/doi/full/10.1111/cgf.14588) by
Weizhen Huang, Matthias B. Hullin and Johannes Hanika.
### Features:
- This is a far-field model, as opposed to the previous near-field
Principled Hair BSDF model. The hair is expected to be less noisy, but
lower roughness values takes longer to render due to numerical
integration along the hair width. The hair also appears to be flat when
viewed up-close.
- The longitudinal width of the scattering lobe differs along the
azimuth, providing a higher contrast compared to the evenly spread
scattering in the near-field Principled Hair BSDF model. For a more
detailed comparison, please refer to the original paper.
- Supports elliptical cross-sections, adding more realism as human hairs
are usually elliptical. The orientation of the cross-section is aligned
with the curve normal, which can be adjusted using geometry nodes.
Default is minimal twist. During sampling, light rays that hit outside
the hair width will continue propogating as if the material is
transparent.
- There is non-physical modulation factors for the first three
lobes (Reflection, Transmission, Secondary Reflection).
### Missing:
- A good default for cross-section orientation. There was an
attempt (9039f76928) to default the orientation to align with the curve
normal in the mathematical sense, but the stability (when animated) is
unclear and it would be a hassle to generalise to all curve types. After
the model is in main, we could experiment with the geometry nodes team
to see what works the best as a default.
Co-authored-by: Lukas Stockner <lukas.stockner@freenet.de>
Pull Request: https://projects.blender.org/blender/blender/pulls/105600
2023-08-18 12:46:13 +02:00
|
|
|
closure color hair_chiang(normal N,
|
|
|
|
|
color sigma,
|
|
|
|
|
float roughnessu,
|
|
|
|
|
float roughnessv,
|
|
|
|
|
float coat,
|
|
|
|
|
float alpha,
|
|
|
|
|
float eta) BUILTIN;
|
|
|
|
|
closure color hair_huang(normal N,
|
|
|
|
|
color sigma,
|
|
|
|
|
float roughness,
|
|
|
|
|
float tilt,
|
|
|
|
|
float eta,
|
|
|
|
|
float aspect_ratio,
|
|
|
|
|
float r_lobe,
|
|
|
|
|
float tt_lobe,
|
|
|
|
|
float trt_lobe) BUILTIN;
|
2020-02-11 21:40:23 -07:00
|
|
|
|
|
|
|
|
// Volume
|
|
|
|
|
closure color henyey_greenstein(float g) BUILTIN;
|
2024-10-02 11:05:28 +02:00
|
|
|
closure color fournier_forand(float B, float IOR) BUILTIN;
|
|
|
|
|
closure color draine(float g, float alpha) BUILTIN;
|
|
|
|
|
closure color rayleigh() BUILTIN;
|
2020-02-11 21:40:23 -07:00
|
|
|
closure color absorption() BUILTIN;
|
|
|
|
|
|
2024-04-29 12:37:51 +02:00
|
|
|
// Ray Portal
|
|
|
|
|
closure color ray_portal_bsdf(vector position, vector direction) BUILTIN;
|
|
|
|
|
|
2020-02-11 21:40:23 -07:00
|
|
|
#endif /* CCL_STDOSL_H */
|