Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix voronoi and gradient noise when using half precision #83

Merged
merged 3 commits into from
Apr 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions com.unity.shadergraph/CHANGELOG.md
Expand Up @@ -31,6 +31,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Copied nodes are now pasted at the cursor location instead of slightly offset from their original location
- Error messages reported on Sub Graph output nodes for invalid previews now present clearer information, with documentation support.
- Updated legacy COLOR output semantic to SV_Target in pixel shader for compatibility with DXC
- Changed the Voronoi Node algorithm to increase the useful range of the input values and to always use float values internally to avoid clipping.
- Changed the `Reference Suffix` of Keyword Enum entries so that you cannot edit them, which ensures that material keywords compile properly.

### Fixed
Expand Down
Expand Up @@ -45,7 +45,8 @@ public override void GenerateNodeFunction(FunctionRegistry registry, GenerationM
{
// Permutation and hashing used in webgl-nosie goo.gl/pX7HtC
p = p % 289;
$precision x = (34 * p.x + 1) * p.x % 289 + p.y;
// need full precision, otherwise half overflows when p > 1
float x = float(34 * p.x + 1) * p.x % 289 + p.y;
x = (34 * x + 1) * x % 289;
x = frac(x / 41) * 2 - 1;
return normalize($precision2(x - floor(x + 0.5), abs(x) - 0.5));
Expand Down
Expand Up @@ -58,7 +58,7 @@ public override void GenerateNodeFunction(FunctionRegistry registry, GenerationM
inline $precision2 Unity_Voronoi_RandomVector_$precision ($precision2 UV, $precision offset)
{
$precision2x2 m = $precision2x2(15.27, 47.63, 99.41, 89.98);
UV = frac(sin(mul(UV, m)) * 46839.32);
alindmanUnity marked this conversation as resolved.
Show resolved Hide resolved
UV = frac(sin(mul(UV, m)));
return $precision2(sin(UV.y*+offset)*0.5+0.5, cos(UV.x*offset)*0.5+0.5);
}
"));
Expand Down