Compare commits

..

24 Commits

Author SHA1 Message Date
b063115d4e EEVEE: Remove softness parameters from RNA & UI
Keep it in DNA for backward compatibility
2019-09-02 16:41:07 +02:00
312dbf8af1 EEVEE: Fix sunlight when sun angle is 180 degrees 2019-09-02 16:41:07 +02:00
eb8093cb14 EEVEE: Shadow: Add back shadow bias
This is needed in some corner case (shadow acne due to aliasing and depth
disparity). This is a simple bias added to default bias. It should not be
needed most of the time but we leave it at 1 by default.
2019-09-02 16:41:07 +02:00
6adaa4202a EEVEE: Fix spotlight shadow optimization
Spot light can be non-uniform and scale in one direction. This fix makes
sure both directions are taken into account before skipping cubemap faces.
2019-09-02 16:41:07 +02:00
4dd3a9790f UI: Make cascaded shadowmap panel on top of contact shadow
This make more sense as cascade parameters are more important.
2019-09-02 16:41:07 +02:00
c584116e25 EEVEE: Shadow: Add temporal sampling to shadowmaps
If soft shadows is enabled, we randomize the shadowmap sample position
to reduce aliasing artifacts (jagged edge shadows).
2019-09-02 16:41:07 +02:00
3e10785c60 Cleanup: EEVEE: Split eevee_lights.c into smaller files
Also have some const correctness fix and some header cleanup.
2019-09-02 16:41:07 +02:00
9468425524 Eevee: Shadow: Refactor / Cleanup of shadow update
- Replace EEVEE_lightbits by BLI_bitmap
- Replace EEVEE_BoundSphere by BoundSphere
- Support for dupli light shadows
- Detect unecessary update of soft shadows (i.e: moving the view)
- Remove Object references
2019-09-02 16:41:07 +02:00
31e21d38e3 Eevee: Light: Refactor shadow tagging to allow dupli shadow casters
Dupli objects can now cast shadows.

This also replace the custom lightbits by BLI_bitmap.
2019-09-02 16:41:07 +02:00
8457593672 Eevee: Shadows: Add texel border on shadow cube for better edge filtering
Unfortunately, this seems to be imprecise on lower cube resolution. But
the result is still most of the time more pleasant than no border filtering.
2019-09-02 16:41:06 +02:00
e13f5cc5ae Eevee: Shadow: Speedup: Only render shadow cube face needed
This reduce the number of face to render to 5 in the case of area lights
and 5 or 1 for spotlights.

Spotlights that have a spot size less than 90 degrees only need 1 face and
are the fastest.
2019-09-02 16:41:06 +02:00
278d174e35 Eevee: Shadows: Make shadowmap follow light orientation
This is in preparation of an optimization
2019-09-02 16:41:06 +02:00
d5555e5d5a DRW: Add line offset to DRW_STATE_SHADOW_OFFSET
This is needed for hairs.
2019-09-02 16:41:06 +02:00
585eaa5b0a Eevee: Shadows: Improve contact shadows
Contact shadows now follow the shadowmap direction. This means it matches
the shadowmap blur that is proportional to the light radius.

Moreover this adds a more efficient bias for most contact shadows.
2019-09-02 16:41:06 +02:00
4ec63b5421 Eevee: Shadow: Speedup: Use only 2 sample for cascaded shadowmap 2019-09-02 16:41:06 +02:00
a77301289d Eevee: Shadow: Remove receiver plane bias and use hardware filtering
In an attempt to simplify the shadowing in eevee, we remove the bias and
filtering option.

Now the shadowmap always get the minimum constant and slope bias and we
only do a bilinear shadow filtering. This means the shadow is as sharper
and exact as the shadow map format allows (bitdepth and size).

Only the lamp size can change the shadow softness.
2019-09-02 16:41:06 +02:00
95a3c256dc Eevee: Shadow: Make sun clip distances automatic
This simplify sun lights setup and matches more cycles behavior.
2019-09-02 16:41:06 +02:00
0edd48c904 Eevee: Remove ESM and VSM code 2019-09-02 16:41:06 +02:00
9e19ec0d18 Eevee: Shadows: Add Receiver Plane Depth Bias
This bias replace the previous bias method. The bias is now scalled to
have the correct depth of the triangle at the sample location. This is done
by computing the actual depth that would be recorded in the shadowmap
at the texels locations, if the triangle was extrapolated.

This leads to less shadow acne and it ensure the bias is always the minimum
amount that ensure correct shadowing.

However this technique is not failure free and if the receiver is nearly
parallel to the light, the bias is nearly infinite and light leaking occurs.

For this reason I decided to cap the bias by the bias parameter to tweak
between shadow acne and light leaking.
2019-09-02 16:41:06 +02:00
e951f5f0fe Eevee: Replace ESM and VSM by PCF shadow mapping
PCF shadowmaps are less prone to light leaking and are faster to
render.

This remove a substantial part of the shadowing code.
2019-09-02 16:41:06 +02:00
4df76629a5 DRW: Add shadow bias state
This state add shadowmap bias to avoid most of self shadowing.
2019-09-02 16:41:06 +02:00
786b0c6414 Eevee: SSS: Refactor translucency
This separate the translucency evaluation to be outside of surface eval.

This as the benefit to reduce code complexity and remove the need for
shadow map (non-test) sampler in the shading pass.

One big change is that bsdf intensity is multiplied and stored with the
albedo color instead of the sss irradiance. This is in order to apply it
to both the translucency and the sss diffusion. This change the look of
mixed SSS shaders which is now closer to cycles.

Performance cost is negligeable.

# Conflicts:
#	source/blender/gpu/shaders/gpu_shader_material.glsl
2019-09-02 16:41:02 +02:00
9ee5e73a3d Eevee: SSS: Refactor to use less memory and always use separate albedo
This refactor reduce the Memory overhead of SSS and enables us to always
use separate albedo. Previously we used 128bits/px for SSS data and
32bits/px for albedo. Now we use 112bits/px for SSS data & separate albedo
altogether.

This refactor is needed for PCF shadow maps.

# Conflicts:
#	source/blender/gpu/shaders/gpu_shader_material.glsl
2019-09-02 16:38:14 +02:00
77a0ef91ba GPUFramebuffer: Bump max color attachement to 6 2019-09-02 16:30:48 +02:00
776 changed files with 23129 additions and 69516 deletions

View File

@@ -752,12 +752,14 @@ if(NOT WITH_CUDA_DYNLOAD)
endif()
#-----------------------------------------------------------------------------
# Check check if submodules are cloned
# Check for valid directories
# ... a partial checkout may cause this.
#
# note: we need to check for a known subdir in both cases.
# since uninitialized git submodules will give blank dirs
if(WITH_INTERNATIONAL)
file(GLOB RESULT "${CMAKE_SOURCE_DIR}/release/datafiles/locale")
list(LENGTH RESULT DIR_LEN)
if(DIR_LEN EQUAL 0)
if(NOT EXISTS "${CMAKE_SOURCE_DIR}/release/datafiles/locale/languages")
message(WARNING
"Translation path '${CMAKE_SOURCE_DIR}/release/datafiles/locale' is missing, "
"This is a 'git submodule', which are known not to work with bridges to other version "
@@ -779,9 +781,7 @@ if(WITH_PYTHON)
message(FATAL_ERROR "At least Python 3.7 is required to build")
endif()
file(GLOB RESULT "${CMAKE_SOURCE_DIR}/release/scripts/addons")
list(LENGTH RESULT DIR_LEN)
if(DIR_LEN EQUAL 0)
if(NOT EXISTS "${CMAKE_SOURCE_DIR}/release/scripts/addons/modules")
message(WARNING
"Addons path '${CMAKE_SOURCE_DIR}/release/scripts/addons' is missing, "
"This is a 'git submodule', which are known not to work with bridges to other version "

View File

@@ -1114,7 +1114,7 @@ run_ldconfig() {
WARNING "--no-sudo enabled, impossible to run ldconfig for $1, you'll have to do it yourself..."
else
INFO "Running ldconfig for $1..."
$SUDO sh -c "/bin/echo -e \"$_lib_path\n$_lib64_path\" > $_ldconf_path"
$SUDO sh -c "echo -e \"$_lib_path\n$_lib64_path\" > $_ldconf_path"
$SUDO /sbin/ldconfig # XXX OpenSuse does not include sbin in command path with sudo!!!
fi
PRINT ""

View File

@@ -1,112 +0,0 @@
# ##### BEGIN GPL LICENSE BLOCK #####
#
# 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.
#
# ##### END GPL LICENSE BLOCK #####
# <pep8 compliant>
import argparse
import os
import subprocess
import sys
class Builder:
def __init__(self, name, branch):
self.name = name
self.branch = branch
# Buildbot runs from build/ directory
self.blender_dir = os.path.abspath(os.path.join('..', 'blender.git'))
self.build_dir = os.path.abspath(os.path.join('..', 'build', name))
self.install_dir = os.path.abspath(os.path.join('..', 'install', name))
self.upload_dir = os.path.abspath(os.path.join('..', 'install'))
# Detect platform
if name.startswith('mac'):
self.platform = 'mac'
self.command_prefix = []
elif name.startswith('linux'):
self.platform = 'linux'
self.command_prefix = ['scl', 'enable', 'devtoolset-6', '--']
elif name.startswith('win'):
self.platform = 'win'
self.command_prefix = []
else:
raise ValueError('Unkonw platform for builder ' + self.platform)
# Always 64 bit now
self.bits = 64
def create_builder_from_arguments():
parser = argparse.ArgumentParser()
parser.add_argument('builder_name')
parser.add_argument('branch', default='master', nargs='?')
args = parser.parse_args()
return Builder(args.builder_name, args.branch)
class VersionInfo:
def __init__(self, builder):
# Get version information
buildinfo_h = os.path.join(builder.build_dir, "source", "creator", "buildinfo.h")
blender_h = os.path.join(builder.blender_dir, "source", "blender", "blenkernel", "BKE_blender_version.h")
version_number = int(self._parse_header_file(blender_h, 'BLENDER_VERSION'))
self.version = "%d.%d" % (version_number // 100, version_number % 100)
self.version_char = self._parse_header_file(blender_h, 'BLENDER_VERSION_CHAR')
self.version_cycle = self._parse_header_file(blender_h, 'BLENDER_VERSION_CYCLE')
self.version_cycle_number = self._parse_header_file(blender_h, 'BLENDER_VERSION_CYCLE_NUMBER')
self.hash = self._parse_header_file(buildinfo_h, 'BUILD_HASH')[1:-1]
if self.version_cycle == "release":
# Final release
self.full_version = self.version + self.version_char
self.is_development_build = False
elif self.version_cycle == "rc":
# Release candidate
version_cycle = self.version_cycle + self.version_cycle_number
if len(self.version_char) == 0:
self.full_version = self.version + version_cycle
else:
self.full_version = self.version + self.version_char + '-' + version_cycle
self.is_development_build = False
else:
# Development build
self.full_version = self.version + '-' + self.hash
self.is_development_build = True
def _parse_header_file(self, filename, define):
import re
regex = re.compile("^#\s*define\s+%s\s+(.*)" % define)
with open(filename, "r") as file:
for l in file:
match = regex.match(l)
if match:
return match.group(1)
return None
def call(cmd, env=None, exit_on_error=True):
print(' '.join(cmd))
# Flush to ensure correct order output on Windows.
sys.stdout.flush()
sys.stderr.flush()
retcode = subprocess.call(cmd, env=env)
if exit_on_error and retcode != 0:
sys.exit(retcode)
return retcode

View File

@@ -18,80 +18,149 @@
# <pep8 compliant>
import buildbot_utils
import os
import subprocess
import sys
import shutil
def get_cmake_options(builder):
config_file = "build_files/cmake/config/blender_release.cmake"
options = ['-DCMAKE_BUILD_TYPE:STRING=Release', '-DWITH_GTESTS=ON']
# get builder name
if len(sys.argv) < 2:
sys.stderr.write("Not enough arguments, expecting builder name\n")
sys.exit(1)
if builder.platform == 'mac':
options.append('-DCMAKE_OSX_ARCHITECTURES:STRING=x86_64')
options.append('-DCMAKE_OSX_DEPLOYMENT_TARGET=10.9')
elif builder.platform == 'win':
options.extend(['-G', 'Visual Studio 15 2017 Win64'])
elif builder.platform == 'linux':
config_file = "build_files/buildbot/config/blender_linux.cmake"
builder = sys.argv[1]
options.append("-C" + os.path.join(builder.blender_dir, config_file))
options.append("-DCMAKE_INSTALL_PREFIX=%s" % (builder.install_dir))
# we run from build/ directory
blender_dir = os.path.join('..', 'blender.git')
return options
def update_git(builder):
# Do extra git fetch because not all platform/git/buildbot combinations
# update the origin remote, causing buildinfo to detect local changes.
os.chdir(builder.blender_dir)
def parse_header_file(filename, define):
import re
regex = re.compile("^#\s*define\s+%s\s+(.*)" % define)
with open(filename, "r") as file:
for l in file:
match = regex.match(l)
if match:
return match.group(1)
return None
print("Fetching remotes")
command = ['git', 'fetch', '--all']
buildbot_utils.call(builder.command_prefix + command)
if 'cmake' in builder:
# cmake
def clean_directories(builder):
# Make sure no garbage remained from the previous run
if os.path.isdir(builder.install_dir):
shutil.rmtree(builder.install_dir)
# Some fine-tuning configuration
blender_dir = os.path.abspath(blender_dir)
build_dir = os.path.abspath(os.path.join('..', 'build', builder))
install_dir = os.path.abspath(os.path.join('..', 'install', builder))
targets = ['blender']
command_prefix = []
# Make sure build directory exists and enter it
os.makedirs(builder.build_dir, exist_ok=True)
bits = 64
# Remove buildinfo files to force buildbot to re-generate them.
for buildinfo in ('buildinfo.h', 'buildinfo.h.txt', ):
full_path = os.path.join(builder.build_dir, 'source', 'creator', buildinfo)
if os.path.exists(full_path):
print("Removing {}" . format(buildinfo))
os.remove(full_path)
# Config file to be used (relative to blender's sources root)
cmake_config_file = "build_files/cmake/config/blender_release.cmake"
def cmake_configure(builder):
# CMake configuration
os.chdir(builder.build_dir)
# Set build options.
cmake_options = []
cmake_extra_options = ['-DCMAKE_BUILD_TYPE:STRING=Release',
'-DWITH_GTESTS=ON']
cmake_cache = os.path.join(builder.build_dir, 'CMakeCache.txt')
if os.path.exists(cmake_cache):
print("Removing CMake cache")
os.remove(cmake_cache)
if builder.startswith('mac'):
# Set up OSX architecture
if builder.endswith('x86_64_10_9_cmake'):
cmake_extra_options.append('-DCMAKE_OSX_ARCHITECTURES:STRING=x86_64')
cmake_extra_options.append('-DCMAKE_OSX_DEPLOYMENT_TARGET=10.9')
print("CMake configure:")
cmake_options = get_cmake_options(builder)
command = ['cmake', builder.blender_dir] + cmake_options
buildbot_utils.call(builder.command_prefix + command)
elif builder.startswith('win'):
if builder.startswith('win64'):
cmake_options.extend(['-G', 'Visual Studio 15 2017 Win64'])
elif builder.startswith('win32'):
bits = 32
cmake_options.extend(['-G', 'Visual Studio 15 2017'])
def cmake_build(builder):
# CMake build
os.chdir(builder.build_dir)
elif builder.startswith('linux'):
cmake_config_file = "build_files/buildbot/config/blender_linux.cmake"
tokens = builder.split("_")
glibc = tokens[1]
if glibc == 'glibc224':
deb_name = "stretch"
if builder.endswith('x86_64_cmake'):
chroot_name = 'buildbot_' + deb_name + '_x86_64'
elif builder.endswith('i686_cmake'):
bits = 32
chroot_name = 'buildbot_' + deb_name + '_i686'
command_prefix = ['schroot', '-c', chroot_name, '--']
elif glibc == 'glibc217':
command_prefix = ['scl', 'enable', 'devtoolset-6', '--']
if builder.platform == 'win':
command = ['cmake', '--build', '.', '--target', 'install', '--config', 'Release']
cmake_options.append("-C" + os.path.join(blender_dir, cmake_config_file))
# Prepare CMake options needed to configure cuda binaries compilation, 64bit only.
if bits == 64:
cmake_options.append("-DWITH_CYCLES_CUDA_BINARIES=ON")
cmake_options.append("-DCUDA_64_BIT_DEVICE_CODE=ON")
else:
command = ['make', '-s', '-j2', 'install']
cmake_options.append("-DWITH_CYCLES_CUDA_BINARIES=OFF")
print("CMake build:")
buildbot_utils.call(builder.command_prefix + command)
cmake_options.append("-DCMAKE_INSTALL_PREFIX=%s" % (install_dir))
if __name__ == "__main__":
builder = buildbot_utils.create_builder_from_arguments()
update_git(builder)
clean_directories(builder)
cmake_configure(builder)
cmake_build(builder)
cmake_options += cmake_extra_options
# Make sure no garbage remained from the previous run
if os.path.isdir(install_dir):
shutil.rmtree(install_dir)
for target in targets:
print("Building target %s" % (target))
# Construct build directory name based on the target
target_build_dir = build_dir
target_command_prefix = command_prefix[:]
if target != 'blender':
target_build_dir += '_' + target
target_name = 'install'
# Tweaking CMake options to respect the target
target_cmake_options = cmake_options[:]
# Do extra git fetch because not all platform/git/buildbot combinations
# update the origin remote, causing buildinfo to detect local changes.
os.chdir(blender_dir)
print("Fetching remotes")
command = ['git', 'fetch', '--all']
print(command)
retcode = subprocess.call(target_command_prefix + command)
if retcode != 0:
sys.exit(retcode)
# Make sure build directory exists and enter it
if not os.path.isdir(target_build_dir):
os.mkdir(target_build_dir)
os.chdir(target_build_dir)
# Configure the build
print("CMake options:")
print(target_cmake_options)
if os.path.exists('CMakeCache.txt'):
print("Removing CMake cache")
os.remove('CMakeCache.txt')
# Remove buildinfo files to force buildbot to re-generate them.
for buildinfo in ('buildinfo.h', 'buildinfo.h.txt', ):
full_path = os.path.join('source', 'creator', buildinfo)
if os.path.exists(full_path):
print("Removing {}" . format(buildinfo))
os.remove(full_path)
retcode = subprocess.call(target_command_prefix + ['cmake', blender_dir] + target_cmake_options)
if retcode != 0:
print('Configuration FAILED!')
sys.exit(retcode)
if 'win32' in builder or 'win64' in builder:
command = ['cmake', '--build', '.', '--target', target_name, '--config', 'Release']
else:
command = ['make', '-s', '-j2', target_name]
print("Executing command:")
print(command)
retcode = subprocess.call(target_command_prefix + command)
if retcode != 0:
sys.exit(retcode)
else:
print("Unknown building system")
sys.exit(1)

View File

@@ -22,36 +22,47 @@
# system and zipping it into buildbot_upload.zip. This is then uploaded
# to the master in the next buildbot step.
import buildbot_utils
import os
import subprocess
import sys
import zipfile
def get_package_name(builder, platform=None):
info = buildbot_utils.VersionInfo(builder)
# get builder name
if len(sys.argv) < 2:
sys.stderr.write("Not enough arguments, expecting builder name\n")
sys.exit(1)
package_name = 'blender-' + info.full_version
if platform:
package_name += '-' + platform
if builder.branch != 'master' and info.is_development_build:
package_name = builder.branch + "-" + package_name
builder = sys.argv[1]
# Never write branch if it is master.
branch = sys.argv[2] if (len(sys.argv) >= 3 and sys.argv[2] != 'master') else ''
return package_name
blender_dir = os.path.join('..', 'blender.git')
build_dir = os.path.join('..', 'build', builder)
install_dir = os.path.join('..', 'install', builder)
buildbot_upload_zip = os.path.abspath(os.path.join(os.path.dirname(install_dir), "buildbot_upload.zip"))
def create_buildbot_upload_zip(builder, package_files):
import zipfile
upload_filename = None # Name of the archive to be uploaded
# (this is the name of archive which will appear on the
# download page)
upload_filepath = None # Filepath to be uploaded to the server
# (this folder will be packed)
buildbot_upload_zip = os.path.join(builder.upload_dir, "buildbot_upload.zip")
if os.path.exists(buildbot_upload_zip):
os.remove(buildbot_upload_zip)
try:
z = zipfile.ZipFile(buildbot_upload_zip, "w", compression=zipfile.ZIP_STORED)
for filepath, filename in package_files:
z.write(filepath, arcname=filename)
z.close()
except Exception as ex:
sys.stderr.write('Create buildbot_upload.zip failed: ' + str(ex) + '\n')
sys.exit(1)
def parse_header_file(filename, define):
import re
regex = re.compile("^#\s*define\s+%s\s+(.*)" % define)
with open(filename, "r") as file:
for l in file:
match = regex.match(l)
if match:
return match.group(1)
return None
# Make sure install directory always exists
if not os.path.exists(install_dir):
os.makedirs(install_dir)
def create_tar_bz2(src, dest, package_name):
# One extra to remove leading os.sep when cleaning root for package_root
@@ -69,120 +80,163 @@ def create_tar_bz2(src, dest, package_name):
package.add(entry[0], entry[1], recursive=False)
package.close()
def cleanup_files(dirpath, extension):
for f in os.listdir(dirpath):
filepath = os.path.join(dirpath, f)
if os.path.isfile(filepath) and f.endswith(extension):
os.remove(filepath)
if builder.find('cmake') != -1:
# CMake
if 'win' in builder or 'mac' in builder:
os.chdir(build_dir)
files = [f for f in os.listdir('.') if os.path.isfile(f) and f.endswith('.zip')]
for f in files:
os.remove(f)
retcode = subprocess.call(['cpack', '-G', 'ZIP'])
result_file = [f for f in os.listdir('.') if os.path.isfile(f) and f.endswith('.zip')][0]
# TODO(sergey): Such magic usually happens in SCon's packaging but we don't have it
# in the CMake yet. For until then we do some magic here.
tokens = result_file.split('-')
blender_version = tokens[1].split('.')
blender_full_version = '.'.join(blender_version[0:2])
git_hash = tokens[2].split('.')[1]
platform = builder.split('_')[0]
if platform == 'mac':
# Special exception for OSX
platform = 'OSX-10.9-'
if builder.endswith('x86_64_10_9_cmake'):
platform += 'x86_64'
if builder.endswith('vc2015'):
platform += "-vc14"
builderified_name = 'blender-{}-{}-{}'.format(blender_full_version, git_hash, platform)
# NOTE: Blender 2.7 is already respected by blender_full_version.
if branch != '' and branch != 'blender2.7':
builderified_name = branch + "-" + builderified_name
os.rename(result_file, "{}.zip".format(builderified_name))
# create zip file
try:
if os.path.exists(buildbot_upload_zip):
os.remove(buildbot_upload_zip)
z = zipfile.ZipFile(buildbot_upload_zip, "w", compression=zipfile.ZIP_STORED)
z.write("{}.zip".format(builderified_name))
z.close()
sys.exit(retcode)
except Exception as ex:
sys.stderr.write('Create buildbot_upload.zip failed' + str(ex) + '\n')
sys.exit(1)
elif builder.startswith('linux_'):
blender = os.path.join(install_dir, 'blender')
buildinfo_h = os.path.join(build_dir, "source", "creator", "buildinfo.h")
blender_h = os.path.join(blender_dir, "source", "blender", "blenkernel", "BKE_blender_version.h")
# Get version information
blender_version = int(parse_header_file(blender_h, 'BLENDER_VERSION'))
blender_version = "%d.%d" % (blender_version // 100, blender_version % 100)
blender_hash = parse_header_file(buildinfo_h, 'BUILD_HASH')[1:-1]
blender_glibc = builder.split('_')[1]
command_prefix = []
bits = 64
blender_arch = 'x86_64'
if blender_glibc == 'glibc224':
if builder.endswith('x86_64_cmake'):
chroot_name = 'buildbot_stretch_x86_64'
elif builder.endswith('i686_cmake'):
chroot_name = 'buildbot_stretch_i686'
bits = 32
blender_arch = 'i686'
command_prefix = ['schroot', '-c', chroot_name, '--']
elif blender_glibc == 'glibc217':
command_prefix = ['scl', 'enable', 'devtoolset-6', '--']
# Strip all unused symbols from the binaries
print("Stripping binaries...")
subprocess.call(command_prefix + ['strip', '--strip-all', blender])
print("Stripping python...")
py_target = os.path.join(install_dir, blender_version)
subprocess.call(command_prefix + ['find', py_target, '-iname', '*.so', '-exec', 'strip', '-s', '{}', ';'])
# Copy all specific files which are too specific to be copied by
# the CMake rules themselves
print("Copying extra scripts and libs...")
extra = '/' + os.path.join('home', 'sources', 'release-builder', 'extra')
mesalibs = os.path.join(extra, 'mesalibs' + str(bits) + '.tar.bz2')
software_gl = os.path.join(blender_dir, 'release', 'bin', 'blender-softwaregl')
icons = os.path.join(blender_dir, 'release', 'freedesktop', 'icons')
os.system('tar -xpf %s -C %s' % (mesalibs, install_dir))
os.system('cp %s %s' % (software_gl, install_dir))
os.system('cp -r %s %s' % (icons, install_dir))
os.system('chmod 755 %s' % (os.path.join(install_dir, 'blender-softwaregl')))
# Construct archive name
package_name = 'blender-%s-%s-linux-%s-%s' % (blender_version,
blender_hash,
blender_glibc,
blender_arch)
# NOTE: Blender 2.7 is already respected by blender_full_version.
if branch != '' and branch != 'blender2.7':
package_name = branch + "-" + package_name
upload_filename = package_name + ".tar.bz2"
print("Creating .tar.bz2 archive")
upload_filepath = install_dir + '.tar.bz2'
create_tar_bz2(install_dir, upload_filepath, package_name)
else:
print("Unknown building system")
sys.exit(1)
def pack_mac(builder):
info = buildbot_utils.VersionInfo(builder)
if upload_filepath is None:
# clean release directory if it already exists
release_dir = 'release'
os.chdir(builder.build_dir)
cleanup_files(builder.build_dir, '.dmg')
if os.path.exists(release_dir):
for f in os.listdir(release_dir):
if os.path.isfile(os.path.join(release_dir, f)):
os.remove(os.path.join(release_dir, f))
package_name = get_package_name(builder, 'macOS')
package_filename = package_name + '.dmg'
package_filepath = os.path.join(builder.build_dir, package_filename)
# create release package
try:
subprocess.call(['make', 'package_archive'])
except Exception as ex:
sys.stderr.write('Make package release failed' + str(ex) + '\n')
sys.exit(1)
release_dir = os.path.join(builder.blender_dir, 'release', 'darwin')
bundle_sh = os.path.join(release_dir, 'bundle.sh')
# find release directory, must exist this time
if not os.path.exists(release_dir):
sys.stderr.write("Failed to find release directory %r.\n" % release_dir)
sys.exit(1)
command = [bundle_sh]
command += ['--source', builder.install_dir]
command += ['--dmg', package_filepath]
if info.is_development_build:
background_image = os.path.join(release_dir, 'buildbot', 'background.tif')
command += ['--background-image', background_image]
buildbot_utils.call(command)
# find release package
file = None
filepath = None
create_buildbot_upload_zip(builder, [(package_filepath, package_filename)])
for f in os.listdir(release_dir):
rf = os.path.join(release_dir, f)
if os.path.isfile(rf) and f.startswith('blender'):
file = f
filepath = rf
if not file:
sys.stderr.write("Failed to find release package.\n")
sys.exit(1)
def pack_win(builder):
info = buildbot_utils.VersionInfo(builder)
upload_filename = file
upload_filepath = filepath
os.chdir(builder.build_dir)
cleanup_files(builder.build_dir, '.zip')
# CPack will add the platform name
cpack_name = get_package_name(builder, None)
package_name = get_package_name(builder, 'windows' + str(builder.bits))
command = ['cmake', '-DCPACK_OVERRIDE_PACKAGENAME:STRING=' + cpack_name, '.']
buildbot_utils.call(builder.command_prefix + command)
command = ['cpack', '-G', 'ZIP']
buildbot_utils.call(builder.command_prefix + command)
package_filename = package_name + '.zip'
package_filepath = os.path.join(builder.build_dir, package_filename)
package_files = [(package_filepath, package_filename)]
if info.version_cycle == 'release':
# Installer only for final release builds, otherwise will get
# 'this product is already installed' messages.
command = ['cpack', '-G', 'WIX']
buildbot_utils.call(builder.command_prefix + command)
package_filename = package_name + '.msi'
package_filepath = os.path.join(builder.build_dir, package_filename)
package_files += [(package_filepath, package_filename)]
create_buildbot_upload_zip(builder, package_files)
def pack_linux(builder):
blender_executable = os.path.join(builder.install_dir, 'blender')
info = buildbot_utils.VersionInfo(builder)
blender_glibc = builder.name.split('_')[1]
blender_arch = 'x86_64'
# Strip all unused symbols from the binaries
print("Stripping binaries...")
buildbot_utils.call(builder.command_prefix + ['strip', '--strip-all', blender_executable])
print("Stripping python...")
py_target = os.path.join(builder.install_dir, info.version)
buildbot_utils.call(builder.command_prefix + ['find', py_target, '-iname', '*.so', '-exec', 'strip', '-s', '{}', ';'])
# Copy all specific files which are too specific to be copied by
# the CMake rules themselves
print("Copying extra scripts and libs...")
extra = '/' + os.path.join('home', 'sources', 'release-builder', 'extra')
mesalibs = os.path.join(extra, 'mesalibs' + str(builder.bits) + '.tar.bz2')
software_gl = os.path.join(builder.blender_dir, 'release', 'bin', 'blender-softwaregl')
icons = os.path.join(builder.blender_dir, 'release', 'freedesktop', 'icons')
os.system('tar -xpf %s -C %s' % (mesalibs, builder.install_dir))
os.system('cp %s %s' % (software_gl, builder.install_dir))
os.system('cp -r %s %s' % (icons, builder.install_dir))
os.system('chmod 755 %s' % (os.path.join(builder.install_dir, 'blender-softwaregl')))
# Construct package name
platform_name = 'linux-' + blender_glibc + '-' + blender_arch
package_name = get_package_name(builder, platform_name)
package_filename = package_name + ".tar.bz2"
print("Creating .tar.bz2 archive")
package_filepath = builder.install_dir + '.tar.bz2'
create_tar_bz2(builder.install_dir, package_filepath, package_name)
# Create buildbot_upload.zip
create_buildbot_upload_zip(builder, [(package_filepath, package_filename)])
if __name__ == "__main__":
builder = buildbot_utils.create_builder_from_arguments()
# Make sure install directory always exists
os.makedirs(builder.install_dir, exist_ok=True)
if builder.platform == 'mac':
pack_mac(builder)
elif builder.platform == 'win':
pack_win(builder)
elif builder.platform == 'linux':
pack_linux(builder)
# create zip file
try:
upload_zip = os.path.join(buildbot_upload_zip)
if os.path.exists(upload_zip):
os.remove(upload_zip)
z = zipfile.ZipFile(upload_zip, "w", compression=zipfile.ZIP_STORED)
z.write(upload_filepath, arcname=upload_filename)
z.close()
except Exception as ex:
sys.stderr.write('Create buildbot_upload.zip failed' + str(ex) + '\n')
sys.exit(1)

View File

@@ -21,17 +21,23 @@
# Runs on buildbot slave, rsync zip directly to buildbot server rather
# than using upload which is much slower
import buildbot_utils
import os
import sys
if __name__ == "__main__":
builder = buildbot_utils.create_builder_from_arguments()
# get builder name
if len(sys.argv) < 2:
sys.stderr.write("Not enough arguments, expecting builder name\n")
sys.exit(1)
# rsync, this assumes ssh keys are setup so no password is needed
local_zip = "buildbot_upload.zip"
remote_folder = "builder.blender.org:/data/buildbot-master/uploaded/"
remote_zip = remote_folder + "buildbot_upload_" + builder.name + ".zip"
builder = sys.argv[1]
command = ["rsync", "-avz", local_zip, remote_zip]
buildbot_utils.call(command)
# rsync, this assumes ssh keys are setup so no password is needed
local_zip = "buildbot_upload.zip"
remote_folder = "builder.blender.org:/data/buildbot-master/uploaded/"
remote_zip = remote_folder + "buildbot_upload_" + builder + ".zip"
command = "rsync -avz %s %s" % (local_zip, remote_zip)
print(command)
ret = os.system(command)
sys.exit(ret)

View File

@@ -18,22 +18,59 @@
# <pep8 compliant>
import buildbot_utils
import subprocess
import os
import sys
def get_ctest_arguments(builder):
args = ['--output-on-failure']
if builder.platform == 'win':
args += ['-C', 'Release']
return args
# get builder name
if len(sys.argv) < 2:
sys.stderr.write("Not enough arguments, expecting builder name\n")
sys.exit(1)
def test(builder):
os.chdir(builder.build_dir)
builder = sys.argv[1]
command = builder.command_prefix + ['ctest'] + get_ctest_arguments(builder)
buildbot_utils.call(command)
# we run from build/ directory
blender_dir = '../blender.git'
if __name__ == "__main__":
builder = buildbot_utils.create_builder_from_arguments()
test(builder)
if "cmake" in builder:
print("Automated tests are still DISABLED!")
sys.exit(0)
build_dir = os.path.abspath(os.path.join('..', 'build', builder))
install_dir = os.path.abspath(os.path.join('..', 'install', builder))
# NOTE: For quick test only to see if the approach work.
# n the future must be replaced with an actual blender version.
blender_version = '2.80'
blender_version_dir = os.path.join(install_dir, blender_version)
command_prefix = []
extra_ctest_args = []
if builder.startswith('win'):
extra_ctest_args += ['-C', 'Release']
elif builder.startswith('linux'):
tokens = builder.split("_")
glibc = tokens[1]
if glibc == 'glibc224':
deb_name = "stretch"
if builder.endswith('x86_64_cmake'):
chroot_name = 'buildbot_' + deb_name + '_x86_64'
elif builder.endswith('i686_cmake'):
chroot_name = 'buildbot_' + deb_name + '_i686'
command_prefix = ['schroot', '--preserve-environment', '-c', chroot_name, '--']
elif glibc == 'glibc217':
command_prefix = ['scl', 'enable', 'devtoolset-6', '--']
ctest_env = os.environ.copy()
ctest_env['BLENDER_SYSTEM_SCRIPTS'] = os.path.join(blender_version_dir, 'scripts')
ctest_env['BLENDER_SYSTEM_DATAFILES'] = os.path.join(blender_version_dir, 'datafiles')
os.chdir(build_dir)
retcode = subprocess.call(command_prefix + ['ctest', '--output-on-failure'] + extra_ctest_args,
env=ctest_env)
# Always exit with a success, for until we know all the tests are passing
# on all builders.
sys.exit(0)
else:
print("Unknown building system")
sys.exit(1)

View File

@@ -18,14 +18,14 @@
# <pep8 compliant>
import buildbot_utils
import os
import sys
import runpy
if __name__ == "__main__":
builder = buildbot_utils.create_builder_from_arguments()
os.chdir(builder.blender_dir)
# We run from build/ directory.
blender_dir = os.path.join('..', 'blender.git')
blender_dir = os.path.abspath(blender_dir)
os.chdir(blender_dir)
# Run make update which handles all libraries and submodules.
make_update = os.path.join(builder.blender_dir, "build_files", "utils", "make_update.py")
buildbot_utils.call([sys.executable, make_update, '--no-blender', "--use-tests"])
# Run make update which handles all libraries and submodules.
make_update = os.path.join(blender_dir, "build_files", "utils", "make_update.py")
runpy.run_path(make_update)

View File

@@ -53,7 +53,7 @@ macro(BLENDER_SRC_GTEST_EX NAME SRC EXTRA_LIBS DO_ADD_TEST)
RUNTIME_OUTPUT_DIRECTORY_RELEASE "${TESTS_OUTPUT_DIR}"
RUNTIME_OUTPUT_DIRECTORY_DEBUG "${TESTS_OUTPUT_DIR}")
if(${DO_ADD_TEST})
add_test(NAME ${TARGET_NAME} COMMAND ${TESTS_OUTPUT_DIR}/${TARGET_NAME} WORKING_DIRECTORY ${TEST_INSTALL_DIR})
add_test(NAME ${TARGET_NAME} COMMAND ${TESTS_OUTPUT_DIR}/${TARGET_NAME} WORKING_DIRECTORY $<TARGET_FILE_DIR:blender>)
# Don't fail tests on leaks since these often happen in external libraries
# that we can't fix.

View File

@@ -719,7 +719,7 @@ macro(remove_strict_flags)
endif()
if(MSVC)
remove_cc_flag(/w34189) # Restore warn C4189 (unused variable) back to w4
remove_cc_flag(/w34189) # Restore warn C4189 (unused variable) back to w4
endif()
endmacro()

View File

@@ -322,6 +322,7 @@ endif()
if(WITH_LLVM)
set(LLVM_ROOT_DIR ${LIBDIR}/llvm)
set(LLVM_VERSION 3.4)
if(EXISTS "${LLVM_ROOT_DIR}/bin/llvm-config")
set(LLVM_CONFIG "${LLVM_ROOT_DIR}/bin/llvm-config")
else()
@@ -333,9 +334,6 @@ if(WITH_LLVM)
execute_process(COMMAND ${LLVM_CONFIG} --prefix
OUTPUT_VARIABLE LLVM_ROOT_DIR
OUTPUT_STRIP_TRAILING_WHITESPACE)
execute_process(COMMAND ${LLVM_CONFIG} --includedir
OUTPUT_VARIABLE LLVM_INCLUDE_DIRS
OUTPUT_STRIP_TRAILING_WHITESPACE)
execute_process(COMMAND ${LLVM_CONFIG} --libdir
OUTPUT_VARIABLE LLVM_LIBPATH
OUTPUT_STRIP_TRAILING_WHITESPACE)

View File

@@ -12,29 +12,33 @@ import shutil
import sys
import make_utils
from make_utils import call, check_output
from make_utils import call
# Parse arguments
def parse_arguments():
parser = argparse.ArgumentParser()
parser.add_argument("--only-code", action="store_true")
parser.add_argument("--svn-command", default="svn")
parser.add_argument("--git-command", default="git")
return parser.parse_args()
args = parse_arguments()
only_code = args.only_code
git_command = args.git_command
svn_command = args.svn_command
svn_non_interactive = [args.svn_command, '--non-interactive']
def print_stage(text):
print("")
print(text)
print("")
# Parse arguments
def parse_arguments():
parser = argparse.ArgumentParser()
parser.add_argument("--no-libraries", action="store_true")
parser.add_argument("--no-blender", action="store_true")
parser.add_argument("--no-submodules", action="store_true")
parser.add_argument("--use-tests", action="store_true")
parser.add_argument("--svn-command", default="svn")
parser.add_argument("--git-command", default="git")
return parser.parse_args()
# Test if we are building a specific release version.
release_version = make_utils.git_branch_release_version(git_command)
# Setup for precompiled libraries and tests from svn.
def svn_update(args, release_version):
svn_non_interactive = [args.svn_command, '--non-interactive']
if not only_code:
lib_dirpath = os.path.join('..', 'lib')
svn_url = make_utils.svn_libraries_base_url(release_version)
@@ -56,27 +60,13 @@ def svn_update(args, release_version):
if not os.path.exists(lib_platform_dirpath):
print_stage("Checking out Precompiled Libraries")
if shutil.which(args.svn_command) is None:
if shutil.which(svn_command) is None:
sys.stderr.write("svn not found, can't checkout libraries\n")
sys.exit(1)
svn_url_platform = svn_url + lib_platform
call(svn_non_interactive + ["checkout", svn_url_platform, lib_platform_dirpath])
if args.use_tests:
lib_tests = "tests"
lib_tests_dirpath = os.path.join(lib_dirpath, lib_tests)
if not os.path.exists(lib_tests_dirpath):
print_stage("Checking out Tests")
if shutil.which(args.svn_command) is None:
sys.stderr.write("svn not found, can't checkout tests\n")
sys.exit(1)
svn_url_tests = svn_url + lib_tests
call(svn_non_interactive + ["checkout", svn_url_tests, lib_tests_dirpath])
# Update precompiled libraries and tests
print_stage("Updating Precompiled Libraries and Tests")
@@ -91,7 +81,7 @@ def svn_update(args, release_version):
if os.path.isdir(dirpath) and \
(os.path.exists(svn_dirpath) or os.path.exists(svn_root_dirpath)):
if shutil.which(args.svn_command) is None:
if shutil.which(svn_command) is None:
sys.stderr.write("svn not found, can't update libraries\n")
sys.exit(1)
@@ -99,71 +89,19 @@ def svn_update(args, release_version):
call(svn_non_interactive + ["switch", svn_url + dirname, dirpath])
call(svn_non_interactive + ["update", dirpath])
# Update blender repository and submodules.
print_stage("Updating Blender Git Repository and Submodules")
# Update blender repository.
def blender_update_skip(args):
if shutil.which(args.git_command) is None:
sys.stderr.write("git not found, can't update code\n")
sys.exit(1)
if shutil.which(git_command) is None:
sys.stderr.write("git not found, can't update code\n")
sys.exit(1)
# Abort if a rebase is still progress.
rebase_merge = check_output([args.git_command, 'rev-parse', '--git-path', 'rebase-merge'])
rebase_apply = check_output([args.git_command, 'rev-parse', '--git-path', 'rebase-apply'])
merge_head = check_output([args.git_command, 'rev-parse', '--git-path', 'MERGE_HEAD'])
if os.path.exists(rebase_merge) or \
os.path.exists(rebase_apply) or \
os.path.exists(merge_head):
return "rebase or merge in progress, complete it first"
call([git_command, "pull", "--rebase"])
call([git_command, "submodule", "update", "--init", "--recursive"])
# Abort if uncommitted changes.
changes = check_output([args.git_command, 'status', '--porcelain', '--untracked-files=no'])
if len(changes) != 0:
return "you have unstaged changes"
# Test if there is an upstream branch configured
branch = check_output([args.git_command, "rev-parse", "--abbrev-ref", "HEAD"])
remote = check_output([args.git_command, "config", "branch." + branch + ".remote"], exit_on_error=False)
if len(remote) == 0:
return "no remote branch to pull from"
return None
def blender_update(args):
print_stage("Updating Blender Git Repository")
call([args.git_command, "pull", "--rebase"])
# Update submodules.
def submodules_update(args, release_version):
print_stage("Updating Submodules")
if shutil.which(args.git_command) is None:
sys.stderr.write("git not found, can't update code\n")
sys.exit(1)
call([args.git_command, "submodule", "update", "--init", "--recursive"])
if not release_version:
# Update submodules to latest master if not building a specific release.
# In that case submodules are set to a specific revision, which is checked
# out by running "git submodule update".
call([args.git_command, "submodule", "foreach", "git", "checkout", "master"])
call([args.git_command, "submodule", "foreach", "git", "pull", "--rebase", "origin", "master"])
if __name__ == "__main__":
args = parse_arguments()
blender_skipped = None
# Test if we are building a specific release version.
release_version = make_utils.git_branch_release_version(args.git_command)
if not args.no_libraries:
svn_update(args, release_version)
if not args.no_blender:
blender_skipped = blender_update_skip(args)
if not blender_skipped:
blender_update(args)
if not args.no_submodules:
submodules_update(args, release_version)
if blender_skipped:
print_stage("Blender repository skipped: " + blender_skipped)
if not release_version:
# Update submodules to latest master if not building a specific release.
# In that case submodules are set to a specific revision, which is checked
# out by running "git submodule update".
call([git_command, "submodule", "foreach", "git", "checkout", "master"])
call([git_command, "submodule", "foreach", "git", "pull", "--rebase", "origin", "master"])

View File

@@ -6,7 +6,7 @@ import re
import subprocess
import sys
def call(cmd, exit_on_error=True):
def call(cmd):
print(" ".join(cmd))
# Flush to ensure correct order output on Windows.
@@ -14,25 +14,8 @@ def call(cmd, exit_on_error=True):
sys.stderr.flush()
retcode = subprocess.call(cmd)
if exit_on_error and retcode != 0:
sys.exit(retcode)
return retcode
def check_output(cmd, exit_on_error=True):
# Flush to ensure correct order output on Windows.
sys.stdout.flush()
sys.stderr.flush()
try:
output = subprocess.check_output(cmd, stderr=subprocess.STDOUT, universal_newlines=True)
except subprocess.CalledProcessError as e:
if exit_on_error:
sys.stderr.write(" ".join(cmd))
sys.stderr.write(e.output + "\n")
sys.exit(e.returncode)
output = ""
return output.strip()
if retcode != 0:
sys.exit(retcode)
def git_branch_release_version(git_command):
# Test if we are building a specific release version.

View File

@@ -85,7 +85,7 @@ if NOT "%1" == "" (
set BUILD_UPDATE_ARGS=
) else if "%1" == "code_update" (
SET BUILD_UPDATE=1
set BUILD_UPDATE_ARGS="--no-libraries"
set BUILD_UPDATE_ARGS="--only-code"
) else if "%1" == "ninja" (
SET BUILD_WITH_NINJA=1
) else if "%1" == "clean" (

View File

@@ -35,7 +35,7 @@ class OBJECT_OT_evaluated_example(bpy.types.Operator):
# modifiers.
#
# For mesh objects the object.data will be a mesh with all modifiers applied.
# This means that in access to vertices or faces after modifier stack happens via fields of
# This means that in access to vertices or faces after modifier stack happens via fields of
# object_eval.object.
#
# For other types of objects the object_eval.data does not have modifiers applied on it,

View File

@@ -210,3 +210,4 @@ def unregister():
if __name__ == "__main__":
register()

View File

@@ -29,7 +29,6 @@ set(SRC
blender_shader.cpp
blender_sync.cpp
blender_texture.cpp
blender_viewport.cpp
CCL_api.h
blender_object_cull.h
@@ -37,7 +36,6 @@ set(SRC
blender_session.h
blender_texture.h
blender_util.h
blender_viewport.h
)
set(LIB

View File

@@ -151,44 +151,6 @@ enum_texture_limit = (
('8192', "8192", "Limit texture size to 8192 pixels", 7),
)
enum_view3d_shading_render_pass= (
('', "General", ""),
('COMBINED', "Combined", "Show the Combined Render pass", 1),
('EMISSION', "Emission", "Show the Emission render pass", 33),
('BACKGROUND', "Background", "Show the Background render pass", 34),
('AO', "Ambient Occlusion", "Show the Ambient Occlusion render pass", 35),
('', "Light", ""),
('DIFFUSE_DIRECT', "Diffuse Direct", "Show the Diffuse Direct render pass", 38),
('DIFFUSE_INDIRECT', "Diffuse Indirect", "Show the Diffuse Indirect render pass", 39),
('DIFFUSE_COLOR', "Diffuse Color", "Show the Diffuse Color render pass", 40),
('GLOSSY_DIRECT', "Glossy Direct", "Show the Glossy Direct render pass", 41),
('GLOSSY_INDIRECT', "Glossy Indirect", "Show the Glossy Indirect render pass", 42),
('GLOSSY_COLOR', "Glossy Color", "Show the Glossy Color render pass", 43),
('', "", ""),
('TRANSMISSION_DIRECT', "Transmission Direct", "Show the Transmission Direct render pass", 44),
('TRANSMISSION_INDIRECT', "Transmission Indirect", "Show the Transmission Indirect render pass", 45),
('TRANSMISSION_COLOR', "Transmission Color", "Show the Transmission Color render pass", 46),
('SUBSURFACE_DIRECT', "Subsurface Direct", "Show the Subsurface Direct render pass", 47),
('SUBSURFACE_INDIRECT', "Subsurface Indirect", "Show the Subsurface Indirect render pass", 48),
('SUBSURFACE_COLOR', "Subsurface Color", "Show the Subsurface Color render pass", 49),
('VOLUME_DIRECT', "Volume Direct", "Show the Volume Direct render pass", 50),
('VOLUME_INDIRECT', "Volume Indirect", "Show the Volume Indirect render pass", 51),
('', "Data", ""),
('NORMAL', "Normal", "Show the Normal render pass", 3),
('UV', "UV", "Show the UV render pass", 4),
('MIST', "Mist", "Show the Mist render pass", 32),
)
class CyclesRenderSettings(bpy.types.PropertyGroup):
@@ -1513,15 +1475,6 @@ class CyclesPreferences(bpy.types.AddonPreferences):
self.draw_impl(self.layout, context)
class CyclesView3DShadingSettings(bpy.types.PropertyGroup):
render_pass: EnumProperty(
name="Render Pass",
description="Render pass to show in the 3D Viewport",
items=enum_view3d_shading_render_pass,
default='COMBINED',
)
def register():
bpy.utils.register_class(CyclesRenderSettings)
bpy.utils.register_class(CyclesCameraSettings)
@@ -1535,12 +1488,6 @@ def register():
bpy.utils.register_class(CyclesDeviceSettings)
bpy.utils.register_class(CyclesPreferences)
bpy.utils.register_class(CyclesRenderLayerSettings)
bpy.utils.register_class(CyclesView3DShadingSettings)
bpy.types.View3DShading.cycles = bpy.props.PointerProperty(
name="Cycles Settings",
type=CyclesView3DShadingSettings,
)
def unregister():
@@ -1556,4 +1503,3 @@ def unregister():
bpy.utils.unregister_class(CyclesDeviceSettings)
bpy.utils.unregister_class(CyclesPreferences)
bpy.utils.unregister_class(CyclesRenderLayerSettings)
bpy.utils.unregister_class(CyclesView3DShadingSettings)

View File

@@ -2050,65 +2050,6 @@ class CYCLES_RENDER_PT_simplify_culling(CyclesButtonsPanel, Panel):
sub.prop(cscene, "distance_cull_margin", text="Distance")
class CYCLES_VIEW3D_PT_shading_render_pass(Panel):
bl_space_type = 'VIEW_3D'
bl_region_type = 'HEADER'
bl_label = "Render Pass"
bl_parent_id = 'VIEW3D_PT_shading'
COMPAT_ENGINES = {'CYCLES'}
@classmethod
def poll(cls, context):
return (context.engine in cls.COMPAT_ENGINES
and context.space_data.shading.type == 'RENDERED')
def draw(self, context):
shading = context.space_data.shading
layout = self.layout
layout.prop(shading.cycles, "render_pass", text="")
class CYCLES_VIEW3D_PT_shading_lighting(Panel):
bl_space_type = 'VIEW_3D'
bl_region_type = 'HEADER'
bl_label = "Lighting"
bl_parent_id = 'VIEW3D_PT_shading'
COMPAT_ENGINES = {'CYCLES'}
@classmethod
def poll(cls, context):
return (context.engine in cls.COMPAT_ENGINES
and context.space_data.shading.type == 'RENDERED')
def draw(self, context):
layout = self.layout
col = layout.column()
split = col.split(factor=0.9)
shading = context.space_data.shading
col.prop(shading, "use_scene_lights_render")
col.prop(shading, "use_scene_world_render")
if not shading.use_scene_world_render:
col = layout.column()
split = col.split(factor=0.9)
col = split.column()
sub = col.row()
sub.scale_y = 0.6
sub.template_icon_view(shading, "studio_light", scale_popup=3)
col = split.column()
col.operator("preferences.studiolight_show", emboss=False, text="", icon='PREFERENCES')
split = layout.split(factor=0.9)
col = split.column()
col.prop(shading, "studiolight_rotate_z", text="Rotation")
col.prop(shading, "studiolight_intensity")
col.prop(shading, "studiolight_background_alpha")
def draw_device(self, context):
scene = context.scene
layout = self.layout
@@ -2190,8 +2131,6 @@ classes = (
CYCLES_RENDER_PT_simplify_viewport,
CYCLES_RENDER_PT_simplify_render,
CYCLES_RENDER_PT_simplify_culling,
CYCLES_VIEW3D_PT_shading_lighting,
CYCLES_VIEW3D_PT_shading_render_pass,
CYCLES_RENDER_PT_motion_blur,
CYCLES_RENDER_PT_motion_blur_curve,
CYCLES_RENDER_PT_film,

View File

@@ -899,8 +899,6 @@ BufferParams BlenderSync::get_buffer_params(BL::RenderSettings &b_render,
params.height = height;
}
update_viewport_display_passes(b_v3d, params.passes, false);
return params;
}

View File

@@ -239,7 +239,7 @@ void BlenderSync::sync_light(BL::Object &b_parent,
light->tag_update(scene);
}
void BlenderSync::sync_background_light(BL::SpaceView3D &b_v3d, bool use_portal)
void BlenderSync::sync_background_light(bool use_portal)
{
BL::World b_world = b_scene.world();
@@ -283,7 +283,6 @@ void BlenderSync::sync_background_light(BL::SpaceView3D &b_v3d, bool use_portal)
world_map = b_world.ptr.data;
world_recalc = false;
viewport_parameters = BlenderViewportParameters(b_v3d);
}
/* Object */
@@ -294,7 +293,6 @@ Object *BlenderSync::sync_object(BL::Depsgraph &b_depsgraph,
float motion_time,
bool show_self,
bool show_particles,
bool show_lights,
BlenderObjectCulling &culling,
bool *use_portal)
{
@@ -313,10 +311,6 @@ Object *BlenderSync::sync_object(BL::Depsgraph &b_depsgraph,
/* light is handled separately */
if (!motion && object_is_light(b_ob)) {
if (!show_lights) {
return NULL;
}
/* TODO: don't use lights for excluded layers used as mask layer,
* when dynamic overrides are back. */
#if 0
@@ -513,9 +507,7 @@ Object *BlenderSync::sync_object(BL::Depsgraph &b_depsgraph,
/* Object Loop */
void BlenderSync::sync_objects(BL::Depsgraph &b_depsgraph,
BL::SpaceView3D &b_v3d,
float motion_time)
void BlenderSync::sync_objects(BL::Depsgraph &b_depsgraph, float motion_time)
{
/* layer data */
bool motion = motion_time != 0.0f;
@@ -538,7 +530,6 @@ void BlenderSync::sync_objects(BL::Depsgraph &b_depsgraph,
/* object loop */
bool cancel = false;
bool use_portal = false;
const bool show_lights = BlenderViewportParameters(b_v3d).use_scene_lights;
BL::ViewLayer b_view_layer = b_depsgraph.view_layer_eval();
@@ -564,7 +555,6 @@ void BlenderSync::sync_objects(BL::Depsgraph &b_depsgraph,
motion_time,
show_self,
show_particles,
show_lights,
culling,
&use_portal);
}
@@ -575,7 +565,7 @@ void BlenderSync::sync_objects(BL::Depsgraph &b_depsgraph,
progress.set_sync_status("");
if (!cancel && !motion) {
sync_background_light(b_v3d, use_portal);
sync_background_light(use_portal);
/* handle removed data and modified pointers */
if (light_map.post_sync())
@@ -594,7 +584,6 @@ void BlenderSync::sync_objects(BL::Depsgraph &b_depsgraph,
void BlenderSync::sync_motion(BL::RenderSettings &b_render,
BL::Depsgraph &b_depsgraph,
BL::SpaceView3D &b_v3d,
BL::Object &b_override,
int width,
int height,
@@ -632,7 +621,7 @@ void BlenderSync::sync_motion(BL::RenderSettings &b_render,
b_engine.frame_set(frame, subframe);
python_thread_state_save(python_thread_state);
sync_camera_motion(b_render, b_cam, width, height, 0.0f);
sync_objects(b_depsgraph, b_v3d, 0.0f);
sync_objects(b_depsgraph, 0.0f);
}
/* always sample these times for camera motion */
@@ -668,7 +657,7 @@ void BlenderSync::sync_motion(BL::RenderSettings &b_render,
}
/* sync object */
sync_objects(b_depsgraph, b_v3d, relative_time);
sync_objects(b_depsgraph, relative_time);
}
/* we need to set the python thread state again because this

View File

@@ -861,7 +861,7 @@ void BlenderSession::synchronize(BL::Depsgraph &b_depsgraph_)
/* copy recalc flags, outside of mutex so we can decide to do the real
* synchronization at a later time to not block on running updates */
sync->sync_recalc(b_depsgraph_, b_v3d);
sync->sync_recalc(b_depsgraph_);
/* don't do synchronization if on pause */
if (session_pause) {

View File

@@ -208,6 +208,24 @@ static void get_tex_mapping(TextureMapping *mapping, BL::TexMapping &b_mapping)
mapping->z_mapping = (TextureMapping::Mapping)b_mapping.mapping_z();
}
static void get_tex_mapping(TextureMapping *mapping, BL::ShaderNodeMapping &b_mapping)
{
if (!b_mapping)
return;
mapping->translation = get_float3(b_mapping.translation());
mapping->rotation = get_float3(b_mapping.rotation());
mapping->scale = get_float3(b_mapping.scale());
mapping->type = (TextureMapping::Type)b_mapping.vector_type();
mapping->use_minmax = b_mapping.use_min() || b_mapping.use_max();
if (b_mapping.use_min())
mapping->min = get_float3(b_mapping.min());
if (b_mapping.use_max())
mapping->max = get_float3(b_mapping.max());
}
static ShaderNode *add_node(Scene *scene,
BL::RenderEngine &b_engine,
BL::BlendData &b_data,
@@ -339,7 +357,9 @@ static ShaderNode *add_node(Scene *scene,
else if (b_node.is_a(&RNA_ShaderNodeMapping)) {
BL::ShaderNodeMapping b_mapping_node(b_node);
MappingNode *mapping = new MappingNode();
mapping->type = (NodeMappingType)b_mapping_node.vector_type();
get_tex_mapping(&mapping->tex_mapping, b_mapping_node);
node = mapping;
}
else if (b_node.is_a(&RNA_ShaderNodeFresnel)) {
@@ -778,19 +798,17 @@ static ShaderNode *add_node(Scene *scene,
else if (b_node.is_a(&RNA_ShaderNodeTexNoise)) {
BL::ShaderNodeTexNoise b_noise_node(b_node);
NoiseTextureNode *noise = new NoiseTextureNode();
noise->dimensions = b_noise_node.noise_dimensions();
BL::TexMapping b_texture_mapping(b_noise_node.texture_mapping());
get_tex_mapping(&noise->tex_mapping, b_texture_mapping);
node = noise;
}
else if (b_node.is_a(&RNA_ShaderNodeTexMusgrave)) {
BL::ShaderNodeTexMusgrave b_musgrave_node(b_node);
MusgraveTextureNode *musgrave_node = new MusgraveTextureNode();
musgrave_node->type = (NodeMusgraveType)b_musgrave_node.musgrave_type();
musgrave_node->dimensions = b_musgrave_node.musgrave_dimensions();
MusgraveTextureNode *musgrave = new MusgraveTextureNode();
musgrave->type = (NodeMusgraveType)b_musgrave_node.musgrave_type();
BL::TexMapping b_texture_mapping(b_musgrave_node.texture_mapping());
get_tex_mapping(&musgrave_node->tex_mapping, b_texture_mapping);
node = musgrave_node;
get_tex_mapping(&musgrave->tex_mapping, b_texture_mapping);
node = musgrave;
}
else if (b_node.is_a(&RNA_ShaderNodeTexCoord)) {
BL::ShaderNodeTexCoord b_tex_coord_node(b_node);
@@ -832,7 +850,7 @@ static ShaderNode *add_node(Scene *scene,
else if (b_node.is_a(&RNA_ShaderNodeTexWhiteNoise)) {
BL::ShaderNodeTexWhiteNoise b_tex_white_noise_node(b_node);
WhiteNoiseTextureNode *white_noise_node = new WhiteNoiseTextureNode();
white_noise_node->dimensions = b_tex_white_noise_node.noise_dimensions();
white_noise_node->dimensions = b_tex_white_noise_node.dimensions();
node = white_noise_node;
}
else if (b_node.is_a(&RNA_ShaderNodeNormalMap)) {
@@ -1165,10 +1183,8 @@ static void add_nodes(Scene *scene,
BL::NodeTree::links_iterator b_link;
for (b_ntree.links.begin(b_link); b_link != b_ntree.links.end(); ++b_link) {
/* Ignore invalid links to avoid unwanted cycles created in graph.
* Also ignore links with unavailable sockets. */
if (!(b_link->is_valid() && b_link->from_socket().enabled() &&
b_link->to_socket().enabled())) {
/* Ignore invalid links to avoid unwanted cycles created in graph. */
if (!b_link->is_valid()) {
continue;
}
/* get blender link data */
@@ -1298,23 +1314,19 @@ void BlenderSync::sync_materials(BL::Depsgraph &b_depsgraph, bool update_all)
/* Sync World */
void BlenderSync::sync_world(BL::Depsgraph &b_depsgraph, BL::SpaceView3D &b_v3d, bool update_all)
void BlenderSync::sync_world(BL::Depsgraph &b_depsgraph, bool update_all)
{
Background *background = scene->background;
Background prevbackground = *background;
BL::World b_world = b_scene.world();
BlenderViewportParameters new_viewport_parameters(b_v3d);
if (world_recalc || update_all || b_world.ptr.data != world_map ||
viewport_parameters.modified(new_viewport_parameters)) {
if (world_recalc || update_all || b_world.ptr.data != world_map) {
Shader *shader = scene->default_background;
ShaderGraph *graph = new ShaderGraph();
/* create nodes */
if (new_viewport_parameters.use_scene_world && b_world && b_world.use_nodes() &&
b_world.node_tree()) {
if (b_world && b_world.use_nodes() && b_world.node_tree()) {
BL::ShaderNodeTree b_ntree(b_world.node_tree());
add_nodes(scene, b_engine, b_data, b_depsgraph, b_scene, graph, b_ntree);
@@ -1325,7 +1337,7 @@ void BlenderSync::sync_world(BL::Depsgraph &b_depsgraph, BL::SpaceView3D &b_v3d,
shader->volume_sampling_method = get_volume_sampling(cworld);
shader->volume_interpolation_method = get_volume_interpolation(cworld);
}
else if (new_viewport_parameters.use_scene_world && b_world) {
else if (b_world) {
BackgroundNode *background = new BackgroundNode();
background->color = get_float3(b_world.color());
graph->add(background);
@@ -1333,53 +1345,6 @@ void BlenderSync::sync_world(BL::Depsgraph &b_depsgraph, BL::SpaceView3D &b_v3d,
ShaderNode *out = graph->output();
graph->connect(background->output("Background"), out->input("Surface"));
}
else if (!new_viewport_parameters.use_scene_world) {
BackgroundNode *background = new BackgroundNode();
graph->add(background);
LightPathNode *light_path = new LightPathNode();
graph->add(light_path);
MixNode *mix_scene_with_background = new MixNode();
mix_scene_with_background->color2 = get_float3(b_world.color());
graph->add(mix_scene_with_background);
EnvironmentTextureNode *texture_environment = new EnvironmentTextureNode();
texture_environment->tex_mapping.type = TextureMapping::VECTOR;
texture_environment->tex_mapping.rotation[2] = new_viewport_parameters.studiolight_rotate_z;
texture_environment->filename = new_viewport_parameters.studiolight_path;
graph->add(texture_environment);
MixNode *mix_intensity = new MixNode();
mix_intensity->type = NODE_MIX_MUL;
mix_intensity->fac = 1.0f;
mix_intensity->color2 = make_float3(new_viewport_parameters.studiolight_intensity,
new_viewport_parameters.studiolight_intensity,
new_viewport_parameters.studiolight_intensity);
graph->add(mix_intensity);
TextureCoordinateNode *texture_coordinate = new TextureCoordinateNode();
graph->add(texture_coordinate);
MixNode *mix_background_with_environment = new MixNode();
mix_background_with_environment->fac = new_viewport_parameters.studiolight_background_alpha;
mix_background_with_environment->color1 = get_float3(b_world.color());
graph->add(mix_background_with_environment);
ShaderNode *out = graph->output();
graph->connect(texture_coordinate->output("Generated"),
texture_environment->input("Vector"));
graph->connect(texture_environment->output("Color"), mix_intensity->input("Color1"));
graph->connect(light_path->output("Is Camera Ray"), mix_scene_with_background->input("Fac"));
graph->connect(mix_intensity->output("Color"), mix_scene_with_background->input("Color1"));
graph->connect(mix_intensity->output("Color"),
mix_background_with_environment->input("Color2"));
graph->connect(mix_background_with_environment->output("Color"),
mix_scene_with_background->input("Color2"));
graph->connect(mix_scene_with_background->output("Color"), background->input("Color"));
graph->connect(background->output("Background"), out->input("Surface"));
}
if (b_world) {
/* AO */
@@ -1424,8 +1389,7 @@ void BlenderSync::sync_world(BL::Depsgraph &b_depsgraph, BL::SpaceView3D &b_v3d,
background->transparent_roughness_threshold = 0.0f;
}
background->use_shader = view_layer.use_background_shader |
viewport_parameters.custom_viewport_parameters();
background->use_shader = view_layer.use_background_shader;
background->use_ao = background->use_ao && view_layer.use_background_ao;
if (background->modified(prevbackground))
@@ -1475,7 +1439,7 @@ void BlenderSync::sync_lights(BL::Depsgraph &b_depsgraph, bool update_all)
}
}
void BlenderSync::sync_shaders(BL::Depsgraph &b_depsgraph, BL::SpaceView3D &b_v3d)
void BlenderSync::sync_shaders(BL::Depsgraph &b_depsgraph)
{
/* for auto refresh images */
bool auto_refresh_update = false;
@@ -1488,7 +1452,7 @@ void BlenderSync::sync_shaders(BL::Depsgraph &b_depsgraph, BL::SpaceView3D &b_v3
shader_map.pre_sync();
sync_world(b_depsgraph, b_v3d, auto_refresh_update);
sync_world(b_depsgraph, auto_refresh_update);
sync_lights(b_depsgraph, auto_refresh_update);
sync_materials(b_depsgraph, auto_refresh_update);
}

View File

@@ -80,7 +80,7 @@ BlenderSync::~BlenderSync()
/* Sync */
void BlenderSync::sync_recalc(BL::Depsgraph &b_depsgraph, BL::SpaceView3D &b_v3d)
void BlenderSync::sync_recalc(BL::Depsgraph &b_depsgraph)
{
/* Sync recalc flags from blender to cycles. Actual update is done separate,
* so we can do it later on if doing it immediate is not suitable. */
@@ -175,11 +175,6 @@ void BlenderSync::sync_recalc(BL::Depsgraph &b_depsgraph, BL::SpaceView3D &b_v3d
}
}
BlenderViewportParameters new_viewport_parameters(b_v3d);
if (viewport_parameters.modified(new_viewport_parameters)) {
world_recalc = true;
}
/* Updates shader with object dependency if objects changed. */
if (has_updated_objects) {
if (scene->default_background->has_object_dependency) {
@@ -206,8 +201,8 @@ void BlenderSync::sync_data(BL::RenderSettings &b_render,
sync_view_layer(b_v3d, b_view_layer);
sync_integrator();
sync_film(b_v3d);
sync_shaders(b_depsgraph, b_v3d);
sync_film();
sync_shaders(b_depsgraph);
sync_images();
sync_curve_settings();
@@ -215,9 +210,9 @@ void BlenderSync::sync_data(BL::RenderSettings &b_render,
if (scene->need_motion() == Scene::MOTION_PASS || scene->need_motion() == Scene::MOTION_NONE ||
scene->camera->motion_position == Camera::MOTION_POSITION_CENTER) {
sync_objects(b_depsgraph, b_v3d);
sync_objects(b_depsgraph);
}
sync_motion(b_render, b_depsgraph, b_v3d, b_override, width, height, python_thread_state);
sync_motion(b_render, b_depsgraph, b_override, width, height, python_thread_state);
mesh_synced.clear();
@@ -336,17 +331,13 @@ void BlenderSync::sync_integrator()
/* Film */
void BlenderSync::sync_film(BL::SpaceView3D &b_v3d)
void BlenderSync::sync_film()
{
PointerRNA cscene = RNA_pointer_get(&b_scene.ptr, "cycles");
Film *film = scene->film;
Film prevfilm = *film;
if (b_v3d) {
film->display_pass = update_viewport_display_passes(b_v3d, film->passes, true);
}
film->exposure = get_float(cscene, "film_exposure");
film->filter_type = (FilterType)get_enum(
cscene, "pixel_filter_type", FILTER_NUM_TYPES, FILTER_BLACKMAN_HARRIS);
@@ -372,10 +363,8 @@ void BlenderSync::sync_film(BL::SpaceView3D &b_v3d)
}
}
if (film->modified(prevfilm)) {
if (film->modified(prevfilm))
film->tag_update(scene);
film->tag_passes_update(scene, prevfilm.passes, false);
}
}
/* Render Layer */

View File

@@ -23,7 +23,6 @@
#include "RNA_blender_cpp.h"
#include "blender/blender_util.h"
#include "blender/blender_viewport.h"
#include "render/scene.h"
#include "render/session.h"
@@ -37,7 +36,6 @@ CCL_NAMESPACE_BEGIN
class Background;
class BlenderObjectCulling;
class BlenderViewportParameters;
class Camera;
class Film;
class Light;
@@ -61,7 +59,7 @@ class BlenderSync {
~BlenderSync();
/* sync */
void sync_recalc(BL::Depsgraph &b_depsgraph, BL::SpaceView3D &b_v3d);
void sync_recalc(BL::Depsgraph &b_depsgraph);
void sync_data(BL::RenderSettings &b_render,
BL::Depsgraph &b_depsgraph,
BL::SpaceView3D &b_v3d,
@@ -108,18 +106,17 @@ class BlenderSync {
/* sync */
void sync_lights(BL::Depsgraph &b_depsgraph, bool update_all);
void sync_materials(BL::Depsgraph &b_depsgraph, bool update_all);
void sync_objects(BL::Depsgraph &b_depsgraph, BL::SpaceView3D &b_v3d, float motion_time = 0.0f);
void sync_objects(BL::Depsgraph &b_depsgraph, float motion_time = 0.0f);
void sync_motion(BL::RenderSettings &b_render,
BL::Depsgraph &b_depsgraph,
BL::SpaceView3D &b_v3d,
BL::Object &b_override,
int width,
int height,
void **python_thread_state);
void sync_film(BL::SpaceView3D &b_v3d);
void sync_film();
void sync_view();
void sync_world(BL::Depsgraph &b_depsgraph, BL::SpaceView3D &b_v3d, bool update_all);
void sync_shaders(BL::Depsgraph &b_depsgraph, BL::SpaceView3D &b_v3d);
void sync_world(BL::Depsgraph &b_depsgraph, bool update_all);
void sync_shaders(BL::Depsgraph &b_depsgraph);
void sync_curve_settings();
void sync_nodes(Shader *shader, BL::ShaderNodeTree &b_ntree);
@@ -137,7 +134,6 @@ class BlenderSync {
float motion_time,
bool show_self,
bool show_particles,
bool show_lights,
BlenderObjectCulling &culling,
bool *use_portal);
void sync_light(BL::Object &b_parent,
@@ -147,7 +143,7 @@ class BlenderSync {
int random_id,
Transform &tfm,
bool *use_portal);
void sync_background_light(BL::SpaceView3D &b_v3d, bool use_portal);
void sync_background_light(bool use_portal);
void sync_mesh_motion(BL::Depsgraph &b_depsgraph,
BL::Object &b_ob,
Object *object,
@@ -187,7 +183,6 @@ class BlenderSync {
set<float> motion_times;
void *world_map;
bool world_recalc;
BlenderViewportParameters viewport_parameters;
Scene *scene;
bool preview;

View File

@@ -1,98 +0,0 @@
/*
* Copyright 2019 Blender Foundation
*
* 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* 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.
*/
#include "blender_viewport.h"
#include "blender_util.h"
CCL_NAMESPACE_BEGIN
BlenderViewportParameters::BlenderViewportParameters()
: use_scene_world(true),
use_scene_lights(true),
studiolight_rotate_z(0.0f),
studiolight_intensity(1.0f),
studiolight_background_alpha(1.0f),
studiolight_path(ustring())
{
}
BlenderViewportParameters::BlenderViewportParameters(BL::SpaceView3D &b_v3d)
: BlenderViewportParameters()
{
/* We only copy the parameters if we are in look dev mode. otherwise
* defaults are being used. These defaults mimic normal render settings */
if (b_v3d && b_v3d.shading().type() == BL::View3DShading::type_RENDERED) {
use_scene_world = b_v3d.shading().use_scene_world_render();
use_scene_lights = b_v3d.shading().use_scene_lights_render();
if (!use_scene_world) {
studiolight_rotate_z = b_v3d.shading().studiolight_rotate_z();
studiolight_intensity = b_v3d.shading().studiolight_intensity();
studiolight_background_alpha = b_v3d.shading().studiolight_background_alpha();
studiolight_path = b_v3d.shading().selected_studio_light().path();
}
}
}
/* Check if two instances are different. */
const bool BlenderViewportParameters::modified(const BlenderViewportParameters &other) const
{
return use_scene_world != other.use_scene_world || use_scene_lights != other.use_scene_lights ||
studiolight_rotate_z != other.studiolight_rotate_z ||
studiolight_intensity != other.studiolight_intensity ||
studiolight_background_alpha != other.studiolight_background_alpha ||
studiolight_path != other.studiolight_path;
}
const bool BlenderViewportParameters::custom_viewport_parameters() const
{
return !(use_scene_world && use_scene_lights);
}
PassType BlenderViewportParameters::get_viewport_display_render_pass(BL::SpaceView3D &b_v3d)
{
PassType display_pass = PASS_NONE;
if (b_v3d) {
BL::View3DShading b_view3dshading = b_v3d.shading();
PointerRNA cshading = RNA_pointer_get(&b_view3dshading.ptr, "cycles");
display_pass = (PassType)get_enum(cshading, "render_pass", -1, -1);
}
return display_pass;
}
PassType update_viewport_display_passes(BL::SpaceView3D &b_v3d,
vector<Pass> &passes,
bool reset_passes)
{
if (b_v3d) {
PassType display_pass = BlenderViewportParameters::get_viewport_display_render_pass(b_v3d);
if (reset_passes) {
passes.clear();
/* We always need a combined pass for now. It would be a good optimization
* to support rendering without combined pass. */
Pass::add(PASS_COMBINED, passes);
}
if (display_pass != PASS_COMBINED) {
Pass::add(display_pass, passes);
}
return display_pass;
}
return PASS_NONE;
}
CCL_NAMESPACE_END

View File

@@ -1,58 +0,0 @@
/*
* Copyright 2019 Blender Foundation
*
* 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* 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.
*/
#ifndef __BLENDER_VIEWPORT_H__
#define __BLENDER_VIEWPORT_H__
#include "MEM_guardedalloc.h"
#include "RNA_types.h"
#include "RNA_access.h"
#include "RNA_blender_cpp.h"
#include "render/film.h"
#include "util/util_param.h"
CCL_NAMESPACE_BEGIN
class BlenderViewportParameters {
private:
bool use_scene_world;
bool use_scene_lights;
float studiolight_rotate_z;
float studiolight_intensity;
float studiolight_background_alpha;
ustring studiolight_path;
BlenderViewportParameters();
BlenderViewportParameters(BL::SpaceView3D &b_v3d);
const bool modified(const BlenderViewportParameters &other) const;
const bool custom_viewport_parameters() const;
friend class BlenderSync;
public:
/* Retrieve the render pass that needs to be displayed on the given `SpaceView3D`
* When the `b_v3d` parameter is not given `PASS_NONE` will be returned. */
static PassType get_viewport_display_render_pass(BL::SpaceView3D &b_v3d);
};
PassType update_viewport_display_passes(BL::SpaceView3D &b_v3d,
vector<Pass> &passes,
bool reset_passes);
CCL_NAMESPACE_END
#endif

View File

@@ -201,7 +201,6 @@ set(SRC_SVM_HEADERS
svm/svm_magic.h
svm/svm_map_range.h
svm/svm_mapping.h
svm/svm_mapping_util.h
svm/svm_math.h
svm/svm_math_util.h
svm/svm_mix.h
@@ -215,7 +214,7 @@ set(SRC_SVM_HEADERS
svm/svm_sepcomb_vector.h
svm/svm_sky.h
svm/svm_tex_coord.h
svm/svm_fractal_noise.h
svm/svm_texture.h
svm/svm_types.h
svm/svm_value.h
svm/svm_vector_transform.h

View File

@@ -73,28 +73,6 @@ ccl_device_inline float bsdf_get_roughness_squared(const ShaderClosure *sc)
return bsdf_get_specular_roughness_squared(sc);
}
/* An additional term to smooth illumination on grazing angles when using bump mapping.
* Based on "Taming the Shadow Terminator" by Matt Jen-Yuan Chiang,
* Yining Karl Li and Brent Burley. */
ccl_device_inline float bump_shadowing_term(float3 Ng, float3 N, float3 I)
{
float g = safe_divide(dot(Ng, I), dot(N, I) * dot(Ng, N));
/* If the incoming light is on the unshadowed side, return full brightness. */
if (g >= 1.0f) {
return 1.0f;
}
/* If the incoming light points away from the surface, return black. */
if (g < 0.0f) {
return 0.0f;
}
/* Return smoothed value to avoid discontinuity at perpendicular angle. */
float g2 = sqr(g);
return -g2 * g + g2 + g;
}
ccl_device_inline int bsdf_sample(KernelGlobals *kg,
ShaderData *sd,
const ShaderClosure *sc,
@@ -446,11 +424,6 @@ ccl_device_inline int bsdf_sample(KernelGlobals *kg,
}
}
}
else if (label & LABEL_DIFFUSE) {
if (!isequal_float3(sc->N, sd->N)) {
*eval *= bump_shadowing_term((label & LABEL_TRANSMIT) ? -sd->N : sd->N, sc->N, *omega_in);
}
}
return label;
}
@@ -562,11 +535,6 @@ ccl_device_inline
eval = make_float3(0.0f, 0.0f, 0.0f);
break;
}
if (CLOSURE_IS_BSDF_DIFFUSE(sc->type)) {
if (!isequal_float3(sc->N, sd->N)) {
eval *= bump_shadowing_term(sd->N, sc->N, omega_in);
}
}
}
else {
switch (sc->type) {
@@ -653,11 +621,6 @@ ccl_device_inline
eval = make_float3(0.0f, 0.0f, 0.0f);
break;
}
if (CLOSURE_IS_BSDF_DIFFUSE(sc->type)) {
if (!isequal_float3(sc->N, sd->N)) {
eval *= bump_shadowing_term(-sd->N, sc->N, omega_in);
}
}
}
return eval;

View File

@@ -16,66 +16,18 @@
CCL_NAMESPACE_BEGIN
ccl_device float4 film_get_pass_result(KernelGlobals *kg,
ccl_global float *buffer,
float sample_scale,
int index,
bool use_display_sample_scale)
ccl_device float4 film_map(KernelGlobals *kg, float4 irradiance, float scale)
{
float4 pass_result;
int display_pass_stride = kernel_data.film.display_pass_stride;
int display_pass_components = kernel_data.film.display_pass_components;
if (display_pass_components == 4) {
ccl_global float4 *in = (ccl_global float4 *)(buffer + display_pass_stride +
index * kernel_data.film.pass_stride);
float alpha = use_display_sample_scale ?
(kernel_data.film.use_display_pass_alpha ? in->w : 1.0f / sample_scale) :
1.0f;
pass_result = make_float4(in->x, in->y, in->z, alpha);
int display_divide_pass_stride = kernel_data.film.display_divide_pass_stride;
if (display_divide_pass_stride != -1) {
ccl_global float4 *divide_in = (ccl_global float4 *)(buffer + display_divide_pass_stride +
index * kernel_data.film.pass_stride);
if (divide_in->x != 0.0f) {
pass_result.x /= divide_in->x;
}
if (divide_in->y != 0.0f) {
pass_result.y /= divide_in->y;
}
if (divide_in->z != 0.0f) {
pass_result.z /= divide_in->z;
}
}
if (kernel_data.film.use_display_exposure) {
float exposure = kernel_data.film.exposure;
pass_result *= make_float4(exposure, exposure, exposure, alpha);
}
}
else if (display_pass_components == 1) {
ccl_global float *in = (ccl_global float *)(buffer + display_pass_stride +
index * kernel_data.film.pass_stride);
pass_result = make_float4(*in, *in, *in, 1.0f / sample_scale);
}
return pass_result;
}
ccl_device float4 film_map(KernelGlobals *kg, float4 rgba_in, float scale)
{
float4 result;
float exposure = kernel_data.film.exposure;
float4 result = irradiance * scale;
/* conversion to srgb */
result.x = color_linear_to_srgb(rgba_in.x);
result.y = color_linear_to_srgb(rgba_in.y);
result.z = color_linear_to_srgb(rgba_in.z);
result.x = color_linear_to_srgb(result.x * exposure);
result.y = color_linear_to_srgb(result.y * exposure);
result.z = color_linear_to_srgb(result.z * exposure);
/* clamp since alpha might be > 1.0 due to russian roulette */
result.w = saturate(rgba_in.w);
result.w = saturate(result.w);
return result;
}
@@ -105,22 +57,15 @@ ccl_device void kernel_film_convert_to_byte(KernelGlobals *kg,
/* buffer offset */
int index = offset + x + y * stride;
bool use_display_sample_scale = (kernel_data.film.display_divide_pass_stride == -1);
float4 rgba_in = film_get_pass_result(kg, buffer, sample_scale, index, use_display_sample_scale);
rgba += index;
buffer += index * kernel_data.film.pass_stride;
/* map colors */
if (use_display_sample_scale) {
float4 float_result = film_map(kg, rgba_in, sample_scale);
uchar4 byte_result = film_float_to_byte(float_result);
*rgba = byte_result;
}
else {
float4 float_result = film_map(kg, rgba_in, 1.0);
uchar4 byte_result = film_float_to_byte(float_result);
*rgba = byte_result;
}
float4 irradiance = *((ccl_global float4 *)buffer);
float4 float_result = film_map(kg, irradiance, sample_scale);
uchar4 byte_result = film_float_to_byte(float_result);
*rgba = byte_result;
}
ccl_device void kernel_film_convert_to_half_float(KernelGlobals *kg,
@@ -134,16 +79,21 @@ ccl_device void kernel_film_convert_to_half_float(KernelGlobals *kg,
{
/* buffer offset */
int index = offset + x + y * stride;
bool use_display_sample_scale = (kernel_data.film.display_divide_pass_stride == -1);
float4 rgba_in = film_get_pass_result(kg, buffer, sample_scale, index, use_display_sample_scale);
ccl_global float4 *in = (ccl_global float4 *)(buffer + index * kernel_data.film.pass_stride);
ccl_global half *out = (ccl_global half *)rgba + index * 4;
if (use_display_sample_scale) {
float4_store_half(out, rgba_in, sample_scale);
}
else {
float4_store_half(out, rgba_in, 1.0f);
float exposure = kernel_data.film.exposure;
float4 rgba_in = *in;
if (exposure != 1.0f) {
rgba_in.x *= exposure;
rgba_in.y *= exposure;
rgba_in.z *= exposure;
}
float4_store_half(out, rgba_in, sample_scale);
}
CCL_NAMESPACE_END

View File

@@ -1168,7 +1168,6 @@ static_assert_align(KernelCamera, 16);
typedef struct KernelFilm {
float exposure;
int pass_flag;
int light_pass_flag;
int pass_stride;
int use_light_pass;
@@ -1234,13 +1233,6 @@ typedef struct KernelFilm {
int pass_bvh_intersections;
int pass_ray_bounces;
#endif
/* viewport rendering options */
int display_pass_stride;
int display_pass_components;
int display_divide_pass_stride;
int use_display_exposure;
int use_display_pass_alpha;
} KernelFilm;
static_assert_align(KernelFilm, 16);

View File

@@ -97,12 +97,10 @@ set(SRC_OSL
set(SRC_OSL_HEADERS
node_color.h
node_fresnel.h
node_noise.h
node_ramp_util.h
node_texture.h
stdosl.h
oslutil.h
vector2.h
vector4.h
)
set(SRC_OSO

View File

@@ -15,6 +15,7 @@
*/
#include "stdosl.h"
#include "node_texture.h"
/* Brick */

View File

@@ -15,6 +15,7 @@
*/
#include "stdosl.h"
#include "node_texture.h"
/* Checker */

View File

@@ -15,6 +15,7 @@
*/
#include "stdosl.h"
#include "node_texture.h"
/* Gradient */

View File

@@ -15,6 +15,7 @@
*/
#include "stdosl.h"
#include "node_texture.h"
/* IES Light */

View File

@@ -15,6 +15,7 @@
*/
#include "stdosl.h"
#include "node_texture.h"
/* Magic */

View File

@@ -16,58 +16,17 @@
#include "stdosl.h"
point safe_divide(point a, point b)
{
return point((b[0] != 0.0) ? a[0] / b[0] : 0.0,
(b[1] != 0.0) ? a[1] / b[1] : 0.0,
(b[2] != 0.0) ? a[2] / b[2] : 0.0);
}
matrix euler_to_mat(point euler)
{
float cx = cos(euler[0]);
float cy = cos(euler[1]);
float cz = cos(euler[2]);
float sx = sin(euler[0]);
float sy = sin(euler[1]);
float sz = sin(euler[2]);
matrix mat = matrix(1.0);
mat[0][0] = cy * cz;
mat[0][1] = cy * sz;
mat[0][2] = -sy;
mat[1][0] = sy * sx * cz - cx * sz;
mat[1][1] = sy * sx * sz + cx * cz;
mat[1][2] = cy * sx;
mat[2][0] = sy * cx * cz + sx * sz;
mat[2][1] = sy * cx * sz - sx * cz;
mat[2][2] = cy * cx;
return mat;
}
shader node_mapping(string type = "point",
shader node_mapping(matrix Matrix = matrix(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
point mapping_min = point(0.0, 0.0, 0.0),
point mapping_max = point(0.0, 0.0, 0.0),
int use_minmax = 0,
point VectorIn = point(0.0, 0.0, 0.0),
point Location = point(0.0, 0.0, 0.0),
point Rotation = point(0.0, 0.0, 0.0),
point Scale = point(1.0, 1.0, 1.0),
output point VectorOut = point(0.0, 0.0, 0.0))
{
if (type == "point") {
VectorOut = transform(euler_to_mat(Rotation), (VectorIn * Scale)) + Location;
}
else if (type == "texture") {
VectorOut = safe_divide(transform(transpose(euler_to_mat(Rotation)), (VectorIn - Location)),
Scale);
}
else if (type == "vector") {
VectorOut = transform(euler_to_mat(Rotation), (VectorIn * Scale));
}
else if (type == "normal") {
VectorOut = normalize(transform(euler_to_mat(Rotation), safe_divide(VectorIn, Scale)));
}
else {
warning("%s", "Unknown Mapping vector type!");
}
point p = transform(Matrix, VectorIn);
if (use_minmax)
p = min(max(mapping_min, p), mapping_max);
VectorOut = p;
}

View File

@@ -15,13 +15,9 @@
*/
#include "stdosl.h"
#include "node_noise.h"
#include "vector2.h"
#include "vector4.h"
#include "node_texture.h"
#define vector3 point
/* 1D Musgrave fBm
/* Musgrave fBm
*
* H: fractal increment parameter
* lacunarity: gap between successive frequencies
@@ -30,56 +26,58 @@
* from "Texturing and Modelling: A procedural approach"
*/
float noise_musgrave_fBm_1d(float co, float H, float lacunarity, float octaves)
float noise_musgrave_fBm(point ip, float H, float lacunarity, float octaves)
{
float p = co;
float rmd;
float value = 0.0;
float pwr = 1.0;
float pwHL = pow(lacunarity, -H);
int i;
point p = ip;
for (int i = 0; i < (int)octaves; i++) {
value += safe_snoise(p) * pwr;
for (i = 0; i < (int)octaves; i++) {
value += safe_noise(p, "signed") * pwr;
pwr *= pwHL;
p *= lacunarity;
}
float rmd = octaves - floor(octaves);
if (rmd != 0.0) {
value += rmd * safe_snoise(p) * pwr;
}
rmd = octaves - floor(octaves);
if (rmd != 0.0)
value += rmd * safe_noise(p, "signed") * pwr;
return value;
}
/* 1D Musgrave Multifractal
/* Musgrave Multifractal
*
* H: highest fractal dimension
* lacunarity: gap between successive frequencies
* octaves: number of frequencies in the fBm
*/
float noise_musgrave_multi_fractal_1d(float co, float H, float lacunarity, float octaves)
float noise_musgrave_multi_fractal(point ip, float H, float lacunarity, float octaves)
{
float p = co;
float rmd;
float value = 1.0;
float pwr = 1.0;
float pwHL = pow(lacunarity, -H);
int i;
point p = ip;
for (int i = 0; i < (int)octaves; i++) {
value *= (pwr * safe_snoise(p) + 1.0);
for (i = 0; i < (int)octaves; i++) {
value *= (pwr * safe_noise(p, "signed") + 1.0);
pwr *= pwHL;
p *= lacunarity;
}
float rmd = octaves - floor(octaves);
if (rmd != 0.0) {
value *= (rmd * pwr * safe_snoise(p) + 1.0); /* correct? */
}
rmd = octaves - floor(octaves);
if (rmd != 0.0)
value *= (rmd * pwr * safe_noise(p, "signed") + 1.0); /* correct? */
return value;
}
/* 1D Musgrave Heterogeneous Terrain
/* Musgrave Heterogeneous Terrain
*
* H: fractal dimension of the roughest area
* lacunarity: gap between successive frequencies
@@ -87,34 +85,36 @@ float noise_musgrave_multi_fractal_1d(float co, float H, float lacunarity, float
* offset: raises the terrain from `sea level'
*/
float noise_musgrave_hetero_terrain_1d(
float co, float H, float lacunarity, float octaves, float offset)
float noise_musgrave_hetero_terrain(
point ip, float H, float lacunarity, float octaves, float offset)
{
float p = co;
float value, increment, rmd;
float pwHL = pow(lacunarity, -H);
float pwr = pwHL;
int i;
point p = ip;
/* first unscaled octave of function; later octaves are scaled */
float value = offset + safe_snoise(p);
value = offset + safe_noise(p, "signed");
p *= lacunarity;
for (int i = 1; i < (int)octaves; i++) {
float increment = (safe_snoise(p) + offset) * pwr * value;
for (i = 1; i < (int)octaves; i++) {
increment = (safe_noise(p, "signed") + offset) * pwr * value;
value += increment;
pwr *= pwHL;
p *= lacunarity;
}
float rmd = octaves - floor(octaves);
rmd = octaves - floor(octaves);
if (rmd != 0.0) {
float increment = (safe_snoise(p) + offset) * pwr * value;
increment = (safe_noise(p, "signed") + offset) * pwr * value;
value += rmd * increment;
}
return value;
}
/* 1D Hybrid Additive/Multiplicative Multifractal Terrain
/* Hybrid Additive/Multiplicative Multifractal Terrain
*
* H: fractal dimension of the roughest area
* lacunarity: gap between successive frequencies
@@ -122,38 +122,38 @@ float noise_musgrave_hetero_terrain_1d(
* offset: raises the terrain from `sea level'
*/
float noise_musgrave_hybrid_multi_fractal_1d(
float co, float H, float lacunarity, float octaves, float offset, float gain)
float noise_musgrave_hybrid_multi_fractal(
point ip, float H, float lacunarity, float octaves, float offset, float gain)
{
float p = co;
float result, signal, weight, rmd;
float pwHL = pow(lacunarity, -H);
float pwr = pwHL;
int i;
point p = ip;
float value = safe_snoise(p) + offset;
float weight = gain * value;
result = safe_noise(p, "signed") + offset;
weight = gain * result;
p *= lacunarity;
for (int i = 1; (weight > 0.001) && (i < (int)octaves); i++) {
if (weight > 1.0) {
for (i = 1; (weight > 0.001) && (i < (int)octaves); i++) {
if (weight > 1.0)
weight = 1.0;
}
float signal = (safe_snoise(p) + offset) * pwr;
signal = (safe_noise(p, "signed") + offset) * pwr;
pwr *= pwHL;
value += weight * signal;
result += weight * signal;
weight *= gain * signal;
p *= lacunarity;
}
float rmd = octaves - floor(octaves);
if (rmd != 0.0) {
value += rmd * ((safe_snoise(p) + offset) * pwr);
}
rmd = octaves - floor(octaves);
if (rmd != 0.0)
result += rmd * ((safe_noise(p, "signed") + offset) * pwr);
return value;
return result;
}
/* 1D Ridged Multifractal Terrain
/* Ridged Multifractal Terrain
*
* H: fractal dimension of the roughest area
* lacunarity: gap between successive frequencies
@@ -161,643 +161,73 @@ float noise_musgrave_hybrid_multi_fractal_1d(
* offset: raises the terrain from `sea level'
*/
float noise_musgrave_ridged_multi_fractal_1d(
float co, float H, float lacunarity, float octaves, float offset, float gain)
float noise_musgrave_ridged_multi_fractal(
point ip, float H, float lacunarity, float octaves, float offset, float gain)
{
float p = co;
float result, signal, weight;
float pwHL = pow(lacunarity, -H);
float pwr = pwHL;
int i;
point p = ip;
float signal = offset - fabs(safe_snoise(p));
signal = offset - fabs(safe_noise(p, "signed"));
signal *= signal;
float value = signal;
float weight = 1.0;
result = signal;
weight = 1.0;
for (int i = 1; i < (int)octaves; i++) {
for (i = 1; i < (int)octaves; i++) {
p *= lacunarity;
weight = clamp(signal * gain, 0.0, 1.0);
signal = offset - fabs(safe_snoise(p));
signal = offset - fabs(safe_noise(p, "signed"));
signal *= signal;
signal *= weight;
value += signal * pwr;
result += signal * pwr;
pwr *= pwHL;
}
return value;
return result;
}
/* 2D Musgrave fBm
*
* H: fractal increment parameter
* lacunarity: gap between successive frequencies
* octaves: number of frequencies in the fBm
*
* from "Texturing and Modelling: A procedural approach"
*/
float noise_musgrave_fBm_2d(vector2 co, float H, float lacunarity, float octaves)
{
vector2 p = co;
float value = 0.0;
float pwr = 1.0;
float pwHL = pow(lacunarity, -H);
for (int i = 0; i < (int)octaves; i++) {
value += safe_snoise(p) * pwr;
pwr *= pwHL;
p *= lacunarity;
}
float rmd = octaves - floor(octaves);
if (rmd != 0.0) {
value += rmd * safe_snoise(p) * pwr;
}
return value;
}
/* 2D Musgrave Multifractal
*
* H: highest fractal dimension
* lacunarity: gap between successive frequencies
* octaves: number of frequencies in the fBm
*/
float noise_musgrave_multi_fractal_2d(vector2 co, float H, float lacunarity, float octaves)
{
vector2 p = co;
float value = 1.0;
float pwr = 1.0;
float pwHL = pow(lacunarity, -H);
for (int i = 0; i < (int)octaves; i++) {
value *= (pwr * safe_snoise(p) + 1.0);
pwr *= pwHL;
p *= lacunarity;
}
float rmd = octaves - floor(octaves);
if (rmd != 0.0) {
value *= (rmd * pwr * safe_snoise(p) + 1.0); /* correct? */
}
return value;
}
/* 2D Musgrave Heterogeneous Terrain
*
* H: fractal dimension of the roughest area
* lacunarity: gap between successive frequencies
* octaves: number of frequencies in the fBm
* offset: raises the terrain from `sea level'
*/
float noise_musgrave_hetero_terrain_2d(
vector2 co, float H, float lacunarity, float octaves, float offset)
{
vector2 p = co;
float pwHL = pow(lacunarity, -H);
float pwr = pwHL;
/* first unscaled octave of function; later octaves are scaled */
float value = offset + safe_snoise(p);
p *= lacunarity;
for (int i = 1; i < (int)octaves; i++) {
float increment = (safe_snoise(p) + offset) * pwr * value;
value += increment;
pwr *= pwHL;
p *= lacunarity;
}
float rmd = octaves - floor(octaves);
if (rmd != 0.0) {
float increment = (safe_snoise(p) + offset) * pwr * value;
value += rmd * increment;
}
return value;
}
/* 2D Hybrid Additive/Multiplicative Multifractal Terrain
*
* H: fractal dimension of the roughest area
* lacunarity: gap between successive frequencies
* octaves: number of frequencies in the fBm
* offset: raises the terrain from `sea level'
*/
float noise_musgrave_hybrid_multi_fractal_2d(
vector2 co, float H, float lacunarity, float octaves, float offset, float gain)
{
vector2 p = co;
float pwHL = pow(lacunarity, -H);
float pwr = pwHL;
float value = safe_snoise(p) + offset;
float weight = gain * value;
p *= lacunarity;
for (int i = 1; (weight > 0.001) && (i < (int)octaves); i++) {
if (weight > 1.0) {
weight = 1.0;
}
float signal = (safe_snoise(p) + offset) * pwr;
pwr *= pwHL;
value += weight * signal;
weight *= gain * signal;
p *= lacunarity;
}
float rmd = octaves - floor(octaves);
if (rmd != 0.0) {
value += rmd * ((safe_snoise(p) + offset) * pwr);
}
return value;
}
/* 2D Ridged Multifractal Terrain
*
* H: fractal dimension of the roughest area
* lacunarity: gap between successive frequencies
* octaves: number of frequencies in the fBm
* offset: raises the terrain from `sea level'
*/
float noise_musgrave_ridged_multi_fractal_2d(
vector2 co, float H, float lacunarity, float octaves, float offset, float gain)
{
vector2 p = co;
float pwHL = pow(lacunarity, -H);
float pwr = pwHL;
float signal = offset - fabs(safe_snoise(p));
signal *= signal;
float value = signal;
float weight = 1.0;
for (int i = 1; i < (int)octaves; i++) {
p *= lacunarity;
weight = clamp(signal * gain, 0.0, 1.0);
signal = offset - fabs(safe_snoise(p));
signal *= signal;
signal *= weight;
value += signal * pwr;
pwr *= pwHL;
}
return value;
}
/* 3D Musgrave fBm
*
* H: fractal increment parameter
* lacunarity: gap between successive frequencies
* octaves: number of frequencies in the fBm
*
* from "Texturing and Modelling: A procedural approach"
*/
float noise_musgrave_fBm_3d(vector3 co, float H, float lacunarity, float octaves)
{
vector3 p = co;
float value = 0.0;
float pwr = 1.0;
float pwHL = pow(lacunarity, -H);
for (int i = 0; i < (int)octaves; i++) {
value += safe_snoise(p) * pwr;
pwr *= pwHL;
p *= lacunarity;
}
float rmd = octaves - floor(octaves);
if (rmd != 0.0) {
value += rmd * safe_snoise(p) * pwr;
}
return value;
}
/* 3D Musgrave Multifractal
*
* H: highest fractal dimension
* lacunarity: gap between successive frequencies
* octaves: number of frequencies in the fBm
*/
float noise_musgrave_multi_fractal_3d(vector3 co, float H, float lacunarity, float octaves)
{
vector3 p = co;
float value = 1.0;
float pwr = 1.0;
float pwHL = pow(lacunarity, -H);
for (int i = 0; i < (int)octaves; i++) {
value *= (pwr * safe_snoise(p) + 1.0);
pwr *= pwHL;
p *= lacunarity;
}
float rmd = octaves - floor(octaves);
if (rmd != 0.0) {
value *= (rmd * pwr * safe_snoise(p) + 1.0); /* correct? */
}
return value;
}
/* 3D Musgrave Heterogeneous Terrain
*
* H: fractal dimension of the roughest area
* lacunarity: gap between successive frequencies
* octaves: number of frequencies in the fBm
* offset: raises the terrain from `sea level'
*/
float noise_musgrave_hetero_terrain_3d(
vector3 co, float H, float lacunarity, float octaves, float offset)
{
vector3 p = co;
float pwHL = pow(lacunarity, -H);
float pwr = pwHL;
/* first unscaled octave of function; later octaves are scaled */
float value = offset + safe_snoise(p);
p *= lacunarity;
for (int i = 1; i < (int)octaves; i++) {
float increment = (safe_snoise(p) + offset) * pwr * value;
value += increment;
pwr *= pwHL;
p *= lacunarity;
}
float rmd = octaves - floor(octaves);
if (rmd != 0.0) {
float increment = (safe_snoise(p) + offset) * pwr * value;
value += rmd * increment;
}
return value;
}
/* 3D Hybrid Additive/Multiplicative Multifractal Terrain
*
* H: fractal dimension of the roughest area
* lacunarity: gap between successive frequencies
* octaves: number of frequencies in the fBm
* offset: raises the terrain from `sea level'
*/
float noise_musgrave_hybrid_multi_fractal_3d(
vector3 co, float H, float lacunarity, float octaves, float offset, float gain)
{
vector3 p = co;
float pwHL = pow(lacunarity, -H);
float pwr = pwHL;
float value = safe_snoise(p) + offset;
float weight = gain * value;
p *= lacunarity;
for (int i = 1; (weight > 0.001) && (i < (int)octaves); i++) {
if (weight > 1.0) {
weight = 1.0;
}
float signal = (safe_snoise(p) + offset) * pwr;
pwr *= pwHL;
value += weight * signal;
weight *= gain * signal;
p *= lacunarity;
}
float rmd = octaves - floor(octaves);
if (rmd != 0.0) {
value += rmd * ((safe_snoise(p) + offset) * pwr);
}
return value;
}
/* 3D Ridged Multifractal Terrain
*
* H: fractal dimension of the roughest area
* lacunarity: gap between successive frequencies
* octaves: number of frequencies in the fBm
* offset: raises the terrain from `sea level'
*/
float noise_musgrave_ridged_multi_fractal_3d(
vector3 co, float H, float lacunarity, float octaves, float offset, float gain)
{
vector3 p = co;
float pwHL = pow(lacunarity, -H);
float pwr = pwHL;
float signal = offset - fabs(safe_snoise(p));
signal *= signal;
float value = signal;
float weight = 1.0;
for (int i = 1; i < (int)octaves; i++) {
p *= lacunarity;
weight = clamp(signal * gain, 0.0, 1.0);
signal = offset - fabs(safe_snoise(p));
signal *= signal;
signal *= weight;
value += signal * pwr;
pwr *= pwHL;
}
return value;
}
/* 4D Musgrave fBm
*
* H: fractal increment parameter
* lacunarity: gap between successive frequencies
* octaves: number of frequencies in the fBm
*
* from "Texturing and Modelling: A procedural approach"
*/
float noise_musgrave_fBm_4d(vector4 co, float H, float lacunarity, float octaves)
{
vector4 p = co;
float value = 0.0;
float pwr = 1.0;
float pwHL = pow(lacunarity, -H);
for (int i = 0; i < (int)octaves; i++) {
value += safe_snoise(p) * pwr;
pwr *= pwHL;
p *= lacunarity;
}
float rmd = octaves - floor(octaves);
if (rmd != 0.0) {
value += rmd * safe_snoise(p) * pwr;
}
return value;
}
/* 4D Musgrave Multifractal
*
* H: highest fractal dimension
* lacunarity: gap between successive frequencies
* octaves: number of frequencies in the fBm
*/
float noise_musgrave_multi_fractal_4d(vector4 co, float H, float lacunarity, float octaves)
{
vector4 p = co;
float value = 1.0;
float pwr = 1.0;
float pwHL = pow(lacunarity, -H);
for (int i = 0; i < (int)octaves; i++) {
value *= (pwr * safe_snoise(p) + 1.0);
pwr *= pwHL;
p *= lacunarity;
}
float rmd = octaves - floor(octaves);
if (rmd != 0.0) {
value *= (rmd * pwr * safe_snoise(p) + 1.0); /* correct? */
}
return value;
}
/* 4D Musgrave Heterogeneous Terrain
*
* H: fractal dimension of the roughest area
* lacunarity: gap between successive frequencies
* octaves: number of frequencies in the fBm
* offset: raises the terrain from `sea level'
*/
float noise_musgrave_hetero_terrain_4d(
vector4 co, float H, float lacunarity, float octaves, float offset)
{
vector4 p = co;
float pwHL = pow(lacunarity, -H);
float pwr = pwHL;
/* first unscaled octave of function; later octaves are scaled */
float value = offset + safe_snoise(p);
p *= lacunarity;
for (int i = 1; i < (int)octaves; i++) {
float increment = (safe_snoise(p) + offset) * pwr * value;
value += increment;
pwr *= pwHL;
p *= lacunarity;
}
float rmd = octaves - floor(octaves);
if (rmd != 0.0) {
float increment = (safe_snoise(p) + offset) * pwr * value;
value += rmd * increment;
}
return value;
}
/* 4D Hybrid Additive/Multiplicative Multifractal Terrain
*
* H: fractal dimension of the roughest area
* lacunarity: gap between successive frequencies
* octaves: number of frequencies in the fBm
* offset: raises the terrain from `sea level'
*/
float noise_musgrave_hybrid_multi_fractal_4d(
vector4 co, float H, float lacunarity, float octaves, float offset, float gain)
{
vector4 p = co;
float pwHL = pow(lacunarity, -H);
float pwr = pwHL;
float value = safe_snoise(p) + offset;
float weight = gain * value;
p *= lacunarity;
for (int i = 1; (weight > 0.001) && (i < (int)octaves); i++) {
if (weight > 1.0) {
weight = 1.0;
}
float signal = (safe_snoise(p) + offset) * pwr;
pwr *= pwHL;
value += weight * signal;
weight *= gain * signal;
p *= lacunarity;
}
float rmd = octaves - floor(octaves);
if (rmd != 0.0) {
value += rmd * ((safe_snoise(p) + offset) * pwr);
}
return value;
}
/* 4D Ridged Multifractal Terrain
*
* H: fractal dimension of the roughest area
* lacunarity: gap between successive frequencies
* octaves: number of frequencies in the fBm
* offset: raises the terrain from `sea level'
*/
float noise_musgrave_ridged_multi_fractal_4d(
vector4 co, float H, float lacunarity, float octaves, float offset, float gain)
{
vector4 p = co;
float pwHL = pow(lacunarity, -H);
float pwr = pwHL;
float signal = offset - fabs(safe_snoise(p));
signal *= signal;
float value = signal;
float weight = 1.0;
for (int i = 1; i < (int)octaves; i++) {
p *= lacunarity;
weight = clamp(signal * gain, 0.0, 1.0);
signal = offset - fabs(safe_snoise(p));
signal *= signal;
signal *= weight;
value += signal * pwr;
pwr *= pwHL;
}
return value;
}
/* Shader */
shader node_musgrave_texture(
int use_mapping = 0,
matrix mapping = matrix(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
string type = "fBM",
string dimensions = "3D",
point Vector = P,
float W = 0.0,
float Dimension = 2.0,
float Scale = 5.0,
float Detail = 2.0,
float Lacunarity = 1.0,
float Detail = 2.0,
float Offset = 0.0,
float Gain = 1.0,
output float Fac = 0.0)
float Scale = 5.0,
point Vector = P,
output float Fac = 0.0,
output color Color = 0.0)
{
float dimension = max(Dimension, 1e-5);
float octaves = clamp(Detail, 0.0, 16.0);
float lacunarity = max(Lacunarity, 1e-5);
float intensity = 1.0;
vector3 s = Vector;
point p = Vector;
if (use_mapping)
s = transform(mapping, s);
p = transform(mapping, p);
if (dimensions == "1D") {
float p = W * Scale;
if (type == "multifractal") {
Fac = noise_musgrave_multi_fractal_1d(p, dimension, lacunarity, octaves);
}
else if (type == "fBM") {
Fac = noise_musgrave_fBm_1d(p, dimension, lacunarity, octaves);
}
else if (type == "hybrid_multifractal") {
Fac = noise_musgrave_hybrid_multi_fractal_1d(
p, dimension, lacunarity, octaves, Offset, Gain);
}
else if (type == "ridged_multifractal") {
Fac = noise_musgrave_ridged_multi_fractal_1d(
p, dimension, lacunarity, octaves, Offset, Gain);
}
else if (type == "hetero_terrain") {
Fac = noise_musgrave_hetero_terrain_1d(p, dimension, lacunarity, octaves, Offset);
}
else {
Fac = 0.0;
}
}
else if (dimensions == "2D") {
vector2 p = vector2(s[0], s[1]) * Scale;
if (type == "multifractal") {
Fac = noise_musgrave_multi_fractal_2d(p, dimension, lacunarity, octaves);
}
else if (type == "fBM") {
Fac = noise_musgrave_fBm_2d(p, dimension, lacunarity, octaves);
}
else if (type == "hybrid_multifractal") {
Fac = noise_musgrave_hybrid_multi_fractal_2d(
p, dimension, lacunarity, octaves, Offset, Gain);
}
else if (type == "ridged_multifractal") {
Fac = noise_musgrave_ridged_multi_fractal_2d(
p, dimension, lacunarity, octaves, Offset, Gain);
}
else if (type == "hetero_terrain") {
Fac = noise_musgrave_hetero_terrain_2d(p, dimension, lacunarity, octaves, Offset);
}
else {
Fac = 0.0;
}
}
else if (dimensions == "3D") {
vector3 p = s * Scale;
if (type == "multifractal") {
Fac = noise_musgrave_multi_fractal_3d(p, dimension, lacunarity, octaves);
}
else if (type == "fBM") {
Fac = noise_musgrave_fBm_3d(p, dimension, lacunarity, octaves);
}
else if (type == "hybrid_multifractal") {
Fac = noise_musgrave_hybrid_multi_fractal_3d(
p, dimension, lacunarity, octaves, Offset, Gain);
}
else if (type == "ridged_multifractal") {
Fac = noise_musgrave_ridged_multi_fractal_3d(
p, dimension, lacunarity, octaves, Offset, Gain);
}
else if (type == "hetero_terrain") {
Fac = noise_musgrave_hetero_terrain_3d(p, dimension, lacunarity, octaves, Offset);
}
else {
Fac = 0.0;
}
}
else if (dimensions == "4D") {
vector4 p = vector4(s[0], s[1], s[2], W) * Scale;
if (type == "multifractal") {
Fac = noise_musgrave_multi_fractal_4d(p, dimension, lacunarity, octaves);
}
else if (type == "fBM") {
Fac = noise_musgrave_fBm_4d(p, dimension, lacunarity, octaves);
}
else if (type == "hybrid_multifractal") {
Fac = noise_musgrave_hybrid_multi_fractal_4d(
p, dimension, lacunarity, octaves, Offset, Gain);
}
else if (type == "ridged_multifractal") {
Fac = noise_musgrave_ridged_multi_fractal_4d(
p, dimension, lacunarity, octaves, Offset, Gain);
}
else if (type == "hetero_terrain") {
Fac = noise_musgrave_hetero_terrain_4d(p, dimension, lacunarity, octaves, Offset);
}
else {
Fac = 0.0;
}
}
else {
Fac = 0.0;
}
p = p * Scale;
if (type == "multifractal")
Fac = intensity * noise_musgrave_multi_fractal(p, dimension, lacunarity, octaves);
else if (type == "fBM")
Fac = intensity * noise_musgrave_fBm(p, dimension, lacunarity, octaves);
else if (type == "hybrid_multifractal")
Fac = intensity *
noise_musgrave_hybrid_multi_fractal(p, dimension, lacunarity, octaves, Offset, Gain);
else if (type == "ridged_multifractal")
Fac = intensity *
noise_musgrave_ridged_multi_fractal(p, dimension, lacunarity, octaves, Offset, Gain);
else if (type == "hetero_terrain")
Fac = intensity * noise_musgrave_hetero_terrain(p, dimension, lacunarity, octaves, Offset);
Color = color(Fac, Fac, Fac);
}

View File

@@ -1,198 +0,0 @@
/*
* Copyright 2011-2013 Blender Foundation
*
* 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* 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.
*/
#include "vector2.h"
#include "vector4.h"
#define vector3 point
float safe_noise(float p)
{
float f = noise("noise", p);
if (isinf(f))
return 0.5;
return f;
}
float safe_noise(vector2 p)
{
float f = noise("noise", p.x, p.y);
if (isinf(f))
return 0.5;
return f;
}
float safe_noise(vector3 p)
{
float f = noise("noise", p);
if (isinf(f))
return 0.5;
return f;
}
float safe_noise(vector4 p)
{
float f = noise("noise", vector3(p.x, p.y, p.z), p.w);
if (isinf(f))
return 0.5;
return f;
}
float safe_snoise(float p)
{
float f = noise("snoise", p);
if (isinf(f))
return 0.0;
return f;
}
float safe_snoise(vector2 p)
{
float f = noise("snoise", p.x, p.y);
if (isinf(f))
return 0.0;
return f;
}
float safe_snoise(vector3 p)
{
float f = noise("snoise", p);
if (isinf(f))
return 0.0;
return f;
}
float safe_snoise(vector4 p)
{
float f = noise("snoise", vector3(p.x, p.y, p.z), p.w);
if (isinf(f))
return 0.0;
return f;
}
/* The fractal_noise functions are all exactly the same except for the input type. */
float fractal_noise(float p, float details)
{
float fscale = 1.0;
float amp = 1.0;
float sum = 0.0;
float octaves = clamp(details, 0.0, 16.0);
int n = (int)octaves;
for (int i = 0; i <= n; i++) {
float t = safe_noise(fscale * p);
sum += t * amp;
amp *= 0.5;
fscale *= 2.0;
}
float rmd = octaves - floor(octaves);
if (rmd != 0.0) {
float t = safe_noise(fscale * p);
float sum2 = sum + t * amp;
sum *= ((float)(1 << n) / (float)((1 << (n + 1)) - 1));
sum2 *= ((float)(1 << (n + 1)) / (float)((1 << (n + 2)) - 1));
return (1.0 - rmd) * sum + rmd * sum2;
}
else {
sum *= ((float)(1 << n) / (float)((1 << (n + 1)) - 1));
return sum;
}
}
/* The fractal_noise functions are all exactly the same except for the input type. */
float fractal_noise(vector2 p, float details)
{
float fscale = 1.0;
float amp = 1.0;
float sum = 0.0;
float octaves = clamp(details, 0.0, 16.0);
int n = (int)octaves;
for (int i = 0; i <= n; i++) {
float t = safe_noise(fscale * p);
sum += t * amp;
amp *= 0.5;
fscale *= 2.0;
}
float rmd = octaves - floor(octaves);
if (rmd != 0.0) {
float t = safe_noise(fscale * p);
float sum2 = sum + t * amp;
sum *= ((float)(1 << n) / (float)((1 << (n + 1)) - 1));
sum2 *= ((float)(1 << (n + 1)) / (float)((1 << (n + 2)) - 1));
return (1.0 - rmd) * sum + rmd * sum2;
}
else {
sum *= ((float)(1 << n) / (float)((1 << (n + 1)) - 1));
return sum;
}
}
/* The fractal_noise functions are all exactly the same except for the input type. */
float fractal_noise(vector3 p, float details)
{
float fscale = 1.0;
float amp = 1.0;
float sum = 0.0;
float octaves = clamp(details, 0.0, 16.0);
int n = (int)octaves;
for (int i = 0; i <= n; i++) {
float t = safe_noise(fscale * p);
sum += t * amp;
amp *= 0.5;
fscale *= 2.0;
}
float rmd = octaves - floor(octaves);
if (rmd != 0.0) {
float t = safe_noise(fscale * p);
float sum2 = sum + t * amp;
sum *= ((float)(1 << n) / (float)((1 << (n + 1)) - 1));
sum2 *= ((float)(1 << (n + 1)) / (float)((1 << (n + 2)) - 1));
return (1.0 - rmd) * sum + rmd * sum2;
}
else {
sum *= ((float)(1 << n) / (float)((1 << (n + 1)) - 1));
return sum;
}
}
/* The fractal_noise functions are all exactly the same except for the input type. */
float fractal_noise(vector4 p, float details)
{
float fscale = 1.0;
float amp = 1.0;
float sum = 0.0;
float octaves = clamp(details, 0.0, 16.0);
int n = (int)octaves;
for (int i = 0; i <= n; i++) {
float t = safe_noise(fscale * p);
sum += t * amp;
amp *= 0.5;
fscale *= 2.0;
}
float rmd = octaves - floor(octaves);
if (rmd != 0.0) {
float t = safe_noise(fscale * p);
float sum2 = sum + t * amp;
sum *= ((float)(1 << n) / (float)((1 << (n + 1)) - 1));
sum2 *= ((float)(1 << (n + 1)) / (float)((1 << (n + 2)) - 1));
return (1.0 - rmd) * sum + rmd * sum2;
}
else {
sum *= ((float)(1 << n) / (float)((1 << (n + 1)) - 1));
return sum;
}
}
#undef vector3

View File

@@ -15,134 +15,46 @@
*/
#include "stdosl.h"
#include "vector2.h"
#include "vector4.h"
#include "node_noise.h"
#include "node_texture.h"
#define vector3 point
/* Noise */
/* The following offset functions generate random offsets to be added to texture
* coordinates to act as a seed since the noise functions don't have seed values.
* A seed value is needed for generating distortion textures and color outputs.
* The offset's components are in the range [100, 200], not too high to cause
* bad precision and not to small to be noticeable. We use float seed because
* OSL only support float hashes.
*/
float random_float_offset(float seed)
float noise(point ip, float distortion, float detail, output color Color)
{
return 100.0 + noise("hash", seed) * 100.0;
}
point r;
point p = ip;
int hard = 0;
vector2 random_vector2_offset(float seed)
{
return vector2(100.0 + noise("hash", seed, 0.0) * 100.0,
100.0 + noise("hash", seed, 1.0) * 100.0);
}
vector3 random_vector3_offset(float seed)
{
return vector3(100.0 + noise("hash", seed, 0.0) * 100.0,
100.0 + noise("hash", seed, 1.0) * 100.0,
100.0 + noise("hash", seed, 2.0) * 100.0);
}
vector4 random_vector4_offset(float seed)
{
return vector4(100.0 + noise("hash", seed, 0.0) * 100.0,
100.0 + noise("hash", seed, 1.0) * 100.0,
100.0 + noise("hash", seed, 2.0) * 100.0,
100.0 + noise("hash", seed, 3.0) * 100.0);
}
float noise_texture(float co, float detail, float distortion, output color Color)
{
float p = co;
if (distortion != 0.0) {
p += safe_noise(p + random_float_offset(0.0)) * distortion;
r[0] = safe_noise(p + point(13.5), "unsigned") * distortion;
r[1] = safe_noise(p, "unsigned") * distortion;
r[2] = safe_noise(p - point(13.5), "unsigned") * distortion;
p += r;
}
float value = fractal_noise(p, detail);
Color = color(value,
fractal_noise(p + random_float_offset(1.0), detail),
fractal_noise(p + random_float_offset(2.0), detail));
return value;
}
float fac = noise_turbulence(p, detail, hard);
float noise_texture(vector2 co, float detail, float distortion, output color Color)
{
vector2 p = co;
if (distortion != 0.0) {
p += vector2(safe_noise(p + random_vector2_offset(0.0)) * distortion,
safe_noise(p + random_vector2_offset(1.0)) * distortion);
}
Color = color(fac,
noise_turbulence(point(p[1], p[0], p[2]), detail, hard),
noise_turbulence(point(p[1], p[2], p[0]), detail, hard));
float value = fractal_noise(p, detail);
Color = color(value,
fractal_noise(p + random_vector2_offset(2.0), detail),
fractal_noise(p + random_vector2_offset(3.0), detail));
return value;
}
float noise_texture(vector3 co, float detail, float distortion, output color Color)
{
vector3 p = co;
if (distortion != 0.0) {
p += vector3(safe_noise(p + random_vector3_offset(0.0)) * distortion,
safe_noise(p + random_vector3_offset(1.0)) * distortion,
safe_noise(p + random_vector3_offset(2.0)) * distortion);
}
float value = fractal_noise(p, detail);
Color = color(value,
fractal_noise(p + random_vector3_offset(3.0), detail),
fractal_noise(p + random_vector3_offset(4.0), detail));
return value;
}
float noise_texture(vector4 co, float detail, float distortion, output color Color)
{
vector4 p = co;
if (distortion != 0.0) {
p += vector4(safe_noise(p + random_vector4_offset(0.0)) * distortion,
safe_noise(p + random_vector4_offset(1.0)) * distortion,
safe_noise(p + random_vector4_offset(2.0)) * distortion,
safe_noise(p + random_vector4_offset(3.0)) * distortion);
}
float value = fractal_noise(p, detail);
Color = color(value,
fractal_noise(p + random_vector4_offset(4.0), detail),
fractal_noise(p + random_vector4_offset(5.0), detail));
return value;
return fac;
}
shader node_noise_texture(int use_mapping = 0,
matrix mapping = matrix(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
string dimensions = "3D",
vector3 Vector = vector3(0, 0, 0),
float W = 0.0,
float Distortion = 0.0,
float Scale = 5.0,
float Detail = 2.0,
float Distortion = 0.0,
point Vector = P,
output float Fac = 0.0,
output color Color = 0.0)
{
vector3 p = Vector;
point p = Vector;
if (use_mapping)
p = transform(mapping, p);
p *= Scale;
float w = W * Scale;
if (dimensions == "1D")
Fac = noise_texture(w, Detail, Distortion, Color);
else if (dimensions == "2D")
Fac = noise_texture(vector2(p[0], p[1]), Detail, Distortion, Color);
else if (dimensions == "3D")
Fac = noise_texture(p, Detail, Distortion, Color);
else if (dimensions == "4D")
Fac = noise_texture(vector4(p[0], p[1], p[2], w), Detail, Distortion, Color);
else
error("Unknown dimension!");
Fac = noise(p * Scale, Distortion, Detail, Color);
}

View File

@@ -0,0 +1,165 @@
/*
* Copyright 2011-2013 Blender Foundation
*
* 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* 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.
*/
/* Voronoi / Worley like */
color cellnoise_color(point p)
{
float r = cellnoise(p);
float g = cellnoise(point(p[1], p[0], p[2]));
float b = cellnoise(point(p[1], p[2], p[0]));
return color(r, g, b);
}
void voronoi(point p, float e, float da[4], point pa[4])
{
/* returns distances in da and point coords in pa */
int xx, yy, zz, xi, yi, zi;
xi = (int)floor(p[0]);
yi = (int)floor(p[1]);
zi = (int)floor(p[2]);
da[0] = 1e10;
da[1] = 1e10;
da[2] = 1e10;
da[3] = 1e10;
for (xx = xi - 1; xx <= xi + 1; xx++) {
for (yy = yi - 1; yy <= yi + 1; yy++) {
for (zz = zi - 1; zz <= zi + 1; zz++) {
point ip = point(xx, yy, zz);
point vp = (point)cellnoise_color(ip);
point pd = p - (vp + ip);
float d = dot(pd, pd);
vp += point(xx, yy, zz);
if (d < da[0]) {
da[3] = da[2];
da[2] = da[1];
da[1] = da[0];
da[0] = d;
pa[3] = pa[2];
pa[2] = pa[1];
pa[1] = pa[0];
pa[0] = vp;
}
else if (d < da[1]) {
da[3] = da[2];
da[2] = da[1];
da[1] = d;
pa[3] = pa[2];
pa[2] = pa[1];
pa[1] = vp;
}
else if (d < da[2]) {
da[3] = da[2];
da[2] = d;
pa[3] = pa[2];
pa[2] = vp;
}
else if (d < da[3]) {
da[3] = d;
pa[3] = vp;
}
}
}
}
}
/* Noise Bases */
float safe_noise(point p, string type)
{
float f = 0.0;
/* Perlin noise in range -1..1 */
if (type == "signed")
f = noise("perlin", p);
/* Perlin noise in range 0..1 */
else
f = noise(p);
/* can happen for big coordinates, things even out to 0.5 then anyway */
if (!isfinite(f))
return 0.5;
return f;
}
/* Turbulence */
float noise_turbulence(point p, float details, int hard)
{
float fscale = 1.0;
float amp = 1.0;
float sum = 0.0;
int i, n;
float octaves = clamp(details, 0.0, 16.0);
n = (int)octaves;
for (i = 0; i <= n; i++) {
float t = safe_noise(fscale * p, "unsigned");
if (hard)
t = fabs(2.0 * t - 1.0);
sum += t * amp;
amp *= 0.5;
fscale *= 2.0;
}
float rmd = octaves - floor(octaves);
if (rmd != 0.0) {
float t = safe_noise(fscale * p, "unsigned");
if (hard)
t = fabs(2.0 * t - 1.0);
float sum2 = sum + t * amp;
sum *= ((float)(1 << n) / (float)((1 << (n + 1)) - 1));
sum2 *= ((float)(1 << (n + 1)) / (float)((1 << (n + 2)) - 1));
return (1.0 - rmd) * sum + rmd * sum2;
}
else {
sum *= ((float)(1 << n) / (float)((1 << (n + 1)) - 1));
return sum;
}
}
/* Utility */
float nonzero(float f, float eps)
{
float r;
if (abs(f) < eps)
r = sign(f) * eps;
else
r = f;
return r;
}

View File

@@ -15,15 +15,7 @@
*/
#include "stdosl.h"
color cellnoise_color(point p)
{
float r = cellnoise(p);
float g = cellnoise(point(p[1], p[0], p[2]));
float b = cellnoise(point(p[1], p[2], p[0]));
return color(r, g, b);
}
#include "node_texture.h"
void voronoi_m(point p, string metric, float e, float da[4], point pa[4])
{

View File

@@ -15,7 +15,7 @@
*/
#include "stdosl.h"
#include "node_noise.h"
#include "node_texture.h"
/* Wave */
@@ -31,7 +31,7 @@ float wave(point p, string type, string profile, float detail, float distortion,
}
if (distortion != 0.0) {
n = n + (distortion * fractal_noise(p * dscale, detail));
n = n + (distortion * noise_turbulence(p * dscale, detail, 0));
}
if (profile == "sine") {

View File

@@ -1,291 +0,0 @@
// Open Shading Language : Copyright (c) 2009-2017 Sony Pictures Imageworks Inc., et al.
// https://github.com/imageworks/OpenShadingLanguage/blob/master/LICENSE
#pragma once
#define VECTOR2_H
// vector2 is a 2D vector
struct vector2 {
float x;
float y;
};
//
// For vector2, define math operators to match vector
//
vector2 __operator__neg__(vector2 a)
{
return vector2(-a.x, -a.y);
}
vector2 __operator__add__(vector2 a, vector2 b)
{
return vector2(a.x + b.x, a.y + b.y);
}
vector2 __operator__add__(vector2 a, int b)
{
return a + vector2(b, b);
}
vector2 __operator__add__(vector2 a, float b)
{
return a + vector2(b, b);
}
vector2 __operator__add__(int a, vector2 b)
{
return vector2(a, a) + b;
}
vector2 __operator__add__(float a, vector2 b)
{
return vector2(a, a) + b;
}
vector2 __operator__sub__(vector2 a, vector2 b)
{
return vector2(a.x - b.x, a.y - b.y);
}
vector2 __operator__sub__(vector2 a, int b)
{
return a - vector2(b, b);
}
vector2 __operator__sub__(vector2 a, float b)
{
return a - vector2(b, b);
}
vector2 __operator__sub__(int a, vector2 b)
{
return vector2(a, a) - b;
}
vector2 __operator__sub__(float a, vector2 b)
{
return vector2(a, a) - b;
}
vector2 __operator__mul__(vector2 a, vector2 b)
{
return vector2(a.x * b.x, a.y * b.y);
}
vector2 __operator__mul__(vector2 a, int b)
{
return a * vector2(b, b);
}
vector2 __operator__mul__(vector2 a, float b)
{
return a * vector2(b, b);
}
vector2 __operator__mul__(int a, vector2 b)
{
return b * vector2(a, a);
}
vector2 __operator__mul__(float a, vector2 b)
{
return b * vector2(a, a);
}
vector2 __operator__div__(vector2 a, vector2 b)
{
return vector2(a.x / b.x, a.y / b.y);
}
vector2 __operator__div__(vector2 a, int b)
{
float b_inv = 1 / b;
return a * vector2(b_inv, b_inv);
}
vector2 __operator__div__(vector2 a, float b)
{
float b_inv = 1 / b;
return a * vector2(b_inv, b_inv);
}
vector2 __operator__div__(int a, vector2 b)
{
return vector2(a, a) / b;
}
vector2 __operator__div__(float a, vector2 b)
{
return vector2(a, a) / b;
}
int __operator__eq__(vector2 a, vector2 b)
{
return (a.x == b.x) && (a.y == b.y);
}
int __operator__ne__(vector2 a, vector2 b)
{
return (a.x != b.x) || (a.y != b.y);
}
//
// For vector2, define most of the stdosl functions to match vector
//
vector2 abs(vector2 a)
{
return vector2(abs(a.x), abs(a.y));
}
vector2 ceil(vector2 a)
{
return vector2(ceil(a.x), ceil(a.y));
}
vector2 floor(vector2 a)
{
return vector2(floor(a.x), floor(a.y));
}
vector2 sqrt(vector2 a)
{
return vector2(sqrt(a.x), sqrt(a.y));
}
vector2 exp(vector2 a)
{
return vector2(exp(a.x), exp(a.y));
}
vector2 log(vector2 a)
{
return vector2(log(a.x), log(a.y));
}
vector2 log2(vector2 a)
{
return vector2(log2(a.x), log2(a.y));
}
vector2 mix(vector2 a, vector2 b, float x)
{
return vector2(mix(a.x, b.x, x), mix(a.y, b.y, x));
}
float dot(vector2 a, vector2 b)
{
return (a.x * b.x + a.y * b.y);
}
float length(vector2 a)
{
return hypot(a.x, a.y);
}
vector2 smoothstep(vector2 low, vector2 high, vector2 in)
{
return vector2(smoothstep(low.x, high.x, in.x), smoothstep(low.y, high.y, in.y));
}
vector2 smoothstep(float low, float high, vector2 in)
{
return vector2(smoothstep(low, high, in.x), smoothstep(low, high, in.y));
}
vector2 clamp(vector2 in, vector2 low, vector2 high)
{
return vector2(clamp(in.x, low.x, high.x), clamp(in.y, low.y, high.y));
}
vector2 clamp(vector2 in, float low, float high)
{
return clamp(in, vector2(low, low), vector2(high, high));
}
vector2 max(vector2 a, vector2 b)
{
return vector2(max(a.x, b.x), max(a.y, b.y));
}
vector2 max(vector2 a, float b)
{
return max(a, vector2(b, b));
}
vector2 normalize(vector2 a)
{
return a / length(a);
}
vector2 min(vector2 a, vector2 b)
{
return vector2(min(a.x, a.x), min(b.y, b.y));
}
vector2 min(vector2 a, float b)
{
return min(a, vector2(b, b));
}
vector2 fmod(vector2 a, vector2 b)
{
return vector2(fmod(a.x, b.x), fmod(a.y, b.y));
}
vector2 fmod(vector2 a, float b)
{
return fmod(a, vector2(b, b));
}
vector2 pow(vector2 in, vector2 amount)
{
return vector2(pow(in.x, amount.x), pow(in.y, amount.y));
}
vector2 pow(vector2 in, float amount)
{
return pow(in, vector2(amount, amount));
}
vector2 sign(vector2 a)
{
return vector2(sign(a.x), sign(a.y));
}
vector2 sin(vector2 a)
{
return vector2(sin(a.x), sin(a.y));
}
vector2 cos(vector2 a)
{
return vector2(cos(a.x), cos(a.y));
}
vector2 tan(vector2 a)
{
return vector2(tan(a.x), tan(a.y));
}
vector2 asin(vector2 a)
{
return vector2(asin(a.x), asin(a.y));
}
vector2 acos(vector2 a)
{
return vector2(acos(a.x), acos(a.y));
}
vector2 atan2(vector2 a, float f)
{
return vector2(atan2(a.x, f), atan2(a.y, f));
}
vector2 atan2(vector2 a, vector2 b)
{
return vector2(atan2(a.x, b.x), atan2(a.y, b.y));
}

View File

@@ -1,327 +0,0 @@
// Open Shading Language : Copyright (c) 2009-2017 Sony Pictures Imageworks Inc., et al.
// https://github.com/imageworks/OpenShadingLanguage/blob/master/LICENSE
#pragma once
#define VECTOR4_H
// vector4 is a 4D vector
struct vector4 {
float x;
float y;
float z;
float w;
};
//
// For vector4, define math operators to match vector
//
vector4 __operator__neg__(vector4 a)
{
return vector4(-a.x, -a.y, -a.z, -a.w);
}
vector4 __operator__add__(vector4 a, vector4 b)
{
return vector4(a.x + b.x, a.y + b.y, a.z + b.z, a.w + b.w);
}
vector4 __operator__add__(vector4 a, int b)
{
return a + vector4(b, b, b, b);
}
vector4 __operator__add__(vector4 a, float b)
{
return a + vector4(b, b, b, b);
}
vector4 __operator__add__(int a, vector4 b)
{
return vector4(a, a, a, a) + b;
}
vector4 __operator__add__(float a, vector4 b)
{
return vector4(a, a, a, a) + b;
}
vector4 __operator__sub__(vector4 a, vector4 b)
{
return vector4(a.x - b.x, a.y - b.y, a.z - b.z, a.w - b.w);
}
vector4 __operator__sub__(vector4 a, int b)
{
return a - vector4(b, b, b, b);
}
vector4 __operator__sub__(vector4 a, float b)
{
return a - vector4(b, b, b, b);
}
vector4 __operator__sub__(int a, vector4 b)
{
return vector4(a, a, a, a) - b;
}
vector4 __operator__sub__(float a, vector4 b)
{
return vector4(a, a, a, a) - b;
}
vector4 __operator__mul__(vector4 a, vector4 b)
{
return vector4(a.x * b.x, a.y * b.y, a.z * b.z, a.w * b.w);
}
vector4 __operator__mul__(vector4 a, int b)
{
return a * vector4(b, b, b, b);
}
vector4 __operator__mul__(vector4 a, float b)
{
return a * vector4(b, b, b, b);
}
vector4 __operator__mul__(int a, vector4 b)
{
return vector4(a, a, a, a) * b;
}
vector4 __operator__mul__(float a, vector4 b)
{
return vector4(a, a, a, a) * b;
}
vector4 __operator__div__(vector4 a, vector4 b)
{
return vector4(a.x / b.x, a.y / b.y, a.z / b.z, a.w / b.w);
}
vector4 __operator__div__(vector4 a, int b)
{
float b_inv = 1 / b;
return a * vector4(b_inv, b_inv, b_inv, b_inv);
}
vector4 __operator__div__(vector4 a, float b)
{
float b_inv = 1 / b;
return a * vector4(b_inv, b_inv, b_inv, b_inv);
}
vector4 __operator__div__(int a, vector4 b)
{
return vector4(a, a, a, a) / b;
}
vector4 __operator__div__(float a, vector4 b)
{
return vector4(a, a, a, a) / b;
}
int __operator__eq__(vector4 a, vector4 b)
{
return (a.x == b.x) && (a.y == b.y) && (a.z == b.z) && (a.w == b.w);
}
int __operator__ne__(vector4 a, vector4 b)
{
return (a.x != b.x) || (a.y != b.y) || (a.z != b.z) || (a.w != b.w);
}
//
// For vector4, define most of the stdosl functions to match vector
//
vector4 abs(vector4 in)
{
return vector4(abs(in.x), abs(in.y), abs(in.z), abs(in.w));
}
vector4 ceil(vector4 in)
{
return vector4(ceil(in.x), ceil(in.y), ceil(in.z), ceil(in.w));
}
vector4 floor(vector4 in)
{
return vector4(floor(in.x), floor(in.y), floor(in.z), floor(in.w));
}
vector4 sqrt(vector4 in)
{
return vector4(sqrt(in.x), sqrt(in.y), sqrt(in.z), sqrt(in.w));
}
vector4 exp(vector4 in)
{
return vector4(exp(in.x), exp(in.y), exp(in.z), exp(in.w));
}
vector4 log(vector4 in)
{
return vector4(log(in.x), log(in.y), log(in.z), log(in.w));
}
vector4 log2(vector4 in)
{
return vector4(log2(in.x), log2(in.y), log2(in.z), log2(in.w));
}
vector4 mix(vector4 value1, vector4 value2, float x)
{
return vector4(mix(value1.x, value2.x, x),
mix(value1.y, value2.y, x),
mix(value1.z, value2.z, x),
mix(value1.w, value2.w, x));
}
vector vec4ToVec3(vector4 v)
{
return vector(v.x, v.y, v.z) / v.w;
}
float dot(vector4 a, vector4 b)
{
return ((a.x * b.x) + (a.y * b.y) + (a.z * b.z) + (a.w * b.w));
}
float length(vector4 a)
{
return sqrt(a.x * a.x + a.y * a.y + a.z * a.z + a.w * a.w);
}
vector4 smoothstep(vector4 low, vector4 high, vector4 in)
{
return vector4(smoothstep(low.x, high.x, in.x),
smoothstep(low.y, high.y, in.y),
smoothstep(low.z, high.z, in.z),
smoothstep(low.w, high.w, in.w));
}
vector4 smoothstep(float low, float high, vector4 in)
{
return vector4(smoothstep(low, high, in.x),
smoothstep(low, high, in.y),
smoothstep(low, high, in.z),
smoothstep(low, high, in.w));
}
vector4 clamp(vector4 in, vector4 low, vector4 high)
{
return vector4(clamp(in.x, low.x, high.x),
clamp(in.y, low.y, high.y),
clamp(in.z, low.z, high.z),
clamp(in.w, low.w, high.w));
}
vector4 clamp(vector4 in, float low, float high)
{
return vector4(clamp(in.x, low, high),
clamp(in.y, low, high),
clamp(in.z, low, high),
clamp(in.w, low, high));
}
vector4 max(vector4 a, vector4 b)
{
return vector4(max(a.x, b.x), max(a.y, b.y), max(a.z, b.z), max(a.w, b.w));
}
vector4 max(vector4 a, float b)
{
return max(a, vector4(b, b, b, b));
}
vector4 normalize(vector4 a)
{
return a / length(a);
}
vector4 min(vector4 a, vector4 b)
{
return vector4(min(a.x, b.x), min(a.y, b.y), min(a.z, b.z), min(a.w, b.w));
}
vector4 min(vector4 a, float b)
{
return min(a, vector4(b, b, b, b));
}
vector4 fmod(vector4 a, vector4 b)
{
return vector4(fmod(a.x, b.x), fmod(a.y, b.y), fmod(a.z, b.z), fmod(a.w, b.w));
}
vector4 fmod(vector4 a, float b)
{
return fmod(a, vector4(b, b, b, b));
}
vector4 pow(vector4 in, vector4 amount)
{
return vector4(
pow(in.x, amount.x), pow(in.y, amount.y), pow(in.z, amount.z), pow(in.w, amount.w));
}
vector4 pow(vector4 in, float amount)
{
return vector4(pow(in.x, amount), pow(in.y, amount), pow(in.z, amount), pow(in.w, amount));
}
vector4 sign(vector4 a)
{
return vector4(sign(a.x), sign(a.y), sign(a.z), sign(a.w));
}
vector4 sin(vector4 a)
{
return vector4(sin(a.x), sin(a.y), sin(a.z), sin(a.w));
}
vector4 cos(vector4 a)
{
return vector4(cos(a.x), cos(a.y), cos(a.z), cos(a.w));
}
vector4 tan(vector4 a)
{
return vector4(tan(a.x), tan(a.y), tan(a.z), tan(a.w));
}
vector4 asin(vector4 a)
{
return vector4(asin(a.x), asin(a.y), asin(a.z), asin(a.w));
}
vector4 acos(vector4 a)
{
return vector4(acos(a.x), acos(a.y), acos(a.z), acos(a.w));
}
vector4 atan2(vector4 a, float f)
{
return vector4(atan2(a.x, f), atan2(a.y, f), atan2(a.z, f), atan2(a.w, f));
}
vector4 atan2(vector4 a, vector4 b)
{
return vector4(atan2(a.x, b.x), atan2(a.y, b.y), atan2(a.z, b.z), atan2(a.w, b.w));
}
vector4 transform(matrix M, vector4 p)
{
return vector4(M[0][0] * p.x + M[0][1] * p.y + M[0][2] * p.z + M[0][2] * p.w,
M[1][0] * p.x + M[1][1] * p.y + M[1][2] * p.z + M[1][2] * p.w,
M[2][0] * p.x + M[2][1] * p.y + M[2][2] * p.z + M[2][2] * p.w,
M[3][0] * p.x + M[3][1] * p.y + M[3][2] * p.z + M[3][2] * p.w);
}
vector4 transform(string fromspace, string tospace, vector4 p)
{
return transform(matrix(fromspace, tospace), p);
}

View File

@@ -158,11 +158,10 @@ CCL_NAMESPACE_END
/* Nodes */
#include "kernel/svm/svm_noise.h"
#include "svm_fractal_noise.h"
#include "svm_texture.h"
#include "kernel/svm/svm_color_util.h"
#include "kernel/svm/svm_math_util.h"
#include "kernel/svm/svm_mapping_util.h"
#include "kernel/svm/svm_attribute.h"
#include "kernel/svm/svm_gradient.h"
@@ -314,7 +313,7 @@ ccl_device_noinline void svm_eval_nodes(KernelGlobals *kg,
svm_node_tex_image_box(kg, sd, stack, node);
break;
case NODE_TEX_NOISE:
svm_node_tex_noise(kg, sd, stack, node.y, node.z, node.w, &offset);
svm_node_tex_noise(kg, sd, stack, node, &offset);
break;
# endif /* __TEXTURES__ */
# ifdef __EXTRA_NODES__
@@ -406,11 +405,8 @@ ccl_device_noinline void svm_eval_nodes(KernelGlobals *kg,
#endif /* NODES_GROUP(NODE_GROUP_LEVEL_1) */
#if NODES_GROUP(NODE_GROUP_LEVEL_2)
case NODE_TEXTURE_MAPPING:
svm_node_texture_mapping(kg, sd, stack, node.y, node.z, &offset);
break;
case NODE_MAPPING:
svm_node_mapping(kg, sd, stack, node.y, node.z, node.w, &offset);
svm_node_mapping(kg, sd, stack, node.y, node.z, &offset);
break;
case NODE_MIN_MAX:
svm_node_min_max(kg, sd, stack, node.y, node.z, &offset);
@@ -432,7 +428,7 @@ ccl_device_noinline void svm_eval_nodes(KernelGlobals *kg,
svm_node_tex_voronoi(kg, sd, stack, node, &offset);
break;
case NODE_TEX_MUSGRAVE:
svm_node_tex_musgrave(kg, sd, stack, node.y, node.z, node.w, &offset);
svm_node_tex_musgrave(kg, sd, stack, node, &offset);
break;
case NODE_TEX_WAVE:
svm_node_tex_wave(kg, sd, stack, node, &offset);

View File

@@ -1,131 +0,0 @@
/*
* Copyright 2011-2013 Blender Foundation
*
* 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* 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.
*/
CCL_NAMESPACE_BEGIN
/* The fractal_noise_[1-4] functions are all exactly the same except for the input type. */
ccl_device_noinline float fractal_noise_1d(float p, float octaves)
{
float fscale = 1.0f;
float amp = 1.0f;
float sum = 0.0f;
octaves = clamp(octaves, 0.0f, 16.0f);
int n = float_to_int(octaves);
for (int i = 0; i <= n; i++) {
float t = noise_1d(fscale * p);
sum += t * amp;
amp *= 0.5f;
fscale *= 2.0f;
}
float rmd = octaves - floorf(octaves);
if (rmd != 0.0f) {
float t = noise_1d(fscale * p);
float sum2 = sum + t * amp;
sum *= ((float)(1 << n) / (float)((1 << (n + 1)) - 1));
sum2 *= ((float)(1 << (n + 1)) / (float)((1 << (n + 2)) - 1));
return (1.0f - rmd) * sum + rmd * sum2;
}
else {
sum *= ((float)(1 << n) / (float)((1 << (n + 1)) - 1));
return sum;
}
}
/* The fractal_noise_[1-4] functions are all exactly the same except for the input type. */
ccl_device_noinline float fractal_noise_2d(float2 p, float octaves)
{
float fscale = 1.0f;
float amp = 1.0f;
float sum = 0.0f;
octaves = clamp(octaves, 0.0f, 16.0f);
int n = float_to_int(octaves);
for (int i = 0; i <= n; i++) {
float t = noise_2d(fscale * p);
sum += t * amp;
amp *= 0.5f;
fscale *= 2.0f;
}
float rmd = octaves - floorf(octaves);
if (rmd != 0.0f) {
float t = noise_2d(fscale * p);
float sum2 = sum + t * amp;
sum *= ((float)(1 << n) / (float)((1 << (n + 1)) - 1));
sum2 *= ((float)(1 << (n + 1)) / (float)((1 << (n + 2)) - 1));
return (1.0f - rmd) * sum + rmd * sum2;
}
else {
sum *= ((float)(1 << n) / (float)((1 << (n + 1)) - 1));
return sum;
}
}
/* The fractal_noise_[1-4] functions are all exactly the same except for the input type. */
ccl_device_noinline float fractal_noise_3d(float3 p, float octaves)
{
float fscale = 1.0f;
float amp = 1.0f;
float sum = 0.0f;
octaves = clamp(octaves, 0.0f, 16.0f);
int n = float_to_int(octaves);
for (int i = 0; i <= n; i++) {
float t = noise_3d(fscale * p);
sum += t * amp;
amp *= 0.5f;
fscale *= 2.0f;
}
float rmd = octaves - floorf(octaves);
if (rmd != 0.0f) {
float t = noise_3d(fscale * p);
float sum2 = sum + t * amp;
sum *= ((float)(1 << n) / (float)((1 << (n + 1)) - 1));
sum2 *= ((float)(1 << (n + 1)) / (float)((1 << (n + 2)) - 1));
return (1.0f - rmd) * sum + rmd * sum2;
}
else {
sum *= ((float)(1 << n) / (float)((1 << (n + 1)) - 1));
return sum;
}
}
/* The fractal_noise_[1-4] functions are all exactly the same except for the input type. */
ccl_device_noinline float fractal_noise_4d(float4 p, float octaves)
{
float fscale = 1.0f;
float amp = 1.0f;
float sum = 0.0f;
octaves = clamp(octaves, 0.0f, 16.0f);
int n = float_to_int(octaves);
for (int i = 0; i <= n; i++) {
float t = noise_4d(fscale * p);
sum += t * amp;
amp *= 0.5f;
fscale *= 2.0f;
}
float rmd = octaves - floorf(octaves);
if (rmd != 0.0f) {
float t = noise_4d(fscale * p);
float sum2 = sum + t * amp;
sum *= ((float)(1 << n) / (float)((1 << (n + 1)) - 1));
sum2 *= ((float)(1 << (n + 1)) / (float)((1 << (n + 2)) - 1));
return (1.0f - rmd) * sum + rmd * sum2;
}
else {
sum *= ((float)(1 << n) / (float)((1 << (n + 1)) - 1));
return sum;
}
}
CCL_NAMESPACE_END

View File

@@ -18,33 +18,7 @@ CCL_NAMESPACE_BEGIN
/* Mapping Node */
ccl_device void svm_node_mapping(KernelGlobals *kg,
ShaderData *sd,
float *stack,
uint type,
uint inputs_stack_offsets,
uint result_stack_offset,
int *offset)
{
uint vector_stack_offset, location_stack_offset, rotation_stack_offset, scale_stack_offset;
svm_unpack_node_uchar4(inputs_stack_offsets,
&vector_stack_offset,
&location_stack_offset,
&rotation_stack_offset,
&scale_stack_offset);
float3 vector = stack_load_float3(stack, vector_stack_offset);
float3 location = stack_load_float3(stack, location_stack_offset);
float3 rotation = stack_load_float3(stack, rotation_stack_offset);
float3 scale = stack_load_float3(stack, scale_stack_offset);
float3 result = svm_mapping((NodeMappingType)type, vector, location, rotation, scale);
stack_store_float3(stack, result_stack_offset, result);
}
/* Texture Mapping */
ccl_device void svm_node_texture_mapping(
ccl_device void svm_node_mapping(
KernelGlobals *kg, ShaderData *sd, float *stack, uint vec_offset, uint out_offset, int *offset)
{
float3 v = stack_load_float3(stack, vec_offset);

View File

@@ -1,39 +0,0 @@
/*
* Copyright 2011-2014 Blender Foundation
*
* 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* 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.
*/
CCL_NAMESPACE_BEGIN
ccl_device float3
svm_mapping(NodeMappingType type, float3 vector, float3 location, float3 rotation, float3 scale)
{
Transform rotationTransform = euler_to_transform(rotation);
switch (type) {
case NODE_MAPPING_TYPE_POINT:
return transform_direction(&rotationTransform, (vector * scale)) + location;
case NODE_MAPPING_TYPE_TEXTURE:
return safe_divide_float3_float3(
transform_direction_transposed(&rotationTransform, (vector - location)), scale);
case NODE_MAPPING_TYPE_VECTOR:
return transform_direction(&rotationTransform, (vector * scale));
case NODE_MAPPING_TYPE_NORMAL:
return safe_normalize(
transform_direction(&rotationTransform, safe_divide_float3_float3(vector, scale)));
default:
return make_float3(0.0f, 0.0f, 0.0f);
}
}
CCL_NAMESPACE_END

View File

@@ -16,7 +16,7 @@
CCL_NAMESPACE_BEGIN
/* 1D Musgrave fBm
/* Musgrave fBm
*
* H: fractal increment parameter
* lacunarity: gap between successive frequencies
@@ -25,62 +25,62 @@ CCL_NAMESPACE_BEGIN
* from "Texturing and Modelling: A procedural approach"
*/
ccl_device_noinline_cpu float noise_musgrave_fBm_1d(float co,
float H,
float lacunarity,
float octaves)
ccl_device_noinline_cpu float noise_musgrave_fBm(float3 p,
float H,
float lacunarity,
float octaves)
{
float p = co;
float rmd;
float value = 0.0f;
float pwr = 1.0f;
float pwHL = powf(lacunarity, -H);
int i;
for (int i = 0; i < float_to_int(octaves); i++) {
value += snoise_1d(p) * pwr;
for (i = 0; i < float_to_int(octaves); i++) {
value += snoise(p) * pwr;
pwr *= pwHL;
p *= lacunarity;
}
float rmd = octaves - floorf(octaves);
if (rmd != 0.0f) {
value += rmd * snoise_1d(p) * pwr;
}
rmd = octaves - floorf(octaves);
if (rmd != 0.0f)
value += rmd * snoise(p) * pwr;
return value;
}
/* 1D Musgrave Multifractal
/* Musgrave Multifractal
*
* H: highest fractal dimension
* lacunarity: gap between successive frequencies
* octaves: number of frequencies in the fBm
*/
ccl_device_noinline_cpu float noise_musgrave_multi_fractal_1d(float co,
float H,
float lacunarity,
float octaves)
ccl_device_noinline_cpu float noise_musgrave_multi_fractal(float3 p,
float H,
float lacunarity,
float octaves)
{
float p = co;
float rmd;
float value = 1.0f;
float pwr = 1.0f;
float pwHL = powf(lacunarity, -H);
int i;
for (int i = 0; i < float_to_int(octaves); i++) {
value *= (pwr * snoise_1d(p) + 1.0f);
for (i = 0; i < float_to_int(octaves); i++) {
value *= (pwr * snoise(p) + 1.0f);
pwr *= pwHL;
p *= lacunarity;
}
float rmd = octaves - floorf(octaves);
if (rmd != 0.0f) {
value *= (rmd * pwr * snoise_1d(p) + 1.0f); /* correct? */
}
rmd = octaves - floorf(octaves);
if (rmd != 0.0f)
value *= (rmd * pwr * snoise(p) + 1.0f); /* correct? */
return value;
}
/* 1D Musgrave Heterogeneous Terrain
/* Musgrave Heterogeneous Terrain
*
* H: fractal dimension of the roughest area
* lacunarity: gap between successive frequencies
@@ -88,34 +88,35 @@ ccl_device_noinline_cpu float noise_musgrave_multi_fractal_1d(float co,
* offset: raises the terrain from `sea level'
*/
ccl_device_noinline_cpu float noise_musgrave_hetero_terrain_1d(
float co, float H, float lacunarity, float octaves, float offset)
ccl_device_noinline_cpu float noise_musgrave_hetero_terrain(
float3 p, float H, float lacunarity, float octaves, float offset)
{
float p = co;
float value, increment, rmd;
float pwHL = powf(lacunarity, -H);
float pwr = pwHL;
int i;
/* first unscaled octave of function; later octaves are scaled */
float value = offset + snoise_1d(p);
value = offset + snoise(p);
p *= lacunarity;
for (int i = 1; i < float_to_int(octaves); i++) {
float increment = (snoise_1d(p) + offset) * pwr * value;
for (i = 1; i < float_to_int(octaves); i++) {
increment = (snoise(p) + offset) * pwr * value;
value += increment;
pwr *= pwHL;
p *= lacunarity;
}
float rmd = octaves - floorf(octaves);
rmd = octaves - floorf(octaves);
if (rmd != 0.0f) {
float increment = (snoise_1d(p) + offset) * pwr * value;
increment = (snoise(p) + offset) * pwr * value;
value += rmd * increment;
}
return value;
}
/* 1D Hybrid Additive/Multiplicative Multifractal Terrain
/* Hybrid Additive/Multiplicative Multifractal Terrain
*
* H: fractal dimension of the roughest area
* lacunarity: gap between successive frequencies
@@ -123,38 +124,37 @@ ccl_device_noinline_cpu float noise_musgrave_hetero_terrain_1d(
* offset: raises the terrain from `sea level'
*/
ccl_device_noinline_cpu float noise_musgrave_hybrid_multi_fractal_1d(
float co, float H, float lacunarity, float octaves, float offset, float gain)
ccl_device_noinline_cpu float noise_musgrave_hybrid_multi_fractal(
float3 p, float H, float lacunarity, float octaves, float offset, float gain)
{
float p = co;
float result, signal, weight, rmd;
float pwHL = powf(lacunarity, -H);
float pwr = pwHL;
int i;
float value = snoise_1d(p) + offset;
float weight = gain * value;
result = snoise(p) + offset;
weight = gain * result;
p *= lacunarity;
for (int i = 1; (weight > 0.001f) && (i < float_to_int(octaves)); i++) {
if (weight > 1.0f) {
for (i = 1; (weight > 0.001f) && (i < float_to_int(octaves)); i++) {
if (weight > 1.0f)
weight = 1.0f;
}
float signal = (snoise_1d(p) + offset) * pwr;
signal = (snoise(p) + offset) * pwr;
pwr *= pwHL;
value += weight * signal;
result += weight * signal;
weight *= gain * signal;
p *= lacunarity;
}
float rmd = octaves - floorf(octaves);
if (rmd != 0.0f) {
value += rmd * ((snoise_1d(p) + offset) * pwr);
}
rmd = octaves - floorf(octaves);
if (rmd != 0.0f)
result += rmd * ((snoise(p) + offset) * pwr);
return value;
return result;
}
/* 1D Ridged Multifractal Terrain
/* Ridged Multifractal Terrain
*
* H: fractal dimension of the roughest area
* lacunarity: gap between successive frequencies
@@ -162,688 +162,93 @@ ccl_device_noinline_cpu float noise_musgrave_hybrid_multi_fractal_1d(
* offset: raises the terrain from `sea level'
*/
ccl_device_noinline_cpu float noise_musgrave_ridged_multi_fractal_1d(
float co, float H, float lacunarity, float octaves, float offset, float gain)
ccl_device_noinline_cpu float noise_musgrave_ridged_multi_fractal(
float3 p, float H, float lacunarity, float octaves, float offset, float gain)
{
float p = co;
float result, signal, weight;
float pwHL = powf(lacunarity, -H);
float pwr = pwHL;
int i;
float signal = offset - fabsf(snoise_1d(p));
signal = offset - fabsf(snoise(p));
signal *= signal;
float value = signal;
float weight = 1.0f;
result = signal;
weight = 1.0f;
for (int i = 1; i < float_to_int(octaves); i++) {
for (i = 1; i < float_to_int(octaves); i++) {
p *= lacunarity;
weight = saturate(signal * gain);
signal = offset - fabsf(snoise_1d(p));
signal = offset - fabsf(snoise(p));
signal *= signal;
signal *= weight;
value += signal * pwr;
result += signal * pwr;
pwr *= pwHL;
}
return value;
return result;
}
/* 2D Musgrave fBm
*
* H: fractal increment parameter
* lacunarity: gap between successive frequencies
* octaves: number of frequencies in the fBm
*
* from "Texturing and Modelling: A procedural approach"
*/
/* Shader */
ccl_device_noinline_cpu float noise_musgrave_fBm_2d(float2 co,
float H,
float lacunarity,
float octaves)
ccl_device float svm_musgrave(NodeMusgraveType type,
float dimension,
float lacunarity,
float octaves,
float offset,
float intensity,
float gain,
float3 p)
{
float2 p = co;
float value = 0.0f;
float pwr = 1.0f;
float pwHL = powf(lacunarity, -H);
if (type == NODE_MUSGRAVE_MULTIFRACTAL)
return intensity * noise_musgrave_multi_fractal(p, dimension, lacunarity, octaves);
else if (type == NODE_MUSGRAVE_FBM)
return intensity * noise_musgrave_fBm(p, dimension, lacunarity, octaves);
else if (type == NODE_MUSGRAVE_HYBRID_MULTIFRACTAL)
return intensity *
noise_musgrave_hybrid_multi_fractal(p, dimension, lacunarity, octaves, offset, gain);
else if (type == NODE_MUSGRAVE_RIDGED_MULTIFRACTAL)
return intensity *
noise_musgrave_ridged_multi_fractal(p, dimension, lacunarity, octaves, offset, gain);
else if (type == NODE_MUSGRAVE_HETERO_TERRAIN)
return intensity * noise_musgrave_hetero_terrain(p, dimension, lacunarity, octaves, offset);
for (int i = 0; i < float_to_int(octaves); i++) {
value += snoise_2d(p) * pwr;
pwr *= pwHL;
p *= lacunarity;
}
float rmd = octaves - floorf(octaves);
if (rmd != 0.0f) {
value += rmd * snoise_2d(p) * pwr;
}
return value;
return 0.0f;
}
/* 2D Musgrave Multifractal
*
* H: highest fractal dimension
* lacunarity: gap between successive frequencies
* octaves: number of frequencies in the fBm
*/
ccl_device_noinline_cpu float noise_musgrave_multi_fractal_2d(float2 co,
float H,
float lacunarity,
float octaves)
ccl_device void svm_node_tex_musgrave(
KernelGlobals *kg, ShaderData *sd, float *stack, uint4 node, int *offset)
{
float2 p = co;
float value = 1.0f;
float pwr = 1.0f;
float pwHL = powf(lacunarity, -H);
for (int i = 0; i < float_to_int(octaves); i++) {
value *= (pwr * snoise_2d(p) + 1.0f);
pwr *= pwHL;
p *= lacunarity;
}
float rmd = octaves - floorf(octaves);
if (rmd != 0.0f) {
value *= (rmd * pwr * snoise_2d(p) + 1.0f); /* correct? */
}
return value;
}
/* 2D Musgrave Heterogeneous Terrain
*
* H: fractal dimension of the roughest area
* lacunarity: gap between successive frequencies
* octaves: number of frequencies in the fBm
* offset: raises the terrain from `sea level'
*/
ccl_device_noinline_cpu float noise_musgrave_hetero_terrain_2d(
float2 co, float H, float lacunarity, float octaves, float offset)
{
float2 p = co;
float pwHL = powf(lacunarity, -H);
float pwr = pwHL;
/* first unscaled octave of function; later octaves are scaled */
float value = offset + snoise_2d(p);
p *= lacunarity;
for (int i = 1; i < float_to_int(octaves); i++) {
float increment = (snoise_2d(p) + offset) * pwr * value;
value += increment;
pwr *= pwHL;
p *= lacunarity;
}
float rmd = octaves - floorf(octaves);
if (rmd != 0.0f) {
float increment = (snoise_2d(p) + offset) * pwr * value;
value += rmd * increment;
}
return value;
}
/* 2D Hybrid Additive/Multiplicative Multifractal Terrain
*
* H: fractal dimension of the roughest area
* lacunarity: gap between successive frequencies
* octaves: number of frequencies in the fBm
* offset: raises the terrain from `sea level'
*/
ccl_device_noinline_cpu float noise_musgrave_hybrid_multi_fractal_2d(
float2 co, float H, float lacunarity, float octaves, float offset, float gain)
{
float2 p = co;
float pwHL = powf(lacunarity, -H);
float pwr = pwHL;
float value = snoise_2d(p) + offset;
float weight = gain * value;
p *= lacunarity;
for (int i = 1; (weight > 0.001f) && (i < float_to_int(octaves)); i++) {
if (weight > 1.0f) {
weight = 1.0f;
}
float signal = (snoise_2d(p) + offset) * pwr;
pwr *= pwHL;
value += weight * signal;
weight *= gain * signal;
p *= lacunarity;
}
float rmd = octaves - floorf(octaves);
if (rmd != 0.0f) {
value += rmd * ((snoise_2d(p) + offset) * pwr);
}
return value;
}
/* 2D Ridged Multifractal Terrain
*
* H: fractal dimension of the roughest area
* lacunarity: gap between successive frequencies
* octaves: number of frequencies in the fBm
* offset: raises the terrain from `sea level'
*/
ccl_device_noinline_cpu float noise_musgrave_ridged_multi_fractal_2d(
float2 co, float H, float lacunarity, float octaves, float offset, float gain)
{
float2 p = co;
float pwHL = powf(lacunarity, -H);
float pwr = pwHL;
float signal = offset - fabsf(snoise_2d(p));
signal *= signal;
float value = signal;
float weight = 1.0f;
for (int i = 1; i < float_to_int(octaves); i++) {
p *= lacunarity;
weight = saturate(signal * gain);
signal = offset - fabsf(snoise_2d(p));
signal *= signal;
signal *= weight;
value += signal * pwr;
pwr *= pwHL;
}
return value;
}
/* 3D Musgrave fBm
*
* H: fractal increment parameter
* lacunarity: gap between successive frequencies
* octaves: number of frequencies in the fBm
*
* from "Texturing and Modelling: A procedural approach"
*/
ccl_device_noinline_cpu float noise_musgrave_fBm_3d(float3 co,
float H,
float lacunarity,
float octaves)
{
float3 p = co;
float value = 0.0f;
float pwr = 1.0f;
float pwHL = powf(lacunarity, -H);
for (int i = 0; i < float_to_int(octaves); i++) {
value += snoise_3d(p) * pwr;
pwr *= pwHL;
p *= lacunarity;
}
float rmd = octaves - floorf(octaves);
if (rmd != 0.0f) {
value += rmd * snoise_3d(p) * pwr;
}
return value;
}
/* 3D Musgrave Multifractal
*
* H: highest fractal dimension
* lacunarity: gap between successive frequencies
* octaves: number of frequencies in the fBm
*/
ccl_device_noinline_cpu float noise_musgrave_multi_fractal_3d(float3 co,
float H,
float lacunarity,
float octaves)
{
float3 p = co;
float value = 1.0f;
float pwr = 1.0f;
float pwHL = powf(lacunarity, -H);
for (int i = 0; i < float_to_int(octaves); i++) {
value *= (pwr * snoise_3d(p) + 1.0f);
pwr *= pwHL;
p *= lacunarity;
}
float rmd = octaves - floorf(octaves);
if (rmd != 0.0f) {
value *= (rmd * pwr * snoise_3d(p) + 1.0f); /* correct? */
}
return value;
}
/* 3D Musgrave Heterogeneous Terrain
*
* H: fractal dimension of the roughest area
* lacunarity: gap between successive frequencies
* octaves: number of frequencies in the fBm
* offset: raises the terrain from `sea level'
*/
ccl_device_noinline_cpu float noise_musgrave_hetero_terrain_3d(
float3 co, float H, float lacunarity, float octaves, float offset)
{
float3 p = co;
float pwHL = powf(lacunarity, -H);
float pwr = pwHL;
/* first unscaled octave of function; later octaves are scaled */
float value = offset + snoise_3d(p);
p *= lacunarity;
for (int i = 1; i < float_to_int(octaves); i++) {
float increment = (snoise_3d(p) + offset) * pwr * value;
value += increment;
pwr *= pwHL;
p *= lacunarity;
}
float rmd = octaves - floorf(octaves);
if (rmd != 0.0f) {
float increment = (snoise_3d(p) + offset) * pwr * value;
value += rmd * increment;
}
return value;
}
/* 3D Hybrid Additive/Multiplicative Multifractal Terrain
*
* H: fractal dimension of the roughest area
* lacunarity: gap between successive frequencies
* octaves: number of frequencies in the fBm
* offset: raises the terrain from `sea level'
*/
ccl_device_noinline_cpu float noise_musgrave_hybrid_multi_fractal_3d(
float3 co, float H, float lacunarity, float octaves, float offset, float gain)
{
float3 p = co;
float pwHL = powf(lacunarity, -H);
float pwr = pwHL;
float value = snoise_3d(p) + offset;
float weight = gain * value;
p *= lacunarity;
for (int i = 1; (weight > 0.001f) && (i < float_to_int(octaves)); i++) {
if (weight > 1.0f) {
weight = 1.0f;
}
float signal = (snoise_3d(p) + offset) * pwr;
pwr *= pwHL;
value += weight * signal;
weight *= gain * signal;
p *= lacunarity;
}
float rmd = octaves - floorf(octaves);
if (rmd != 0.0f) {
value += rmd * ((snoise_3d(p) + offset) * pwr);
}
return value;
}
/* 3D Ridged Multifractal Terrain
*
* H: fractal dimension of the roughest area
* lacunarity: gap between successive frequencies
* octaves: number of frequencies in the fBm
* offset: raises the terrain from `sea level'
*/
ccl_device_noinline_cpu float noise_musgrave_ridged_multi_fractal_3d(
float3 co, float H, float lacunarity, float octaves, float offset, float gain)
{
float3 p = co;
float pwHL = powf(lacunarity, -H);
float pwr = pwHL;
float signal = offset - fabsf(snoise_3d(p));
signal *= signal;
float value = signal;
float weight = 1.0f;
for (int i = 1; i < float_to_int(octaves); i++) {
p *= lacunarity;
weight = saturate(signal * gain);
signal = offset - fabsf(snoise_3d(p));
signal *= signal;
signal *= weight;
value += signal * pwr;
pwr *= pwHL;
}
return value;
}
/* 4D Musgrave fBm
*
* H: fractal increment parameter
* lacunarity: gap between successive frequencies
* octaves: number of frequencies in the fBm
*
* from "Texturing and Modelling: A procedural approach"
*/
ccl_device_noinline_cpu float noise_musgrave_fBm_4d(float4 co,
float H,
float lacunarity,
float octaves)
{
float4 p = co;
float value = 0.0f;
float pwr = 1.0f;
float pwHL = powf(lacunarity, -H);
for (int i = 0; i < float_to_int(octaves); i++) {
value += snoise_4d(p) * pwr;
pwr *= pwHL;
p *= lacunarity;
}
float rmd = octaves - floorf(octaves);
if (rmd != 0.0f) {
value += rmd * snoise_4d(p) * pwr;
}
return value;
}
/* 4D Musgrave Multifractal
*
* H: highest fractal dimension
* lacunarity: gap between successive frequencies
* octaves: number of frequencies in the fBm
*/
ccl_device_noinline_cpu float noise_musgrave_multi_fractal_4d(float4 co,
float H,
float lacunarity,
float octaves)
{
float4 p = co;
float value = 1.0f;
float pwr = 1.0f;
float pwHL = powf(lacunarity, -H);
for (int i = 0; i < float_to_int(octaves); i++) {
value *= (pwr * snoise_4d(p) + 1.0f);
pwr *= pwHL;
p *= lacunarity;
}
float rmd = octaves - floorf(octaves);
if (rmd != 0.0f) {
value *= (rmd * pwr * snoise_4d(p) + 1.0f); /* correct? */
}
return value;
}
/* 4D Musgrave Heterogeneous Terrain
*
* H: fractal dimension of the roughest area
* lacunarity: gap between successive frequencies
* octaves: number of frequencies in the fBm
* offset: raises the terrain from `sea level'
*/
ccl_device_noinline_cpu float noise_musgrave_hetero_terrain_4d(
float4 co, float H, float lacunarity, float octaves, float offset)
{
float4 p = co;
float pwHL = powf(lacunarity, -H);
float pwr = pwHL;
/* first unscaled octave of function; later octaves are scaled */
float value = offset + snoise_4d(p);
p *= lacunarity;
for (int i = 1; i < float_to_int(octaves); i++) {
float increment = (snoise_4d(p) + offset) * pwr * value;
value += increment;
pwr *= pwHL;
p *= lacunarity;
}
float rmd = octaves - floorf(octaves);
if (rmd != 0.0f) {
float increment = (snoise_4d(p) + offset) * pwr * value;
value += rmd * increment;
}
return value;
}
/* 4D Hybrid Additive/Multiplicative Multifractal Terrain
*
* H: fractal dimension of the roughest area
* lacunarity: gap between successive frequencies
* octaves: number of frequencies in the fBm
* offset: raises the terrain from `sea level'
*/
ccl_device_noinline_cpu float noise_musgrave_hybrid_multi_fractal_4d(
float4 co, float H, float lacunarity, float octaves, float offset, float gain)
{
float4 p = co;
float pwHL = powf(lacunarity, -H);
float pwr = pwHL;
float value = snoise_4d(p) + offset;
float weight = gain * value;
p *= lacunarity;
for (int i = 1; (weight > 0.001f) && (i < float_to_int(octaves)); i++) {
if (weight > 1.0f) {
weight = 1.0f;
}
float signal = (snoise_4d(p) + offset) * pwr;
pwr *= pwHL;
value += weight * signal;
weight *= gain * signal;
p *= lacunarity;
}
float rmd = octaves - floorf(octaves);
if (rmd != 0.0f) {
value += rmd * ((snoise_4d(p) + offset) * pwr);
}
return value;
}
/* 4D Ridged Multifractal Terrain
*
* H: fractal dimension of the roughest area
* lacunarity: gap between successive frequencies
* octaves: number of frequencies in the fBm
* offset: raises the terrain from `sea level'
*/
ccl_device_noinline_cpu float noise_musgrave_ridged_multi_fractal_4d(
float4 co, float H, float lacunarity, float octaves, float offset, float gain)
{
float4 p = co;
float pwHL = powf(lacunarity, -H);
float pwr = pwHL;
float signal = offset - fabsf(snoise_4d(p));
signal *= signal;
float value = signal;
float weight = 1.0f;
for (int i = 1; i < float_to_int(octaves); i++) {
p *= lacunarity;
weight = saturate(signal * gain);
signal = offset - fabsf(snoise_4d(p));
signal *= signal;
signal *= weight;
value += signal * pwr;
pwr *= pwHL;
}
return value;
}
ccl_device void svm_node_tex_musgrave(KernelGlobals *kg,
ShaderData *sd,
float *stack,
uint offsets1,
uint offsets2,
uint offsets3,
int *offset)
{
uint type, dimensions, co_stack_offset, w_stack_offset;
uint scale_stack_offset, detail_stack_offset, dimension_stack_offset, lacunarity_stack_offset;
uint offset_stack_offset, gain_stack_offset, fac_stack_offset;
svm_unpack_node_uchar4(offsets1, &type, &dimensions, &co_stack_offset, &w_stack_offset);
svm_unpack_node_uchar4(offsets2,
&scale_stack_offset,
&detail_stack_offset,
&dimension_stack_offset,
&lacunarity_stack_offset);
svm_unpack_node_uchar3(offsets3, &offset_stack_offset, &gain_stack_offset, &fac_stack_offset);
uint4 defaults1 = read_node(kg, offset);
uint4 defaults2 = read_node(kg, offset);
float3 co = stack_load_float3(stack, co_stack_offset);
float w = stack_load_float_default(stack, w_stack_offset, defaults1.x);
float scale = stack_load_float_default(stack, scale_stack_offset, defaults1.y);
float detail = stack_load_float_default(stack, detail_stack_offset, defaults1.z);
float dimension = stack_load_float_default(stack, dimension_stack_offset, defaults1.w);
float lacunarity = stack_load_float_default(stack, lacunarity_stack_offset, defaults2.x);
float foffset = stack_load_float_default(stack, offset_stack_offset, defaults2.y);
float gain = stack_load_float_default(stack, gain_stack_offset, defaults2.z);
uint4 node2 = read_node(kg, offset);
uint4 node3 = read_node(kg, offset);
uint type, co_offset, color_offset, fac_offset;
uint dimension_offset, lacunarity_offset, detail_offset, offset_offset;
uint gain_offset, scale_offset;
svm_unpack_node_uchar4(node.y, &type, &co_offset, &color_offset, &fac_offset);
svm_unpack_node_uchar4(
node.z, &dimension_offset, &lacunarity_offset, &detail_offset, &offset_offset);
svm_unpack_node_uchar2(node.w, &gain_offset, &scale_offset);
float3 co = stack_load_float3(stack, co_offset);
float dimension = stack_load_float_default(stack, dimension_offset, node2.x);
float lacunarity = stack_load_float_default(stack, lacunarity_offset, node2.y);
float detail = stack_load_float_default(stack, detail_offset, node2.z);
float foffset = stack_load_float_default(stack, offset_offset, node2.w);
float gain = stack_load_float_default(stack, gain_offset, node3.x);
float scale = stack_load_float_default(stack, scale_offset, node3.y);
dimension = fmaxf(dimension, 1e-5f);
detail = clamp(detail, 0.0f, 16.0f);
lacunarity = fmaxf(lacunarity, 1e-5f);
float fac;
float f = svm_musgrave(
(NodeMusgraveType)type, dimension, lacunarity, detail, foffset, 1.0f, gain, co * scale);
switch (dimensions) {
case 1: {
float p = w * scale;
switch ((NodeMusgraveType)type) {
case NODE_MUSGRAVE_MULTIFRACTAL:
fac = noise_musgrave_multi_fractal_1d(p, dimension, lacunarity, detail);
break;
case NODE_MUSGRAVE_FBM:
fac = noise_musgrave_fBm_1d(p, dimension, lacunarity, detail);
break;
case NODE_MUSGRAVE_HYBRID_MULTIFRACTAL:
fac = noise_musgrave_hybrid_multi_fractal_1d(
p, dimension, lacunarity, detail, foffset, gain);
break;
case NODE_MUSGRAVE_RIDGED_MULTIFRACTAL:
fac = noise_musgrave_ridged_multi_fractal_1d(
p, dimension, lacunarity, detail, foffset, gain);
break;
case NODE_MUSGRAVE_HETERO_TERRAIN:
fac = noise_musgrave_hetero_terrain_1d(p, dimension, lacunarity, detail, foffset);
break;
default:
fac = 0.0f;
}
break;
}
case 2: {
float2 p = make_float2(co.x, co.y) * scale;
switch ((NodeMusgraveType)type) {
case NODE_MUSGRAVE_MULTIFRACTAL:
fac = noise_musgrave_multi_fractal_2d(p, dimension, lacunarity, detail);
break;
case NODE_MUSGRAVE_FBM:
fac = noise_musgrave_fBm_2d(p, dimension, lacunarity, detail);
break;
case NODE_MUSGRAVE_HYBRID_MULTIFRACTAL:
fac = noise_musgrave_hybrid_multi_fractal_2d(
p, dimension, lacunarity, detail, foffset, gain);
break;
case NODE_MUSGRAVE_RIDGED_MULTIFRACTAL:
fac = noise_musgrave_ridged_multi_fractal_2d(
p, dimension, lacunarity, detail, foffset, gain);
break;
case NODE_MUSGRAVE_HETERO_TERRAIN:
fac = noise_musgrave_hetero_terrain_2d(p, dimension, lacunarity, detail, foffset);
break;
default:
fac = 0.0f;
}
break;
}
case 3: {
float3 p = co * scale;
switch ((NodeMusgraveType)type) {
case NODE_MUSGRAVE_MULTIFRACTAL:
fac = noise_musgrave_multi_fractal_3d(p, dimension, lacunarity, detail);
break;
case NODE_MUSGRAVE_FBM:
fac = noise_musgrave_fBm_3d(p, dimension, lacunarity, detail);
break;
case NODE_MUSGRAVE_HYBRID_MULTIFRACTAL:
fac = noise_musgrave_hybrid_multi_fractal_3d(
p, dimension, lacunarity, detail, foffset, gain);
break;
case NODE_MUSGRAVE_RIDGED_MULTIFRACTAL:
fac = noise_musgrave_ridged_multi_fractal_3d(
p, dimension, lacunarity, detail, foffset, gain);
break;
case NODE_MUSGRAVE_HETERO_TERRAIN:
fac = noise_musgrave_hetero_terrain_3d(p, dimension, lacunarity, detail, foffset);
break;
default:
fac = 0.0f;
}
break;
}
case 4: {
float4 p = make_float4(co.x, co.y, co.z, w) * scale;
switch ((NodeMusgraveType)type) {
case NODE_MUSGRAVE_MULTIFRACTAL:
fac = noise_musgrave_multi_fractal_4d(p, dimension, lacunarity, detail);
break;
case NODE_MUSGRAVE_FBM:
fac = noise_musgrave_fBm_4d(p, dimension, lacunarity, detail);
break;
case NODE_MUSGRAVE_HYBRID_MULTIFRACTAL:
fac = noise_musgrave_hybrid_multi_fractal_4d(
p, dimension, lacunarity, detail, foffset, gain);
break;
case NODE_MUSGRAVE_RIDGED_MULTIFRACTAL:
fac = noise_musgrave_ridged_multi_fractal_4d(
p, dimension, lacunarity, detail, foffset, gain);
break;
case NODE_MUSGRAVE_HETERO_TERRAIN:
fac = noise_musgrave_hetero_terrain_4d(p, dimension, lacunarity, detail, foffset);
break;
default:
fac = 0.0f;
}
break;
}
default:
fac = 0.0f;
}
stack_store_float(stack, fac_stack_offset, fac);
if (stack_valid(fac_offset))
stack_store_float(stack, fac_offset, f);
if (stack_valid(color_offset))
stack_store_float3(stack, color_offset, make_float3(f, f, f));
}
CCL_NAMESPACE_END

View File

@@ -32,562 +32,246 @@
CCL_NAMESPACE_BEGIN
/* **** Perlin Noise **** */
#ifdef __KERNEL_SSE2__
ccl_device_inline ssei quick_floor_sse(const ssef &x)
{
ssei b = truncatei(x);
ssei isneg = cast((x < ssef(0.0f)).m128);
return b + isneg; // unsaturated add 0xffffffff is the same as subtract -1
}
#endif
#ifdef __KERNEL_SSE2__
ccl_device_inline ssei hash_sse(const ssei &kx, const ssei &ky, const ssei &kz)
{
# define rot(x, k) (((x) << (k)) | (srl(x, 32 - (k))))
# define xor_rot(a, b, c) \
do { \
a = a ^ b; \
a = a - rot(b, c); \
} while (0)
uint len = 3;
ssei magic = ssei(0xdeadbeef + (len << 2) + 13);
ssei a = magic + kx;
ssei b = magic + ky;
ssei c = magic + kz;
xor_rot(c, b, 14);
xor_rot(a, c, 11);
xor_rot(b, a, 25);
xor_rot(c, b, 16);
xor_rot(a, c, 4);
xor_rot(b, a, 14);
xor_rot(c, b, 24);
return c;
# undef rot
# undef xor_rot
}
#endif
#if 0 // unused
ccl_device int imod(int a, int b)
{
a %= b;
return a < 0 ? a + b : a;
}
ccl_device uint phash(int kx, int ky, int kz, int3 p)
{
return hash(imod(kx, p.x), imod(ky, p.y), imod(kz, p.z));
}
#endif
#ifndef __KERNEL_SSE2__
ccl_device float floorfrac(float x, int *i)
{
*i = quick_floor_to_int(x);
return x - *i;
}
#else
ccl_device_inline ssef floorfrac_sse(const ssef &x, ssei *i)
{
*i = quick_floor_sse(x);
return x - ssef(*i);
}
#endif
#ifndef __KERNEL_SSE2__
ccl_device float fade(float t)
{
return t * t * t * (t * (t * 6.0f - 15.0f) + 10.0f);
}
ccl_device_inline float negate_if(float val, int condition)
#else
ccl_device_inline ssef fade_sse(const ssef *t)
{
return (condition) ? -val : val;
ssef a = madd(*t, ssef(6.0f), ssef(-15.0f));
ssef b = madd(*t, a, ssef(10.0f));
return ((*t) * (*t)) * ((*t) * b);
}
#endif
ccl_device float grad1(int hash, float x)
{
int h = hash & 15;
float g = 1 + (h & 7);
return negate_if(g, h & 8) * x;
}
ccl_device_noinline_cpu float perlin_1d(float x)
{
int X;
float fx = floorfrac(x, &X);
float u = fade(fx);
return mix(grad1(hash_uint(X), fx), grad1(hash_uint(X + 1), fx - 1.0f), u);
}
/* 2D, 3D, and 4D noise can be accelerated using SSE, so we first check if
* SSE is supported, that is, if __KERNEL_SSE2__ is defined. If it is not
* supported, we do a standard implementation, but if it is supported, we
* do an implementation using SSE intrinsics.
*/
#ifndef __KERNEL_SSE2__
/* ** Standard Implementation ** */
/* Bilinear Interpolation:
*
* v2 v3
* @ + + + + @ y
* + + ^
* + + |
* + + |
* @ + + + + @ @------> x
* v0 v1
*
*/
ccl_device float bi_mix(float v0, float v1, float v2, float v3, float x, float y)
ccl_device float nerp(float t, float a, float b)
{
float x1 = 1.0f - x;
return (1.0f - y) * (v0 * x1 + v1 * x) + y * (v2 * x1 + v3 * x);
return (1.0f - t) * a + t * b;
}
/* Trilinear Interpolation:
*
* v6 v7
* @ + + + + + + @
* +\ +\
* + \ + \
* + \ + \
* + \ v4 + \ v5
* + @ + + + +++ + @ z
* + + + + y ^
* v2 @ + +++ + + + @ v3 + \ |
* \ + \ + \ |
* \ + \ + \|
* \ + \ + +---------> x
* \+ \+
* @ + + + + + + @
* v0 v1
*/
ccl_device float tri_mix(float v0,
float v1,
float v2,
float v3,
float v4,
float v5,
float v6,
float v7,
float x,
float y,
float z)
#else
ccl_device_inline ssef nerp_sse(const ssef &t, const ssef &a, const ssef &b)
{
float x1 = 1.0f - x;
float y1 = 1.0f - y;
float z1 = 1.0f - z;
return z1 * (y1 * (v0 * x1 + v1 * x) + y * (v2 * x1 + v3 * x)) +
z * (y1 * (v4 * x1 + v5 * x) + y * (v6 * x1 + v7 * x));
ssef x1 = (ssef(1.0f) - t) * a;
return madd(t, b, x1);
}
#endif
ccl_device float quad_mix(float v0,
float v1,
float v2,
float v3,
float v4,
float v5,
float v6,
float v7,
float v8,
float v9,
float v10,
float v11,
float v12,
float v13,
float v14,
float v15,
float x,
float y,
float z,
float w)
{
return mix(tri_mix(v0, v1, v2, v3, v4, v5, v6, v7, x, y, z),
tri_mix(v8, v9, v10, v11, v12, v13, v14, v15, x, y, z),
w);
}
ccl_device float grad2(int hash, float x, float y)
{
int h = hash & 7;
float u = h < 4 ? x : y;
float v = 2.0f * (h < 4 ? y : x);
return negate_if(u, h & 1) + negate_if(v, h & 2);
}
ccl_device float grad3(int hash, float x, float y, float z)
#ifndef __KERNEL_SSE2__
ccl_device float grad(int hash, float x, float y, float z)
{
// use vectors pointing to the edges of the cube
int h = hash & 15;
float u = h < 8 ? x : y;
float vt = ((h == 12) || (h == 14)) ? x : z;
float vt = ((h == 12) | (h == 14)) ? x : z;
float v = h < 4 ? y : vt;
return negate_if(u, h & 1) + negate_if(v, h & 2);
return ((h & 1) ? -u : u) + ((h & 2) ? -v : v);
}
ccl_device float grad4(int hash, float x, float y, float z, float w)
#else
ccl_device_inline ssef grad_sse(const ssei &hash, const ssef &x, const ssef &y, const ssef &z)
{
int h = hash & 31;
float u = h < 24 ? x : y;
float v = h < 16 ? y : z;
float s = h < 8 ? z : w;
return negate_if(u, h & 1) + negate_if(v, h & 2) + negate_if(s, h & 4);
}
ssei c1 = ssei(1);
ssei c2 = ssei(2);
ccl_device_noinline_cpu float perlin_2d(float x, float y)
{
int X;
int Y;
ssei h = hash & ssei(15); // h = hash & 15
float fx = floorfrac(x, &X);
float fy = floorfrac(y, &Y);
sseb case_ux = h < ssei(8); // 0xffffffff if h < 8 else 0
float u = fade(fx);
float v = fade(fy);
ssef u = select(case_ux, x, y); // u = h<8 ? x : y
float r = bi_mix(grad2(hash_uint2(X, Y), fx, fy),
grad2(hash_uint2(X + 1, Y), fx - 1.0f, fy),
grad2(hash_uint2(X, Y + 1), fx, fy - 1.0f),
grad2(hash_uint2(X + 1, Y + 1), fx - 1.0f, fy - 1.0f),
u,
v);
sseb case_vy = h < ssei(4); // 0xffffffff if h < 4 else 0
sseb case_h12 = h == ssei(12); // 0xffffffff if h == 12 else 0
sseb case_h14 = h == ssei(14); // 0xffffffff if h == 14 else 0
sseb case_vx = case_h12 | case_h14; // 0xffffffff if h == 12 or h == 14 else 0
ssef v = select(case_vy, y, select(case_vx, x, z)); // v = h<4 ? y : h == 12 || h == 14 ? x : z
ssei case_uneg = (h & c1) << 31; // 1<<31 if h&1 else 0
ssef case_uneg_mask = cast(case_uneg); // -0.0 if h&1 else +0.0
ssef ru = u ^ case_uneg_mask; // -u if h&1 else u (copy float sign)
ssei case_vneg = (h & c2) << 30; // 2<<30 if h&2 else 0
ssef case_vneg_mask = cast(case_vneg); // -0.0 if h&2 else +0.0
ssef rv = v ^ case_vneg_mask; // -v if h&2 else v (copy float sign)
ssef r = ru + rv; // ((h&1) ? -u : u) + ((h&2) ? -v : v)
return r;
}
#endif
ccl_device_noinline_cpu float perlin_3d(float x, float y, float z)
#ifndef __KERNEL_SSE2__
ccl_device float scale3(float result)
{
return 0.9820f * result;
}
#else
ccl_device_inline ssef scale3_sse(const ssef &result)
{
return ssef(0.9820f) * result;
}
#endif
#ifndef __KERNEL_SSE2__
ccl_device_noinline_cpu float perlin(float x, float y, float z)
{
int X;
int Y;
int Z;
float fx = floorfrac(x, &X);
int Y;
float fy = floorfrac(y, &Y);
int Z;
float fz = floorfrac(z, &Z);
float u = fade(fx);
float v = fade(fy);
float w = fade(fz);
float r = tri_mix(grad3(hash_uint3(X, Y, Z), fx, fy, fz),
grad3(hash_uint3(X + 1, Y, Z), fx - 1.0f, fy, fz),
grad3(hash_uint3(X, Y + 1, Z), fx, fy - 1.0f, fz),
grad3(hash_uint3(X + 1, Y + 1, Z), fx - 1.0f, fy - 1.0f, fz),
grad3(hash_uint3(X, Y, Z + 1), fx, fy, fz - 1.0f),
grad3(hash_uint3(X + 1, Y, Z + 1), fx - 1.0f, fy, fz - 1.0f),
grad3(hash_uint3(X, Y + 1, Z + 1), fx, fy - 1.0f, fz - 1.0f),
grad3(hash_uint3(X + 1, Y + 1, Z + 1), fx - 1.0f, fy - 1.0f, fz - 1.0f),
u,
v,
w);
return r;
float result;
result = nerp(
w,
nerp(v,
nerp(u,
grad(hash_uint3(X, Y, Z), fx, fy, fz),
grad(hash_uint3(X + 1, Y, Z), fx - 1.0f, fy, fz)),
nerp(u,
grad(hash_uint3(X, Y + 1, Z), fx, fy - 1.0f, fz),
grad(hash_uint3(X + 1, Y + 1, Z), fx - 1.0f, fy - 1.0f, fz))),
nerp(v,
nerp(u,
grad(hash_uint3(X, Y, Z + 1), fx, fy, fz - 1.0f),
grad(hash_uint3(X + 1, Y, Z + 1), fx - 1.0f, fy, fz - 1.0f)),
nerp(u,
grad(hash_uint3(X, Y + 1, Z + 1), fx, fy - 1.0f, fz - 1.0f),
grad(hash_uint3(X + 1, Y + 1, Z + 1), fx - 1.0f, fy - 1.0f, fz - 1.0f))));
float r = scale3(result);
/* can happen for big coordinates, things even out to 0.0 then anyway */
return (isfinite(r)) ? r : 0.0f;
}
ccl_device_noinline_cpu float perlin_4d(float x, float y, float z, float w)
{
int X;
int Y;
int Z;
int W;
float fx = floorfrac(x, &X);
float fy = floorfrac(y, &Y);
float fz = floorfrac(z, &Z);
float fw = floorfrac(w, &W);
float u = fade(fx);
float v = fade(fy);
float t = fade(fz);
float s = fade(fw);
float r = quad_mix(
grad4(hash_uint4(X, Y, Z, W), fx, fy, fz, fw),
grad4(hash_uint4(X + 1, Y, Z, W), fx - 1.0f, fy, fz, fw),
grad4(hash_uint4(X, Y + 1, Z, W), fx, fy - 1.0f, fz, fw),
grad4(hash_uint4(X + 1, Y + 1, Z, W), fx - 1.0f, fy - 1.0f, fz, fw),
grad4(hash_uint4(X, Y, Z + 1, W), fx, fy, fz - 1.0f, fw),
grad4(hash_uint4(X + 1, Y, Z + 1, W), fx - 1.0f, fy, fz - 1.0f, fw),
grad4(hash_uint4(X, Y + 1, Z + 1, W), fx, fy - 1.0f, fz - 1.0f, fw),
grad4(hash_uint4(X + 1, Y + 1, Z + 1, W), fx - 1.0f, fy - 1.0f, fz - 1.0f, fw),
grad4(hash_uint4(X, Y, Z, W + 1), fx, fy, fz, fw - 1.0f),
grad4(hash_uint4(X + 1, Y, Z, W + 1), fx - 1.0f, fy, fz, fw - 1.0f),
grad4(hash_uint4(X, Y + 1, Z, W + 1), fx, fy - 1.0f, fz, fw - 1.0f),
grad4(hash_uint4(X + 1, Y + 1, Z, W + 1), fx - 1.0f, fy - 1.0f, fz, fw - 1.0f),
grad4(hash_uint4(X, Y, Z + 1, W + 1), fx, fy, fz - 1.0f, fw - 1.0f),
grad4(hash_uint4(X + 1, Y, Z + 1, W + 1), fx - 1.0f, fy, fz - 1.0f, fw - 1.0f),
grad4(hash_uint4(X, Y + 1, Z + 1, W + 1), fx, fy - 1.0f, fz - 1.0f, fw - 1.0f),
grad4(hash_uint4(X + 1, Y + 1, Z + 1, W + 1), fx - 1.0f, fy - 1.0f, fz - 1.0f, fw - 1.0f),
u,
v,
t,
s);
return r;
}
#else
/* ** SSE Implementation ** */
/* SSE Bilinear Interpolation:
*
* The function takes two ssef inputs:
* - p : Contains the values at the points (v0, v1, v2, v3).
* - f : Contains the values (x, y, _, _). The third and fourth values are unused.
*
* The interpolation is done in two steps:
* 1. Interpolate (v0, v1) and (v2, v3) along the x axis to get g (g0, g1).
* (v2, v3) is generated by moving v2 and v3 to the first and second
* places of the ssef using the shuffle mask <2, 3, 2, 3>. The third and
* fourth values are unused.
* 2. Interpolate g0 and g1 along the y axis to get the final value.
* g1 is generated by populating an ssef with the second value of g.
* Only the first value is important in the final ssef.
*
* v1 v3 g1
* @ + + + + @ @ y
* + + (1) + (2) ^
* + + ---> + ---> final |
* + + + |
* @ + + + + @ @ @------> x
* v0 v2 g0
*
*/
ccl_device_inline ssef bi_mix(ssef p, ssef f)
{
ssef g = mix(p, shuffle<2, 3, 2, 3>(p), shuffle<0>(f));
return mix(g, shuffle<1>(g), shuffle<1>(f));
}
/* SSE Trilinear Interpolation:
*
* The function takes three ssef inputs:
* - p : Contains the values at the points (v0, v1, v2, v3).
* - q : Contains the values at the points (v4, v5, v6, v7).
* - f : Contains the values (x, y, z, _). The fourth value is unused.
*
* The interpolation is done in three steps:
* 1. Interpolate p and q along the x axis to get s (s0, s1, s2, s3).
* 2. Interpolate (s0, s1) and (s2, s3) along the y axis to get g (g0, g1).
* (s2, s3) is generated by moving v2 and v3 to the first and second
* places of the ssef using the shuffle mask <2, 3, 2, 3>. The third and
* fourth values are unused.
* 3. Interplate g0 and g1 along the z axis to get the final value.
* g1 is generated by populating an ssef with the second value of g.
* Only the first value is important in the final ssef.
*
* v3 v7
* @ + + + + + + @ s3 @
* +\ +\ +\
* + \ + \ + \
* + \ + \ + \ g1
* + \ v1 + \ v5 + \ s1 @
* + @ + + + +++ + @ + @ + z
* + + + + (1) + + (2) + (3) y ^
* v2 @ + +++ + + + @ v6 + ---> s2 @ + ---> + ---> final \ |
* \ + \ + \ + + \ |
* \ + \ + \ + + \|
* \ + \ + \ + @ +---------> x
* \+ \+ \+ g0
* @ + + + + + + @ @
* v0 v4 s0
*/
ccl_device_inline ssef tri_mix(ssef p, ssef q, ssef f)
{
ssef s = mix(p, q, shuffle<0>(f));
ssef g = mix(s, shuffle<2, 3, 2, 3>(s), shuffle<1>(f));
return mix(g, shuffle<1>(g), shuffle<2>(f));
}
/* SSE Quadrilinear Interpolation:
*
* Quadrilinear interpolation is as simple as a linear interpolation
* between two trilinear interpolations.
*
*/
ccl_device_inline ssef quad_mix(ssef p, ssef q, ssef r, ssef s, ssef f)
{
return mix(tri_mix(p, q, f), tri_mix(r, s, f), shuffle<3>(f));
}
ccl_device_inline ssef fade(const ssef &t)
{
ssef a = madd(t, 6.0f, -15.0f);
ssef b = madd(t, a, 10.0f);
return (t * t) * (t * b);
}
/* Negate val if the nth bit of h is 1. */
# define negate_if_nth_bit(val, h, n) ((val) ^ cast(((h) & (1 << (n))) << (31 - (n))))
ccl_device_inline ssef grad(const ssei &hash, const ssef &x, const ssef &y)
{
ssei h = hash & 7;
ssef u = select(h < 4, x, y);
ssef v = 2.0f * select(h < 4, y, x);
return negate_if_nth_bit(u, h, 0) + negate_if_nth_bit(v, h, 1);
}
ccl_device_inline ssef grad(const ssei &hash, const ssef &x, const ssef &y, const ssef &z)
{
ssei h = hash & 15;
ssef u = select(h < 8, x, y);
ssef vt = select((h == 12) | (h == 14), x, z);
ssef v = select(h < 4, y, vt);
return negate_if_nth_bit(u, h, 0) + negate_if_nth_bit(v, h, 1);
}
ccl_device_inline ssef
grad(const ssei &hash, const ssef &x, const ssef &y, const ssef &z, const ssef &w)
{
ssei h = hash & 31;
ssef u = select(h < 24, x, y);
ssef v = select(h < 16, y, z);
ssef s = select(h < 8, z, w);
return negate_if_nth_bit(u, h, 0) + negate_if_nth_bit(v, h, 1) + negate_if_nth_bit(s, h, 2);
}
/* We use SSE to compute and interpolate 4 gradients at once:
*
* Point Offset from v0
* v0 (0, 0)
* v1 (0, 1)
* v2 (1, 0) (0, 1, 0, 1) = shuffle<0, 2, 0, 2>(shuffle<1, 1, 1, 1>(V, V + 1))
* v3 (1, 1) ^
* | |__________| (0, 0, 1, 1) = shuffle<0, 0, 0, 0>(V, V + 1)
* | ^
* |__________________________|
*
*/
ccl_device_noinline float perlin_2d(float x, float y)
{
ssei XY;
ssef fxy = floorfrac(ssef(x, y, 0.0f, 0.0f), &XY);
ssef uv = fade(fxy);
ssei XY1 = XY + 1;
ssei X = shuffle<0, 0, 0, 0>(XY, XY1);
ssei Y = shuffle<0, 2, 0, 2>(shuffle<1, 1, 1, 1>(XY, XY1));
ssei h = hash_ssei2(X, Y);
ssef fxy1 = fxy - 1.0f;
ssef fx = shuffle<0, 0, 0, 0>(fxy, fxy1);
ssef fy = shuffle<0, 2, 0, 2>(shuffle<1, 1, 1, 1>(fxy, fxy1));
ssef g = grad(h, fx, fy);
return extract<0>(bi_mix(g, uv));
}
/* We use SSE to compute and interpolate 4 gradients at once. Since we have 8
* gradients in 3D, we need to compute two sets of gradients at the points:
*
* Point Offset from v0
* v0 (0, 0, 0)
* v1 (0, 0, 1)
* v2 (0, 1, 0) (0, 1, 0, 1) = shuffle<0, 2, 0, 2>(shuffle<2, 2, 2, 2>(V, V + 1))
* v3 (0, 1, 1) ^
* | |__________| (0, 0, 1, 1) = shuffle<1, 1, 1, 1>(V, V + 1)
* | ^
* |__________________________|
*
* Point Offset from v0
* v4 (1, 0, 0)
* v5 (1, 0, 1)
* v6 (1, 1, 0)
* v7 (1, 1, 1)
*
*/
ccl_device_noinline float perlin_3d(float x, float y, float z)
ccl_device_noinline float perlin(float x, float y, float z)
{
ssef xyz = ssef(x, y, z, 0.0f);
ssei XYZ;
ssef fxyz = floorfrac(ssef(x, y, z, 0.0f), &XYZ);
ssef uvw = fade(fxyz);
ssei XYZ1 = XYZ + 1;
ssei Y = shuffle<1, 1, 1, 1>(XYZ, XYZ1);
ssei Z = shuffle<0, 2, 0, 2>(shuffle<2, 2, 2, 2>(XYZ, XYZ1));
ssef fxyz = floorfrac_sse(xyz, &XYZ);
ssei h1 = hash_ssei3(shuffle<0>(XYZ), Y, Z);
ssei h2 = hash_ssei3(shuffle<0>(XYZ1), Y, Z);
ssef uvw = fade_sse(&fxyz);
ssef u = shuffle<0>(uvw), v = shuffle<1>(uvw), w = shuffle<2>(uvw);
ssef fxyz1 = fxyz - 1.0f;
ssef fy = shuffle<1, 1, 1, 1>(fxyz, fxyz1);
ssef fz = shuffle<0, 2, 0, 2>(shuffle<2, 2, 2, 2>(fxyz, fxyz1));
ssei XYZ_ofc = XYZ + ssei(1);
ssei vdy = shuffle<1, 1, 1, 1>(XYZ, XYZ_ofc); // +0, +0, +1, +1
ssei vdz = shuffle<0, 2, 0, 2>(shuffle<2, 2, 2, 2>(XYZ, XYZ_ofc)); // +0, +1, +0, +1
ssef g1 = grad(h1, shuffle<0>(fxyz), fy, fz);
ssef g2 = grad(h2, shuffle<0>(fxyz1), fy, fz);
ssei h1 = hash_sse(shuffle<0>(XYZ), vdy, vdz); // hash directions 000, 001, 010, 011
ssei h2 = hash_sse(shuffle<0>(XYZ_ofc), vdy, vdz); // hash directions 100, 101, 110, 111
return extract<0>(tri_mix(g1, g2, uvw));
}
ssef fxyz_ofc = fxyz - ssef(1.0f);
ssef vfy = shuffle<1, 1, 1, 1>(fxyz, fxyz_ofc);
ssef vfz = shuffle<0, 2, 0, 2>(shuffle<2, 2, 2, 2>(fxyz, fxyz_ofc));
/* We use SSE to compute and interpolate 4 gradients at once. Since we have 16
* gradients in 4D, we need to compute four sets of gradients at the points:
*
* Point Offset from v0
* v0 (0, 0, 0, 0)
* v1 (0, 0, 1, 0)
* v2 (0, 1, 0, 0) (0, 1, 0, 1) = shuffle<0, 2, 0, 2>(shuffle<2, 2, 2, 2>(V, V + 1))
* v3 (0, 1, 1, 0) ^
* | |________| (0, 0, 1, 1) = shuffle<1, 1, 1, 1>(V, V + 1)
* | ^
* |_______________________|
*
* Point Offset from v0
* v4 (1, 0, 0, 0)
* v5 (1, 0, 1, 0)
* v6 (1, 1, 0, 0)
* v7 (1, 1, 1, 0)
*
* Point Offset from v0
* v8 (0, 0, 0, 1)
* v9 (0, 0, 1, 1)
* v10 (0, 1, 0, 1)
* v11 (0, 1, 1, 1)
*
* Point Offset from v0
* v12 (1, 0, 0, 1)
* v13 (1, 0, 1, 1)
* v14 (1, 1, 0, 1)
* v15 (1, 1, 1, 1)
*
*/
ccl_device_noinline float perlin_4d(float x, float y, float z, float w)
{
ssei XYZW;
ssef fxyzw = floorfrac(ssef(x, y, z, w), &XYZW);
ssef uvws = fade(fxyzw);
ssef g1 = grad_sse(h1, shuffle<0>(fxyz), vfy, vfz);
ssef g2 = grad_sse(h2, shuffle<0>(fxyz_ofc), vfy, vfz);
ssef n1 = nerp_sse(u, g1, g2);
ssei XYZW1 = XYZW + 1;
ssei Y = shuffle<1, 1, 1, 1>(XYZW, XYZW1);
ssei Z = shuffle<0, 2, 0, 2>(shuffle<2, 2, 2, 2>(XYZW, XYZW1));
ssef n1_half = shuffle<2, 3, 2, 3>(n1); // extract 2 floats to a separate vector
ssef n2 = nerp_sse(
v, n1, n1_half); // process nerp([a, b, _, _], [c, d, _, _]) -> [a', b', _, _]
ssei h1 = hash_ssei4(shuffle<0>(XYZW), Y, Z, shuffle<3>(XYZW));
ssei h2 = hash_ssei4(shuffle<0>(XYZW1), Y, Z, shuffle<3>(XYZW));
ssef n2_second = shuffle<1>(n2); // extract b to a separate vector
ssef result = nerp_sse(
w, n2, n2_second); // process nerp([a', _, _, _], [b', _, _, _]) -> [a'', _, _, _]
ssei h3 = hash_ssei4(shuffle<0>(XYZW), Y, Z, shuffle<3>(XYZW1));
ssei h4 = hash_ssei4(shuffle<0>(XYZW1), Y, Z, shuffle<3>(XYZW1));
ssef r = scale3_sse(result);
ssef fxyzw1 = fxyzw - 1.0f;
ssef fy = shuffle<1, 1, 1, 1>(fxyzw, fxyzw1);
ssef fz = shuffle<0, 2, 0, 2>(shuffle<2, 2, 2, 2>(fxyzw, fxyzw1));
ssef g1 = grad(h1, shuffle<0>(fxyzw), fy, fz, shuffle<3>(fxyzw));
ssef g2 = grad(h2, shuffle<0>(fxyzw1), fy, fz, shuffle<3>(fxyzw));
ssef g3 = grad(h3, shuffle<0>(fxyzw), fy, fz, shuffle<3>(fxyzw1));
ssef g4 = grad(h4, shuffle<0>(fxyzw1), fy, fz, shuffle<3>(fxyzw1));
return extract<0>(quad_mix(g1, g2, g3, g4, uvws));
ssef infmask = cast(ssei(0x7f800000));
ssef rinfmask = ((r & infmask) == infmask).m128; // 0xffffffff if r is inf/-inf/nan else 0
ssef rfinite = andnot(rinfmask, r); // 0 if r is inf/-inf/nan else r
return extract<0>(rfinite);
}
#endif
/* Remap the output of noise to a predictable range [-1, 1].
* The scale values were computed experimentally by the OSL developers.
*/
ccl_device_inline float noise_scale1(float result)
/* perlin noise in range 0..1 */
ccl_device float noise(float3 p)
{
return 0.2500f * result;
float r = perlin(p.x, p.y, p.z);
return 0.5f * r + 0.5f;
}
ccl_device_inline float noise_scale2(float result)
/* perlin noise in range -1..1 */
ccl_device float snoise(float3 p)
{
return 0.6616f * result;
}
ccl_device_inline float noise_scale3(float result)
{
return 0.9820f * result;
}
ccl_device_inline float noise_scale4(float result)
{
return 0.8344f * result;
}
/* Safe Signed And Unsigned Noise */
ccl_device_inline float snoise_1d(float p)
{
return noise_scale1(ensure_finite(perlin_1d(p)));
}
ccl_device_inline float noise_1d(float p)
{
return 0.5f * snoise_1d(p) + 0.5f;
}
ccl_device_inline float snoise_2d(float2 p)
{
return noise_scale2(ensure_finite(perlin_2d(p.x, p.y)));
}
ccl_device_inline float noise_2d(float2 p)
{
return 0.5f * snoise_2d(p) + 0.5f;
}
ccl_device_inline float snoise_3d(float3 p)
{
return noise_scale3(ensure_finite(perlin_3d(p.x, p.y, p.z)));
}
ccl_device_inline float noise_3d(float3 p)
{
return 0.5f * snoise_3d(p) + 0.5f;
}
ccl_device_inline float snoise_4d(float4 p)
{
return noise_scale4(ensure_finite(perlin_4d(p.x, p.y, p.z, p.w)));
}
ccl_device_inline float noise_4d(float4 p)
{
return 0.5f * snoise_4d(p) + 0.5f;
return perlin(p.x, p.y, p.z);
}
/* cell noise */
@@ -609,7 +293,7 @@ ccl_device float3 cellnoise3(float3 p)
ssei ip_yxz = shuffle<1, 0, 2, 3>(ssei(ip.m128));
ssei ip_xyy = shuffle<0, 1, 1, 3>(ssei(ip.m128));
ssei ip_zzx = shuffle<2, 2, 0, 3>(ssei(ip.m128));
ssei bits = hash_ssei3(ip_xyy, ip_yxz, ip_zzx);
ssei bits = hash_sse(ip_xyy, ip_yxz, ip_zzx);
return float3(uint32_to_float(bits) * ssef(1.0f / (float)0xFFFFFFFF));
#endif
}

View File

@@ -16,172 +16,44 @@
CCL_NAMESPACE_BEGIN
/* The following offset functions generate random offsets to be added to texture
* coordinates to act as a seed since the noise functions don't have seed values.
* A seed value is needed for generating distortion textures and color outputs.
* The offset's components are in the range [100, 200], not too high to cause
* bad precision and not to small to be noticeable. We use float seed because
* OSL only support float hashes.
*/
/* Noise */
ccl_device_inline float random_float_offset(float seed)
ccl_device void svm_node_tex_noise(
KernelGlobals *kg, ShaderData *sd, float *stack, uint4 node, int *offset)
{
return 100.0f + hash_float_to_float(seed) * 100.0f;
}
uint co_offset, scale_offset, detail_offset, distortion_offset, fac_offset, color_offset;
ccl_device_inline float2 random_float2_offset(float seed)
{
return make_float2(100.0f + hash_float2_to_float(make_float2(seed, 0.0f)) * 100.0f,
100.0f + hash_float2_to_float(make_float2(seed, 1.0f)) * 100.0f);
}
svm_unpack_node_uchar4(node.y, &co_offset, &scale_offset, &detail_offset, &distortion_offset);
svm_unpack_node_uchar2(node.z, &color_offset, &fac_offset);
ccl_device_inline float3 random_float3_offset(float seed)
{
return make_float3(100.0f + hash_float2_to_float(make_float2(seed, 0.0f)) * 100.0f,
100.0f + hash_float2_to_float(make_float2(seed, 1.0f)) * 100.0f,
100.0f + hash_float2_to_float(make_float2(seed, 2.0f)) * 100.0f);
}
uint4 node2 = read_node(kg, offset);
ccl_device_inline float4 random_float4_offset(float seed)
{
return make_float4(100.0f + hash_float2_to_float(make_float2(seed, 0.0f)) * 100.0f,
100.0f + hash_float2_to_float(make_float2(seed, 1.0f)) * 100.0f,
100.0f + hash_float2_to_float(make_float2(seed, 2.0f)) * 100.0f,
100.0f + hash_float2_to_float(make_float2(seed, 3.0f)) * 100.0f);
}
float scale = stack_load_float_default(stack, scale_offset, node2.x);
float detail = stack_load_float_default(stack, detail_offset, node2.y);
float distortion = stack_load_float_default(stack, distortion_offset, node2.z);
float3 p = stack_load_float3(stack, co_offset) * scale;
int hard = 0;
ccl_device void noise_texture_1d(
float co, float detail, float distortion, bool color_is_needed, float *value, float3 *color)
{
float p = co;
if (distortion != 0.0f) {
p += noise_1d(p + random_float_offset(0.0f)) * distortion;
float3 r, offset = make_float3(13.5f, 13.5f, 13.5f);
r.x = noise(p + offset) * distortion;
r.y = noise(p) * distortion;
r.z = noise(p - offset) * distortion;
p += r;
}
*value = fractal_noise_1d(p, detail);
if (color_is_needed) {
*color = make_float3(*value,
fractal_noise_1d(p + random_float_offset(1.0f), detail),
fractal_noise_1d(p + random_float_offset(2.0f), detail));
float f = noise_turbulence(p, detail, hard);
if (stack_valid(fac_offset)) {
stack_store_float(stack, fac_offset, f);
}
}
ccl_device void noise_texture_2d(
float2 co, float detail, float distortion, bool color_is_needed, float *value, float3 *color)
{
float2 p = co;
if (distortion != 0.0f) {
p += make_float2(noise_2d(p + random_float2_offset(0.0f)) * distortion,
noise_2d(p + random_float2_offset(1.0f)) * distortion);
}
*value = fractal_noise_2d(p, detail);
if (color_is_needed) {
*color = make_float3(*value,
fractal_noise_2d(p + random_float2_offset(2.0f), detail),
fractal_noise_2d(p + random_float2_offset(3.0f), detail));
}
}
ccl_device void noise_texture_3d(
float3 co, float detail, float distortion, bool color_is_needed, float *value, float3 *color)
{
float3 p = co;
if (distortion != 0.0f) {
p += make_float3(noise_3d(p + random_float3_offset(0.0f)) * distortion,
noise_3d(p + random_float3_offset(1.0f)) * distortion,
noise_3d(p + random_float3_offset(2.0f)) * distortion);
}
*value = fractal_noise_3d(p, detail);
if (color_is_needed) {
*color = make_float3(*value,
fractal_noise_3d(p + random_float3_offset(3.0f), detail),
fractal_noise_3d(p + random_float3_offset(4.0f), detail));
}
}
ccl_device void noise_texture_4d(
float4 co, float detail, float distortion, bool color_is_needed, float *value, float3 *color)
{
float4 p = co;
if (distortion != 0.0f) {
p += make_float4(noise_4d(p + random_float4_offset(0.0f)) * distortion,
noise_4d(p + random_float4_offset(1.0f)) * distortion,
noise_4d(p + random_float4_offset(2.0f)) * distortion,
noise_4d(p + random_float4_offset(3.0f)) * distortion);
}
*value = fractal_noise_4d(p, detail);
if (color_is_needed) {
*color = make_float3(*value,
fractal_noise_4d(p + random_float4_offset(4.0f), detail),
fractal_noise_4d(p + random_float4_offset(5.0f), detail));
}
}
ccl_device void svm_node_tex_noise(KernelGlobals *kg,
ShaderData *sd,
float *stack,
uint dimensions,
uint offsets1,
uint offsets2,
int *offset)
{
uint vector_stack_offset, w_stack_offset, scale_stack_offset, detail_stack_offset;
uint distortion_stack_offset, value_stack_offset, color_stack_offset;
svm_unpack_node_uchar4(
offsets1, &vector_stack_offset, &w_stack_offset, &scale_stack_offset, &detail_stack_offset);
svm_unpack_node_uchar3(
offsets2, &distortion_stack_offset, &value_stack_offset, &color_stack_offset);
uint4 defaults = read_node(kg, offset);
float3 vector = stack_load_float3(stack, vector_stack_offset);
float w = stack_load_float_default(stack, w_stack_offset, defaults.x);
float scale = stack_load_float_default(stack, scale_stack_offset, defaults.y);
float detail = stack_load_float_default(stack, detail_stack_offset, defaults.z);
float distortion = stack_load_float_default(stack, distortion_stack_offset, defaults.w);
vector *= scale;
w *= scale;
float value;
float3 color;
switch (dimensions) {
case 1:
noise_texture_1d(w, detail, distortion, stack_valid(color_stack_offset), &value, &color);
break;
case 2:
noise_texture_2d(make_float2(vector.x, vector.y),
detail,
distortion,
stack_valid(color_stack_offset),
&value,
&color);
break;
case 3:
noise_texture_3d(
vector, detail, distortion, stack_valid(color_stack_offset), &value, &color);
break;
case 4:
noise_texture_4d(make_float4(vector.x, vector.y, vector.z, w),
detail,
distortion,
stack_valid(color_stack_offset),
&value,
&color);
break;
default:
kernel_assert(0);
}
if (stack_valid(value_stack_offset)) {
stack_store_float(stack, value_stack_offset, value);
}
if (stack_valid(color_stack_offset)) {
stack_store_float3(stack, color_stack_offset, color);
if (stack_valid(color_offset)) {
float3 color = make_float3(f,
noise_turbulence(make_float3(p.y, p.x, p.z), detail, hard),
noise_turbulence(make_float3(p.y, p.z, p.x), detail, hard));
stack_store_float3(stack, color_offset, color);
}
}

View File

@@ -0,0 +1,63 @@
/*
* Copyright 2011-2013 Blender Foundation
*
* 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* 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.
*/
CCL_NAMESPACE_BEGIN
/* Turbulence */
ccl_device_noinline float noise_turbulence(float3 p, float octaves, int hard)
{
float fscale = 1.0f;
float amp = 1.0f;
float sum = 0.0f;
int i, n;
octaves = clamp(octaves, 0.0f, 16.0f);
n = float_to_int(octaves);
for (i = 0; i <= n; i++) {
float t = noise(fscale * p);
if (hard)
t = fabsf(2.0f * t - 1.0f);
sum += t * amp;
amp *= 0.5f;
fscale *= 2.0f;
}
float rmd = octaves - floorf(octaves);
if (rmd != 0.0f) {
float t = noise(fscale * p);
if (hard)
t = fabsf(2.0f * t - 1.0f);
float sum2 = sum + t * amp;
sum *= ((float)(1 << n) / (float)((1 << (n + 1)) - 1));
sum2 *= ((float)(1 << (n + 1)) / (float)((1 << (n + 2)) - 1));
return (1.0f - rmd) * sum + rmd * sum2;
}
else {
sum *= ((float)(1 << n) / (float)((1 << (n + 1)) - 1));
return sum;
}
}
CCL_NAMESPACE_END

View File

@@ -140,7 +140,6 @@ typedef enum ShaderNodeType {
NODE_IES,
NODE_MAP_RANGE,
NODE_CLAMP,
NODE_TEXTURE_MAPPING,
NODE_TEX_WHITE_NOISE,
} ShaderNodeType;
@@ -300,13 +299,6 @@ typedef enum NodeVectorMathType {
NODE_VECTOR_MATH_MAXIMUM,
} NodeVectorMathType;
typedef enum NodeMappingType {
NODE_MAPPING_TYPE_POINT,
NODE_MAPPING_TYPE_TEXTURE,
NODE_MAPPING_TYPE_VECTOR,
NODE_MAPPING_TYPE_NORMAL
} NodeMappingType;
typedef enum NodeVectorTransformType {
NODE_VECTOR_TRANSFORM_TYPE_VECTOR,
NODE_VECTOR_TRANSFORM_TYPE_POINT,

View File

@@ -33,7 +33,7 @@ ccl_device_noinline_cpu float svm_wave(NodeWaveType type,
n = len(p) * 20.0f;
if (distortion != 0.0f)
n += distortion * fractal_noise_3d(p * dscale, detail);
n += distortion * noise_turbulence(p * dscale, detail, 0);
if (profile == NODE_WAVE_PROFILE_SIN) {
return 0.5f + 0.5f * sinf(n);

View File

@@ -64,6 +64,7 @@ class BufferParams {
void get_offset_stride(int &offset, int &stride);
bool modified(const BufferParams &params);
void add_pass(PassType type);
int get_passes_size();
int get_denoising_offset();
int get_denoising_prefiltered_offset();

View File

@@ -429,21 +429,4 @@ void ConstantFolder::fold_vector_math(NodeVectorMathType type) const
}
}
void ConstantFolder::fold_mapping(NodeMappingType type) const
{
ShaderInput *vector_in = node->input("Vector");
ShaderInput *location_in = node->input("Location");
ShaderInput *rotation_in = node->input("Rotation");
ShaderInput *scale_in = node->input("Scale");
if (is_zero(scale_in)) {
make_zero();
}
else if ((is_zero(location_in) || type == NODE_MAPPING_TYPE_VECTOR ||
type == NODE_MAPPING_TYPE_NORMAL) &&
is_zero(rotation_in) && is_one(scale_in)) {
try_bypass_or_make_constant(vector_in);
}
}
CCL_NAMESPACE_END

View File

@@ -66,7 +66,6 @@ class ConstantFolder {
void fold_mix(NodeMix type, bool clamp) const;
void fold_math(NodeMathType type) const;
void fold_vector_math(NodeVectorMathType type) const;
void fold_mapping(NodeMappingType type) const;
};
CCL_NAMESPACE_END

View File

@@ -267,7 +267,7 @@ NODE_DEFINE(Film)
NodeType *type = NodeType::add("film", create);
SOCKET_FLOAT(exposure, "Exposure", 0.8f);
SOCKET_FLOAT(pass_alpha_threshold, "Pass Alpha Threshold", 0.0f);
SOCKET_FLOAT(pass_alpha_threshold, "Pass Alpha Threshold", 0.5f);
static NodeEnum filter_enum;
filter_enum.insert("box", FILTER_BOX);
@@ -318,13 +318,6 @@ void Film::device_update(Device *device, DeviceScene *dscene, Scene *scene)
/* update __data */
kfilm->exposure = exposure;
kfilm->pass_flag = 0;
kfilm->display_pass_stride = -1;
kfilm->display_pass_components = 0;
kfilm->display_divide_pass_stride = -1;
kfilm->use_display_exposure = false;
kfilm->use_display_pass_alpha = (display_pass == PASS_COMBINED);
kfilm->light_pass_flag = 0;
kfilm->pass_stride = 0;
kfilm->use_light_pass = use_light_visibility || use_sample_clamp;
@@ -471,16 +464,6 @@ void Film::device_update(Device *device, DeviceScene *dscene, Scene *scene)
break;
}
if (pass.type == display_pass) {
kfilm->display_pass_stride = kfilm->pass_stride;
kfilm->display_pass_components = pass.components;
kfilm->use_display_exposure = pass.exposure && (kfilm->exposure != 1.0f);
}
else if (pass.type == PASS_DIFFUSE_COLOR || pass.type == PASS_TRANSMISSION_COLOR ||
pass.type == PASS_GLOSSY_COLOR || pass.type == PASS_SUBSURFACE_COLOR) {
kfilm->display_divide_pass_stride = kfilm->pass_stride;
}
kfilm->pass_stride += pass.components;
}
@@ -502,18 +485,7 @@ void Film::device_update(Device *device, DeviceScene *dscene, Scene *scene)
}
kfilm->pass_stride = align_up(kfilm->pass_stride, 4);
/* When displaying the normal/uv pass in the viewport we need to disable
* transparency.
*
* We also don't need to perform light accumulations. Later we want to optimize this to suppress
* light calculations. */
if (display_pass == PASS_NORMAL || display_pass == PASS_UV) {
kfilm->use_light_pass = 0;
}
else {
kfilm->pass_alpha_threshold = pass_alpha_threshold;
}
kfilm->pass_alpha_threshold = pass_alpha_threshold;
/* update filter table */
vector<float> table = filter_table(filter_type, filter_width);
@@ -546,7 +518,7 @@ bool Film::modified(const Film &film)
return !Node::equals(film) || !Pass::equals(passes, film.passes);
}
void Film::tag_passes_update(Scene *scene, const vector<Pass> &passes_, bool update_passes)
void Film::tag_passes_update(Scene *scene, const vector<Pass> &passes_)
{
if (Pass::contains(passes, PASS_UV) != Pass::contains(passes_, PASS_UV)) {
scene->mesh_manager->tag_update(scene);
@@ -554,16 +526,10 @@ void Film::tag_passes_update(Scene *scene, const vector<Pass> &passes_, bool upd
foreach (Shader *shader, scene->shaders)
shader->need_update_mesh = true;
}
else if (Pass::contains(passes, PASS_MOTION) != Pass::contains(passes_, PASS_MOTION)) {
else if (Pass::contains(passes, PASS_MOTION) != Pass::contains(passes_, PASS_MOTION))
scene->mesh_manager->tag_update(scene);
}
else if (Pass::contains(passes, PASS_AO) != Pass::contains(passes_, PASS_AO)) {
scene->integrator->tag_update(scene);
}
if (update_passes) {
passes = passes_;
}
passes = passes_;
}
void Film::tag_update(Scene * /*scene*/)

View File

@@ -64,7 +64,6 @@ class Film : public Node {
int denoising_flags;
float pass_alpha_threshold;
PassType display_pass;
int pass_stride;
int denoising_data_offset;
int denoising_clean_offset;
@@ -91,7 +90,7 @@ class Film : public Node {
void device_free(Device *device, DeviceScene *dscene, Scene *scene);
bool modified(const Film &film);
void tag_passes_update(Scene *scene, const vector<Pass> &passes_, bool update_passes=true);
void tag_passes_update(Scene *scene, const vector<Pass> &passes_);
void tag_update(Scene *scene);
};

View File

@@ -25,7 +25,6 @@
#include "kernel/svm/svm_color_util.h"
#include "kernel/svm/svm_ramp_util.h"
#include "kernel/svm/svm_math_util.h"
#include "kernel/svm/svm_mapping_util.h"
#include "render/osl.h"
#include "render/constant_fold.h"
@@ -150,7 +149,7 @@ bool TextureMapping::skip()
void TextureMapping::compile(SVMCompiler &compiler, int offset_in, int offset_out)
{
compiler.add_node(NODE_TEXTURE_MAPPING, offset_in, offset_out);
compiler.add_node(NODE_MAPPING, offset_in, offset_out);
Transform tfm = compute_transform();
compiler.add_node(tfm.x);
@@ -894,22 +893,14 @@ NODE_DEFINE(NoiseTextureNode)
TEXTURE_MAPPING_DEFINE(NoiseTextureNode);
static NodeEnum dimensions_enum;
dimensions_enum.insert("1D", 1);
dimensions_enum.insert("2D", 2);
dimensions_enum.insert("3D", 3);
dimensions_enum.insert("4D", 4);
SOCKET_ENUM(dimensions, "Dimensions", dimensions_enum, 3);
SOCKET_IN_POINT(
vector, "Vector", make_float3(0.0f, 0.0f, 0.0f), SocketType::LINK_TEXTURE_GENERATED);
SOCKET_IN_FLOAT(w, "W", 0.0f);
SOCKET_IN_FLOAT(scale, "Scale", 1.0f);
SOCKET_IN_FLOAT(detail, "Detail", 2.0f);
SOCKET_IN_FLOAT(distortion, "Distortion", 0.0f);
SOCKET_IN_POINT(
vector, "Vector", make_float3(0.0f, 0.0f, 0.0f), SocketType::LINK_TEXTURE_GENERATED);
SOCKET_OUT_FLOAT(fac, "Fac");
SOCKET_OUT_COLOR(color, "Color");
SOCKET_OUT_FLOAT(fac, "Fac");
return type;
}
@@ -920,40 +911,31 @@ NoiseTextureNode::NoiseTextureNode() : TextureNode(node_type)
void NoiseTextureNode::compile(SVMCompiler &compiler)
{
ShaderInput *vector_in = input("Vector");
ShaderInput *w_in = input("W");
ShaderInput *scale_in = input("Scale");
ShaderInput *detail_in = input("Detail");
ShaderInput *distortion_in = input("Distortion");
ShaderOutput *fac_out = output("Fac");
ShaderInput *detail_in = input("Detail");
ShaderInput *scale_in = input("Scale");
ShaderInput *vector_in = input("Vector");
ShaderOutput *color_out = output("Color");
ShaderOutput *fac_out = output("Fac");
int vector_stack_offset = tex_mapping.compile_begin(compiler, vector_in);
int w_stack_offset = compiler.stack_assign_if_linked(w_in);
int scale_stack_offset = compiler.stack_assign_if_linked(scale_in);
int detail_stack_offset = compiler.stack_assign_if_linked(detail_in);
int distortion_stack_offset = compiler.stack_assign_if_linked(distortion_in);
int fac_stack_offset = compiler.stack_assign_if_linked(fac_out);
int color_stack_offset = compiler.stack_assign_if_linked(color_out);
int vector_offset = tex_mapping.compile_begin(compiler, vector_in);
compiler.add_node(
NODE_TEX_NOISE,
dimensions,
compiler.encode_uchar4(
vector_stack_offset, w_stack_offset, scale_stack_offset, detail_stack_offset),
compiler.encode_uchar4(distortion_stack_offset, fac_stack_offset, color_stack_offset));
compiler.add_node(__float_as_int(w),
__float_as_int(scale),
__float_as_int(detail),
__float_as_int(distortion));
compiler.add_node(NODE_TEX_NOISE,
compiler.encode_uchar4(vector_offset,
compiler.stack_assign_if_linked(scale_in),
compiler.stack_assign_if_linked(detail_in),
compiler.stack_assign_if_linked(distortion_in)),
compiler.encode_uchar4(compiler.stack_assign_if_linked(color_out),
compiler.stack_assign_if_linked(fac_out)));
compiler.add_node(__float_as_int(scale), __float_as_int(detail), __float_as_int(distortion));
tex_mapping.compile_end(compiler, vector_in, vector_stack_offset);
tex_mapping.compile_end(compiler, vector_in, vector_offset);
}
void NoiseTextureNode::compile(OSLCompiler &compiler)
{
tex_mapping.compile(compiler);
compiler.parameter(this, "dimensions");
compiler.add(this, "node_noise_texture");
}
@@ -1183,13 +1165,6 @@ NODE_DEFINE(MusgraveTextureNode)
TEXTURE_MAPPING_DEFINE(MusgraveTextureNode);
static NodeEnum dimensions_enum;
dimensions_enum.insert("1D", 1);
dimensions_enum.insert("2D", 2);
dimensions_enum.insert("3D", 3);
dimensions_enum.insert("4D", 4);
SOCKET_ENUM(dimensions, "Dimensions", dimensions_enum, 3);
static NodeEnum type_enum;
type_enum.insert("multifractal", NODE_MUSGRAVE_MULTIFRACTAL);
type_enum.insert("fBM", NODE_MUSGRAVE_FBM);
@@ -1198,16 +1173,16 @@ NODE_DEFINE(MusgraveTextureNode)
type_enum.insert("hetero_terrain", NODE_MUSGRAVE_HETERO_TERRAIN);
SOCKET_ENUM(type, "Type", type_enum, NODE_MUSGRAVE_FBM);
SOCKET_IN_POINT(
vector, "Vector", make_float3(0.0f, 0.0f, 0.0f), SocketType::LINK_TEXTURE_GENERATED);
SOCKET_IN_FLOAT(w, "W", 0.0f);
SOCKET_IN_FLOAT(scale, "Scale", 1.0f);
SOCKET_IN_FLOAT(detail, "Detail", 2.0f);
SOCKET_IN_FLOAT(dimension, "Dimension", 2.0f);
SOCKET_IN_FLOAT(lacunarity, "Lacunarity", 1.0f);
SOCKET_IN_FLOAT(offset, "Offset", 0.0f);
SOCKET_IN_FLOAT(gain, "Gain", 1.0f);
SOCKET_IN_POINT(
vector, "Vector", make_float3(0.0f, 0.0f, 0.0f), SocketType::LINK_TEXTURE_GENERATED);
SOCKET_OUT_COLOR(color, "Color");
SOCKET_OUT_FLOAT(fac, "Fac");
return type;
@@ -1220,38 +1195,35 @@ MusgraveTextureNode::MusgraveTextureNode() : TextureNode(node_type)
void MusgraveTextureNode::compile(SVMCompiler &compiler)
{
ShaderInput *vector_in = input("Vector");
ShaderInput *w_in = input("W");
ShaderInput *scale_in = input("Scale");
ShaderInput *detail_in = input("Detail");
ShaderInput *dimension_in = input("Dimension");
ShaderInput *lacunarity_in = input("Lacunarity");
ShaderInput *detail_in = input("Detail");
ShaderInput *offset_in = input("Offset");
ShaderInput *gain_in = input("Gain");
ShaderOutput *fac_out = output("Fac");
ShaderOutput *color_out = output("Color");
int vector_stack_offset = tex_mapping.compile_begin(compiler, vector_in);
int w_stack_offset = compiler.stack_assign_if_linked(w_in);
int scale_stack_offset = compiler.stack_assign_if_linked(scale_in);
int detail_stack_offset = compiler.stack_assign_if_linked(detail_in);
int dimension_stack_offset = compiler.stack_assign_if_linked(dimension_in);
int lacunarity_stack_offset = compiler.stack_assign_if_linked(lacunarity_in);
int offset_stack_offset = compiler.stack_assign_if_linked(offset_in);
int gain_stack_offset = compiler.stack_assign_if_linked(gain_in);
int fac_stack_offset = compiler.stack_assign(fac_out);
int vector_offset = tex_mapping.compile_begin(compiler, vector_in);
compiler.add_node(
NODE_TEX_MUSGRAVE,
compiler.encode_uchar4(type, dimensions, vector_stack_offset, w_stack_offset),
compiler.encode_uchar4(scale_stack_offset,
detail_stack_offset,
dimension_stack_offset,
lacunarity_stack_offset),
compiler.encode_uchar4(offset_stack_offset, gain_stack_offset, fac_stack_offset));
compiler.add_node(
__float_as_int(w), __float_as_int(scale), __float_as_int(detail), __float_as_int(dimension));
compiler.add_node(__float_as_int(lacunarity), __float_as_int(offset), __float_as_int(gain));
compiler.add_node(NODE_TEX_MUSGRAVE,
compiler.encode_uchar4(type,
vector_offset,
compiler.stack_assign_if_linked(color_out),
compiler.stack_assign_if_linked(fac_out)),
compiler.encode_uchar4(compiler.stack_assign_if_linked(dimension_in),
compiler.stack_assign_if_linked(lacunarity_in),
compiler.stack_assign_if_linked(detail_in),
compiler.stack_assign_if_linked(offset_in)),
compiler.encode_uchar4(compiler.stack_assign_if_linked(gain_in),
compiler.stack_assign_if_linked(scale_in)));
compiler.add_node(__float_as_int(dimension),
__float_as_int(lacunarity),
__float_as_int(detail),
__float_as_int(offset));
compiler.add_node(__float_as_int(gain), __float_as_int(scale));
tex_mapping.compile_end(compiler, vector_in, vector_stack_offset);
tex_mapping.compile_end(compiler, vector_in, vector_offset);
}
void MusgraveTextureNode::compile(OSLCompiler &compiler)
@@ -1259,7 +1231,6 @@ void MusgraveTextureNode::compile(OSLCompiler &compiler)
tex_mapping.compile(compiler);
compiler.parameter(this, "type");
compiler.parameter(this, "dimensions");
compiler.add(this, "node_musgrave_texture");
}
@@ -1739,18 +1710,9 @@ NODE_DEFINE(MappingNode)
{
NodeType *type = NodeType::add("mapping", create, NodeType::SHADER);
static NodeEnum type_enum;
type_enum.insert("point", NODE_MAPPING_TYPE_POINT);
type_enum.insert("texture", NODE_MAPPING_TYPE_TEXTURE);
type_enum.insert("vector", NODE_MAPPING_TYPE_VECTOR);
type_enum.insert("normal", NODE_MAPPING_TYPE_NORMAL);
SOCKET_ENUM(type, "Type", type_enum, NODE_MAPPING_TYPE_POINT);
TEXTURE_MAPPING_DEFINE(MappingNode);
SOCKET_IN_POINT(vector, "Vector", make_float3(0.0f, 0.0f, 0.0f));
SOCKET_IN_POINT(location, "Location", make_float3(0.0f, 0.0f, 0.0f));
SOCKET_IN_POINT(rotation, "Rotation", make_float3(0.0f, 0.0f, 0.0f));
SOCKET_IN_POINT(scale, "Scale", make_float3(1.0f, 1.0f, 1.0f));
SOCKET_OUT_POINT(vector, "Vector");
return type;
@@ -1760,42 +1722,22 @@ MappingNode::MappingNode() : ShaderNode(node_type)
{
}
void MappingNode::constant_fold(const ConstantFolder &folder)
{
if (folder.all_inputs_constant()) {
float3 result = svm_mapping((NodeMappingType)type, vector, location, rotation, scale);
folder.make_constant(result);
}
else {
folder.fold_mapping((NodeMappingType)type);
}
}
void MappingNode::compile(SVMCompiler &compiler)
{
ShaderInput *vector_in = input("Vector");
ShaderInput *location_in = input("Location");
ShaderInput *rotation_in = input("Rotation");
ShaderInput *scale_in = input("Scale");
ShaderOutput *vector_out = output("Vector");
int vector_stack_offset = compiler.stack_assign(vector_in);
int location_stack_offset = compiler.stack_assign(location_in);
int rotation_stack_offset = compiler.stack_assign(rotation_in);
int scale_stack_offset = compiler.stack_assign(scale_in);
int result_stack_offset = compiler.stack_assign(vector_out);
compiler.add_node(
NODE_MAPPING,
type,
compiler.encode_uchar4(
vector_stack_offset, location_stack_offset, rotation_stack_offset, scale_stack_offset),
result_stack_offset);
tex_mapping.compile(
compiler, compiler.stack_assign(vector_in), compiler.stack_assign(vector_out));
}
void MappingNode::compile(OSLCompiler &compiler)
{
compiler.parameter(this, "type");
compiler.parameter("Matrix", tex_mapping.compute_transform());
compiler.parameter_point("mapping_min", tex_mapping.min);
compiler.parameter_point("mapping_max", tex_mapping.max);
compiler.parameter("use_minmax", tex_mapping.use_minmax);
compiler.add(this, "node_mapping");
}

View File

@@ -206,8 +206,7 @@ class NoiseTextureNode : public TextureNode {
public:
SHADER_NODE_CLASS(NoiseTextureNode)
int dimensions;
float w, scale, detail, distortion;
float scale, detail, distortion;
float3 vector;
};
@@ -236,9 +235,8 @@ class MusgraveTextureNode : public TextureNode {
return NODE_GROUP_LEVEL_2;
}
int dimensions;
NodeMusgraveType type;
float w, scale, detail, dimension, lacunarity, offset, gain;
float scale, detail, dimension, lacunarity, offset, gain;
float3 vector;
};
@@ -392,10 +390,9 @@ class MappingNode : public ShaderNode {
{
return NODE_GROUP_LEVEL_2;
}
void constant_fold(const ConstantFolder &folder);
float3 vector, location, rotation, scale;
NodeMappingType type;
float3 vector;
TextureMapping tex_mapping;
};
class RGBToBWNode : public ShaderNode {

View File

@@ -83,7 +83,7 @@ Session::Session(const SessionParams &params_)
display_outdated = false;
gpu_draw_ready = false;
gpu_need_display_buffer_update = false;
gpu_need_tonemap = false;
pause = false;
kernels_loaded = false;
@@ -97,8 +97,8 @@ Session::~Session()
/* wait for session thread to end */
progress.set_cancel("Exiting");
gpu_need_display_buffer_update = false;
gpu_need_display_buffer_update_cond.notify_all();
gpu_need_tonemap = false;
gpu_need_tonemap_cond.notify_all();
{
thread_scoped_lock pause_lock(pause_mutex);
@@ -110,12 +110,12 @@ Session::~Session()
}
if (params.write_render_cb) {
/* Copy to display buffer and write out image if requested */
/* tonemap and write out image if requested */
delete display;
display = new DisplayBuffer(device, false);
display->reset(buffers->params);
copy_to_display_buffer(params.samples);
tonemap(params.samples);
int w = display->draw_width;
int h = display->draw_height;
@@ -168,8 +168,8 @@ void Session::reset_gpu(BufferParams &buffer_params, int samples)
reset_(buffer_params, samples);
gpu_need_display_buffer_update = false;
gpu_need_display_buffer_update_cond.notify_all();
gpu_need_tonemap = false;
gpu_need_tonemap_cond.notify_all();
pause_cond.notify_all();
}
@@ -186,11 +186,11 @@ bool Session::draw_gpu(BufferParams &buffer_params, DeviceDrawParams &draw_param
if (!buffer_params.modified(display->params)) {
/* for CUDA we need to do tone-mapping still, since we can
* only access GL buffers from the main thread. */
if (gpu_need_display_buffer_update) {
if (gpu_need_tonemap) {
thread_scoped_lock buffers_lock(buffers_mutex);
copy_to_display_buffer(tile_manager.state.sample);
gpu_need_display_buffer_update = false;
gpu_need_display_buffer_update_cond.notify_all();
tonemap(tile_manager.state.sample);
gpu_need_tonemap = false;
gpu_need_tonemap_cond.notify_all();
}
display->draw(device, draw_params);
@@ -307,17 +307,17 @@ void Session::run_gpu()
/* update status and timing */
update_status_time();
gpu_need_display_buffer_update = true;
gpu_need_tonemap = true;
gpu_draw_ready = true;
progress.set_update();
/* wait for until display buffer is updated */
/* wait for tonemap */
if (!params.background) {
while (gpu_need_display_buffer_update) {
while (gpu_need_tonemap) {
if (progress.get_cancel())
break;
gpu_need_display_buffer_update_cond.wait(buffers_lock);
gpu_need_tonemap_cond.wait(buffers_lock);
}
}
@@ -561,7 +561,7 @@ void Session::run_cpu()
while (!progress.get_cancel()) {
/* advance to next tile */
bool no_tiles = !tile_manager.next();
bool need_copy_to_display_buffer = false;
bool need_tonemap = false;
DeviceKernelStatus kernel_state = DEVICE_KERNEL_UNKNOWN;
if (no_tiles) {
@@ -650,7 +650,7 @@ void Session::run_cpu()
update_status_time();
if (!params.background)
need_copy_to_display_buffer = true;
need_tonemap = true;
if (!device->error_message().empty())
progress.set_error(device->error_message());
@@ -668,10 +668,10 @@ void Session::run_cpu()
delayed_reset.do_reset = false;
reset_(delayed_reset.params, delayed_reset.samples);
}
else if (need_copy_to_display_buffer) {
/* Only copy to display_buffer if we do not reset, we don't
else if (need_tonemap) {
/* tonemap only if we do not reset, we don't we don't
* want to show the result of an incomplete sample */
copy_to_display_buffer(tile_manager.state.sample);
tonemap(tile_manager.state.sample);
}
if (!device->error_message().empty())
@@ -1044,9 +1044,9 @@ void Session::render()
device->task_add(task);
}
void Session::copy_to_display_buffer(int sample)
void Session::tonemap(int sample)
{
/* add film conversion task */
/* add tonemap task */
DeviceTask task(DeviceTask::FILM_CONVERT);
task.x = tile_manager.state.buffer.full_x;

View File

@@ -176,7 +176,7 @@ class Session {
void update_status_time(bool show_pause = false, bool show_done = false);
void copy_to_display_buffer(int sample);
void tonemap(int sample);
void render();
void reset_(BufferParams &params, int samples);
@@ -202,8 +202,8 @@ class Session {
volatile bool display_outdated;
volatile bool gpu_draw_ready;
volatile bool gpu_need_display_buffer_update;
thread_condition_variable gpu_need_display_buffer_update_cond;
volatile bool gpu_need_tonemap;
thread_condition_variable gpu_need_tonemap_cond;
bool pause;
thread_condition_variable pause_cond;

View File

@@ -213,109 +213,6 @@ ccl_device_inline float3 hash_float4_to_float3(float4 k)
hash_float4_to_float(make_float4(k.w, k.z, k.y, k.x)));
}
/* SSE Versions Of Jenkins Lookup3 Hash Functions */
#ifdef __KERNEL_SSE2__
# define rot(x, k) (((x) << (k)) | (srl(x, 32 - (k))))
# define mix(a, b, c) \
{ \
a -= c; \
a ^= rot(c, 4); \
c += b; \
b -= a; \
b ^= rot(a, 6); \
a += c; \
c -= b; \
c ^= rot(b, 8); \
b += a; \
a -= c; \
a ^= rot(c, 16); \
c += b; \
b -= a; \
b ^= rot(a, 19); \
a += c; \
c -= b; \
c ^= rot(b, 4); \
b += a; \
}
# define final(a, b, c) \
{ \
c ^= b; \
c -= rot(b, 14); \
a ^= c; \
a -= rot(c, 11); \
b ^= a; \
b -= rot(a, 25); \
c ^= b; \
c -= rot(b, 16); \
a ^= c; \
a -= rot(c, 4); \
b ^= a; \
b -= rot(a, 14); \
c ^= b; \
c -= rot(b, 24); \
}
ccl_device_inline ssei hash_ssei(ssei kx)
{
ssei a, b, c;
a = b = c = ssei(0xdeadbeef + (1 << 2) + 13);
a += kx;
final(a, b, c);
return c;
}
ccl_device_inline ssei hash_ssei2(ssei kx, ssei ky)
{
ssei a, b, c;
a = b = c = ssei(0xdeadbeef + (2 << 2) + 13);
b += ky;
a += kx;
final(a, b, c);
return c;
}
ccl_device_inline ssei hash_ssei3(ssei kx, ssei ky, ssei kz)
{
ssei a, b, c;
a = b = c = ssei(0xdeadbeef + (3 << 2) + 13);
c += kz;
b += ky;
a += kx;
final(a, b, c);
return c;
}
ccl_device_inline ssei hash_ssei4(ssei kx, ssei ky, ssei kz, ssei kw)
{
ssei a, b, c;
a = b = c = ssei(0xdeadbeef + (4 << 2) + 13);
a += kx;
b += ky;
c += kz;
mix(a, b, c);
a += kw;
final(a, b, c);
return c;
}
# undef rot
# undef final
# undef mix
#endif
#ifndef __KERNEL_GPU__
static inline uint hash_string(const char *str)
{

View File

@@ -318,12 +318,6 @@ ccl_device_inline int quick_floor_to_int(float x)
return float_to_int(x) - ((x < 0) ? 1 : 0);
}
ccl_device_inline float floorfrac(float x, int *i)
{
*i = quick_floor_to_int(x);
return x - *i;
}
ccl_device_inline int ceil_to_int(float f)
{
return float_to_int(ceilf(f));

View File

@@ -523,29 +523,13 @@ __forceinline ssei truncatei(const ssef &a)
return _mm_cvttps_epi32(a.m128);
}
/* This is about 25% faster than straightforward floor to integer conversion
* due to better pipelining.
*
* Unsaturated add 0xffffffff (a < 0) is the same as subtract -1.
*/
__forceinline ssei floori(const ssef &a)
{
return truncatei(a) + cast((a < 0.0f).m128);
}
__forceinline ssef floorfrac(const ssef &x, ssei *i)
{
*i = floori(x);
return x - ssef(*i);
}
////////////////////////////////////////////////////////////////////////////////
/// Common Functions
////////////////////////////////////////////////////////////////////////////////
__forceinline ssef mix(const ssef &a, const ssef &b, const ssef &t)
{
return madd(t, b, (ssef(1.0f) - t) * a);
# if defined(__KERNEL_SSE41__)
return ssei(floor(a));
# else
return ssei(a - ssef(0.5f));
# endif
}
////////////////////////////////////////////////////////////////////////////////

View File

@@ -310,15 +310,6 @@ __forceinline ssei &operator|=(ssei &a, const int32_t &b)
return a = a | b;
}
__forceinline ssei &operator^=(ssei &a, const ssei &b)
{
return a = a ^ b;
}
__forceinline ssei &operator^=(ssei &a, const int32_t &b)
{
return a = a ^ b;
}
__forceinline ssei &operator<<=(ssei &a, const int32_t &b)
{
return a = a << b;

View File

@@ -148,32 +148,6 @@ ccl_device_inline Transform make_transform(float a,
return t;
}
ccl_device_inline Transform euler_to_transform(const float3 euler)
{
float cx = cosf(euler.x);
float cy = cosf(euler.y);
float cz = cosf(euler.z);
float sx = sinf(euler.x);
float sy = sinf(euler.y);
float sz = sinf(euler.z);
Transform t;
t.x.x = cy * cz;
t.y.x = cy * sz;
t.z.x = -sy;
t.x.y = sy * sx * cz - cx * sz;
t.y.y = sy * sx * sz + cx * cz;
t.z.y = cy * sx;
t.x.z = sy * cx * cz + sx * sz;
t.y.z = sy * cx * sz - sx * cz;
t.z.z = cy * cx;
t.x.w = t.y.w = t.z.w = 0.0f;
return t;
}
/* Constructs a coordinate frame from a normalized normal. */
ccl_device_inline Transform make_transform_frame(float3 N)
{

View File

@@ -34,8 +34,8 @@
* The default destructor of this object has been made protected on purpose.
* This disables the creation of shared objects on the stack.
*
* \author Maarten Gribnau
* \date March 31, 2001
* @author Maarten Gribnau
* @date March 31, 2001
*/
class MEM_RefCounted {
@@ -49,20 +49,20 @@ class MEM_RefCounted {
/**
* Returns the reference count of this object.
* \return the reference count.
* @return the reference count.
*/
inline virtual int getRef() const;
/**
* Increases the reference count of this object.
* \return the new reference count.
* @return the new reference count.
*/
inline virtual int incRef();
/**
* Decreases the reference count of this object.
* If the reference count reaches zero, the object self-destructs.
* \return the new reference count.
* @return the new reference count.
*/
inline virtual int decRef();

View File

@@ -31,15 +31,15 @@ extern "C" {
/**
* Counts how many bytes is requered for for future utf-8 string using utf-16
* \param string16: pointer to working utf-16 string
* \return How many bytes must be allocated includeng NULL.
* @param string-16 pointer to working utf-16 string
* @return How many bytes must be allocated includeng NULL.
*/
size_t count_utf_8_from_16(const wchar_t *string16);
/**
* Counts how many wchar_t (two byte) is requered for for future utf-16 string using utf-8
* \param string8: pointer to working utf-8 string
* \return How many bytes must be allocated includeng NULL.
* @param string-8 pointer to working utf-8 string
* @return How many bytes must be allocated includeng NULL.
*/
size_t count_utf_16_from_8(const char *string8);
@@ -54,36 +54,36 @@ size_t count_utf_16_from_8(const char *string8);
/**
* Converts utf-16 string to allocated utf-8 string
* \param in16: utf-16 string to convert
* \param out8: utf-8 string to string the conversion
* \param size8: the allocated size in bytes of out8
* \return Returns any errors occured during conversion. See the block above,
* @param in16 utf-16 string to convert
* @param out8 utf-8 string to string the conversion
* @param size8 the allocated size in bytes of out8
* @return Returns any errors occured during conversion. See the block above,
*/
int conv_utf_16_to_8(const wchar_t *in16, char *out8, size_t size8);
/**
* Converts utf-8 string to allocated utf-16 string
* \param in8: utf-8 string to convert
* \param out16: utf-16 string to string the conversion
* \param size16: the allocated size in wchar_t (two byte) of out16
* \return Returns any errors occured during conversion. See the block above,
* @param in8 utf-8 string to convert
* @param out16 utf-16 string to string the conversion
* @param size16 the allocated size in wchar_t (two byte) of out16
* @return Returns any errors occured during conversion. See the block above,
*/
int conv_utf_8_to_16(const char *in8, wchar_t *out16, size_t size16);
/**
* Allocates and converts the utf-8 string from utf-16
* \param in16: utf-16 string to convert
* \param add: any additional size which will be allocated for new utf-8 string in bytes
* \return New allocated and converted utf-8 string or NULL if in16 is 0.
* @param in16 utf-16 string to convert
* @param add any additional size which will be allocated for new utf-8 string in bytes
* @return New allocated and converted utf-8 string or NULL if in16 is 0.
*/
char *alloc_utf_8_from_16(const wchar_t *in16, size_t add);
/**
* Allocates and converts the utf-16 string from utf-8
* \param in8: utf-8 string to convert
* \param add: any additional size which will be allocated for new utf-16 string
* @param in8 utf-8 string to convert
* @param add any additional size which will be allocated for new utf-16 string
* in wchar_t (two bytes)
* \return New allocated and converted utf-16 string or NULL if in8 is 0.
* @return New allocated and converted utf-16 string or NULL if in8 is 0.
*/
wchar_t *alloc_utf16_from_8(const char *in8, size_t add);

View File

@@ -54,11 +54,6 @@ while [[ $# -gt 0 ]]; do
shift
shift
;;
--background-image)
_background_image="$2"
shift
shift
;;
-h|--help)
echo "Usage:"
echo " $(basename "$0") --source DIR --dmg IMAGENAME "

File diff suppressed because it is too large Load Diff

Before

Width:  |  Height:  |  Size: 2.6 MiB

After

Width:  |  Height:  |  Size: 2.4 MiB

Some files were not shown because too many files have changed in this diff Show More