2022-02-11 09:07:11 +11:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
|
* Copyright 2006 Blender Foundation. All rights reserved. */
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
|
2019-02-18 08:08:12 +11:00
|
|
|
/** \file
|
|
|
|
|
* \ingroup gpu
|
2014-01-19 23:14:24 +11:00
|
|
|
*
|
|
|
|
|
* Manages materials, lights and textures.
|
2011-02-27 20:25:53 +00:00
|
|
|
*/
|
|
|
|
|
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
#include <math.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
|
|
#include "MEM_guardedalloc.h"
|
|
|
|
|
|
|
|
|
|
#include "DNA_material_types.h"
|
|
|
|
|
#include "DNA_scene_types.h"
|
|
|
|
|
#include "DNA_world_types.h"
|
|
|
|
|
|
2018-07-20 20:06:39 +02:00
|
|
|
#include "BLI_listbase.h"
|
2020-03-19 09:33:03 +01:00
|
|
|
#include "BLI_math.h"
|
2018-08-02 18:31:38 +02:00
|
|
|
#include "BLI_string.h"
|
2019-05-16 16:43:41 +02:00
|
|
|
#include "BLI_string_utils.h"
|
2020-03-19 09:33:03 +01:00
|
|
|
#include "BLI_utildefines.h"
|
2011-01-07 18:36:47 +00:00
|
|
|
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
#include "BKE_main.h"
|
2020-02-06 13:05:45 +01:00
|
|
|
#include "BKE_material.h"
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
#include "BKE_node.h"
|
|
|
|
|
#include "BKE_scene.h"
|
2022-04-14 18:47:58 +02:00
|
|
|
#include "BKE_world.h"
|
2011-01-07 19:18:31 +00:00
|
|
|
|
2022-01-24 16:18:30 -06:00
|
|
|
#include "NOD_shader.h"
|
|
|
|
|
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
#include "GPU_material.h"
|
2015-12-06 21:20:19 +01:00
|
|
|
#include "GPU_shader.h"
|
|
|
|
|
#include "GPU_texture.h"
|
2020-08-20 23:09:37 +02:00
|
|
|
#include "GPU_uniform_buffer.h"
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
|
2018-03-05 00:54:31 +01:00
|
|
|
#include "DRW_engine.h"
|
|
|
|
|
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
#include "gpu_codegen.h"
|
2020-02-12 12:48:44 +01:00
|
|
|
#include "gpu_node_graph.h"
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
|
|
|
|
|
/* Structs */
|
2018-08-10 15:13:39 +02:00
|
|
|
#define MAX_COLOR_BAND 128
|
|
|
|
|
|
|
|
|
|
typedef struct GPUColorBandBuilder {
|
|
|
|
|
float pixels[MAX_COLOR_BAND][CM_TABLE + 1][4];
|
|
|
|
|
int current_layer;
|
|
|
|
|
} GPUColorBandBuilder;
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
|
|
|
|
|
struct GPUMaterial {
|
2022-04-14 18:47:58 +02:00
|
|
|
/* Contains GPUShader and source code for deferred compilation.
|
|
|
|
|
* Can be shared between similar material (i.e: sharing same nodetree topology). */
|
|
|
|
|
GPUPass *pass;
|
|
|
|
|
/** UBOs for this material parameters. */
|
|
|
|
|
GPUUniformBuf *ubo;
|
|
|
|
|
/** Compilation status. Do not use if shader is not GPU_MAT_SUCCESS. */
|
2019-01-23 14:15:43 +11:00
|
|
|
eGPUMaterialStatus status;
|
2022-04-14 18:47:58 +02:00
|
|
|
/** Some flags about the nodetree & the needed resources. */
|
|
|
|
|
eGPUMaterialFlag flag;
|
|
|
|
|
/* Identify shader variations (shadow, probe, world background...).
|
|
|
|
|
* Should be unique even across render engines. */
|
|
|
|
|
uint64_t uuid;
|
|
|
|
|
/* Number of generated function. */
|
|
|
|
|
int generated_function_len;
|
|
|
|
|
/** Object type for attribute fetching. */
|
|
|
|
|
bool is_volume_shader;
|
|
|
|
|
|
|
|
|
|
/** DEPRECATED Currently only used for deferred compilation. */
|
|
|
|
|
Scene *scene;
|
|
|
|
|
/** Source material, might be null. */
|
|
|
|
|
Material *ma;
|
|
|
|
|
/** 1D Texture array containing all color bands. */
|
|
|
|
|
GPUTexture *coba_tex;
|
|
|
|
|
/** Builder for coba_tex. */
|
|
|
|
|
GPUColorBandBuilder *coba_builder;
|
|
|
|
|
/* Low level node graph(s). Also contains resources needed by the material. */
|
2020-02-12 12:48:44 +01:00
|
|
|
GPUNodeGraph graph;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2022-04-14 18:47:58 +02:00
|
|
|
/** DEPRECATED: To remove. */
|
2020-03-11 14:58:19 +01:00
|
|
|
bool has_surface_output;
|
2022-04-14 18:47:58 +02:00
|
|
|
bool has_volume_output;
|
|
|
|
|
/** DEPRECATED: To remove. */
|
2020-08-20 23:09:37 +02:00
|
|
|
GPUUniformBuf *sss_profile; /* UBO containing SSS profile. */
|
|
|
|
|
GPUTexture *sss_tex_profile; /* Texture containing SSS profile. */
|
2022-04-14 18:47:58 +02:00
|
|
|
bool sss_enabled;
|
2018-06-07 18:43:43 +02:00
|
|
|
float sss_radii[3];
|
2017-11-14 02:17:34 +01:00
|
|
|
int sss_samples;
|
2017-11-14 00:49:54 +01:00
|
|
|
bool sss_dirty;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-08-02 18:31:38 +02:00
|
|
|
#ifndef NDEBUG
|
|
|
|
|
char name[64];
|
|
|
|
|
#endif
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/* Functions */
|
|
|
|
|
|
2018-08-10 15:13:39 +02:00
|
|
|
GPUTexture **gpu_material_ramp_texture_row_set(GPUMaterial *mat,
|
|
|
|
|
int size,
|
|
|
|
|
float *pixels,
|
|
|
|
|
float *row)
|
|
|
|
|
{
|
2020-09-07 15:57:12 +10:00
|
|
|
/* In order to put all the color-bands into one 1D array texture,
|
2018-08-10 15:13:39 +02:00
|
|
|
* we need them to be the same size. */
|
|
|
|
|
BLI_assert(size == CM_TABLE + 1);
|
2018-09-10 09:56:14 +02:00
|
|
|
UNUSED_VARS_NDEBUG(size);
|
2018-08-10 15:13:39 +02:00
|
|
|
|
|
|
|
|
if (mat->coba_builder == NULL) {
|
|
|
|
|
mat->coba_builder = MEM_mallocN(sizeof(GPUColorBandBuilder), "GPUColorBandBuilder");
|
|
|
|
|
mat->coba_builder->current_layer = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int layer = mat->coba_builder->current_layer;
|
|
|
|
|
*row = (float)layer;
|
|
|
|
|
|
|
|
|
|
if (*row == MAX_COLOR_BAND) {
|
|
|
|
|
printf("Too many color band in shader! Remove some Curve, Black Body or Color Ramp Node.\n");
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
float *dst = (float *)mat->coba_builder->pixels[layer];
|
|
|
|
|
memcpy(dst, pixels, sizeof(float) * (CM_TABLE + 1) * 4);
|
|
|
|
|
mat->coba_builder->current_layer += 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return &mat->coba_tex;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void gpu_material_ramp_texture_build(GPUMaterial *mat)
|
|
|
|
|
{
|
2019-04-22 09:32:37 +10:00
|
|
|
if (mat->coba_builder == NULL) {
|
2018-08-10 15:13:39 +02:00
|
|
|
return;
|
2019-04-22 09:32:37 +10:00
|
|
|
}
|
2018-08-10 15:13:39 +02:00
|
|
|
|
|
|
|
|
GPUColorBandBuilder *builder = mat->coba_builder;
|
|
|
|
|
|
2019-03-20 18:17:16 +11:00
|
|
|
mat->coba_tex = GPU_texture_create_1d_array(
|
2020-09-05 17:33:56 +02:00
|
|
|
"mat_ramp", CM_TABLE + 1, builder->current_layer, 1, GPU_RGBA16F, (float *)builder->pixels);
|
2018-08-10 15:13:39 +02:00
|
|
|
|
|
|
|
|
MEM_freeN(builder);
|
|
|
|
|
mat->coba_builder = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2018-06-08 16:11:34 +02:00
|
|
|
static void gpu_material_free_single(GPUMaterial *material)
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
{
|
2018-06-08 16:11:34 +02:00
|
|
|
/* Cancel / wait any pending lazy compilation. */
|
|
|
|
|
DRW_deferred_shader_remove(material);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-02-12 12:48:44 +01:00
|
|
|
gpu_node_graph_free(&material->graph);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-08-10 15:13:39 +02:00
|
|
|
if (material->pass != NULL) {
|
2018-06-08 16:11:34 +02:00
|
|
|
GPU_pass_release(material->pass);
|
2018-08-10 15:13:39 +02:00
|
|
|
}
|
2018-06-08 16:11:34 +02:00
|
|
|
if (material->ubo != NULL) {
|
2020-08-20 23:09:37 +02:00
|
|
|
GPU_uniformbuf_free(material->ubo);
|
2018-06-08 16:11:34 +02:00
|
|
|
}
|
2022-04-14 18:47:58 +02:00
|
|
|
if (material->coba_tex != NULL) {
|
|
|
|
|
GPU_texture_free(material->coba_tex);
|
2018-06-08 16:11:34 +02:00
|
|
|
}
|
|
|
|
|
if (material->sss_profile != NULL) {
|
2020-08-20 23:09:37 +02:00
|
|
|
GPU_uniformbuf_free(material->sss_profile);
|
2018-06-08 16:11:34 +02:00
|
|
|
}
|
2022-04-14 18:47:58 +02:00
|
|
|
if (material->sss_tex_profile != NULL) {
|
|
|
|
|
GPU_texture_free(material->sss_tex_profile);
|
2018-08-10 15:13:39 +02:00
|
|
|
}
|
2018-06-08 16:11:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void GPU_material_free(ListBase *gpumaterial)
|
|
|
|
|
{
|
2020-04-03 19:15:01 +02:00
|
|
|
LISTBASE_FOREACH (LinkData *, link, gpumaterial) {
|
2018-06-08 16:11:34 +02:00
|
|
|
GPUMaterial *material = link->data;
|
2018-07-19 15:48:13 +02:00
|
|
|
gpu_material_free_single(material);
|
|
|
|
|
MEM_freeN(material);
|
2018-06-08 16:11:34 +02:00
|
|
|
}
|
|
|
|
|
BLI_freelistN(gpumaterial);
|
|
|
|
|
}
|
2017-11-14 00:49:54 +01:00
|
|
|
|
2013-11-25 20:58:23 +09:00
|
|
|
Scene *GPU_material_scene(GPUMaterial *material)
|
|
|
|
|
{
|
|
|
|
|
return material->scene;
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-27 22:27:09 +02:00
|
|
|
GPUPass *GPU_material_get_pass(GPUMaterial *material)
|
|
|
|
|
{
|
|
|
|
|
return material->pass;
|
|
|
|
|
}
|
2014-11-24 17:18:56 +01:00
|
|
|
|
2020-06-02 16:58:07 +02:00
|
|
|
GPUShader *GPU_material_get_shader(GPUMaterial *material)
|
|
|
|
|
{
|
|
|
|
|
return material->pass ? GPU_pass_shader_get(material->pass) : NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-11 14:37:27 +02:00
|
|
|
Material *GPU_material_get_material(GPUMaterial *material)
|
|
|
|
|
{
|
|
|
|
|
return material->ma;
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-20 23:09:37 +02:00
|
|
|
GPUUniformBuf *GPU_material_uniform_buffer_get(GPUMaterial *material)
|
2017-07-14 17:40:54 +02:00
|
|
|
{
|
|
|
|
|
return material->ubo;
|
|
|
|
|
}
|
|
|
|
|
|
2018-06-07 19:40:47 +02:00
|
|
|
void GPU_material_uniform_buffer_create(GPUMaterial *material, ListBase *inputs)
|
2017-07-14 17:40:54 +02:00
|
|
|
{
|
2020-08-20 23:09:37 +02:00
|
|
|
#ifndef NDEBUG
|
|
|
|
|
const char *name = material->name;
|
|
|
|
|
#else
|
2020-08-23 14:48:44 +02:00
|
|
|
const char *name = "Material";
|
2020-08-20 23:09:37 +02:00
|
|
|
#endif
|
2020-08-21 12:30:55 +02:00
|
|
|
material->ubo = GPU_uniformbuf_create_from_list(inputs, name);
|
2017-07-14 17:40:54 +02:00
|
|
|
}
|
|
|
|
|
|
2022-04-14 18:47:58 +02:00
|
|
|
ListBase GPU_material_attributes(GPUMaterial *material)
|
|
|
|
|
{
|
|
|
|
|
return material->graph.attributes;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ListBase GPU_material_textures(GPUMaterial *material)
|
|
|
|
|
{
|
|
|
|
|
return material->graph.textures;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
GPUUniformAttrList *GPU_material_uniform_attributes(GPUMaterial *material)
|
|
|
|
|
{
|
|
|
|
|
GPUUniformAttrList *attrs = &material->graph.uniform_attrs;
|
|
|
|
|
return attrs->count > 0 ? attrs : NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#if 1 /* End of life code. */
|
2017-11-14 00:49:54 +01:00
|
|
|
/* Eevee Subsurface scattering. */
|
|
|
|
|
/* Based on Separable SSS. by Jorge Jimenez and Diego Gutierrez */
|
|
|
|
|
|
2022-04-14 18:47:58 +02:00
|
|
|
# define SSS_SAMPLES 65
|
|
|
|
|
# define SSS_EXPONENT 2.0f /* Importance sampling exponent */
|
2017-11-14 00:49:54 +01:00
|
|
|
|
|
|
|
|
typedef struct GPUSssKernelData {
|
|
|
|
|
float kernel[SSS_SAMPLES][4];
|
2017-11-22 04:51:21 +01:00
|
|
|
float param[3], max_radius;
|
2022-04-14 18:47:58 +02:00
|
|
|
float avg_inv_radius;
|
2017-11-22 04:51:21 +01:00
|
|
|
int samples;
|
2022-04-14 18:47:58 +02:00
|
|
|
int pad[2];
|
2017-11-14 00:49:54 +01:00
|
|
|
} GPUSssKernelData;
|
|
|
|
|
|
2019-05-29 16:57:09 +02:00
|
|
|
BLI_STATIC_ASSERT_ALIGN(GPUSssKernelData, 16)
|
|
|
|
|
|
2017-11-22 04:51:21 +01:00
|
|
|
static void sss_calculate_offsets(GPUSssKernelData *kd, int count, float exponent)
|
2017-11-14 00:49:54 +01:00
|
|
|
{
|
2017-11-14 02:17:34 +01:00
|
|
|
float step = 2.0f / (float)(count - 1);
|
|
|
|
|
for (int i = 0; i < count; i++) {
|
2017-11-14 00:49:54 +01:00
|
|
|
float o = ((float)i) * step - 1.0f;
|
|
|
|
|
float sign = (o < 0.0f) ? -1.0f : 1.0f;
|
2017-11-22 04:51:21 +01:00
|
|
|
float ofs = sign * fabsf(powf(o, exponent));
|
2017-11-14 00:49:54 +01:00
|
|
|
kd->kernel[i][3] = ofs;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-14 18:47:58 +02:00
|
|
|
# define BURLEY_TRUNCATE 16.0f
|
|
|
|
|
# define BURLEY_TRUNCATE_CDF 0.9963790093708328f // cdf(BURLEY_TRUNCATE)
|
2017-11-16 21:28:40 +01:00
|
|
|
static float burley_profile(float r, float d)
|
2017-11-14 00:49:54 +01:00
|
|
|
{
|
2017-11-16 21:28:40 +01:00
|
|
|
float exp_r_3_d = expf(-r / (3.0f * d));
|
|
|
|
|
float exp_r_d = exp_r_3_d * exp_r_3_d * exp_r_3_d;
|
|
|
|
|
return (exp_r_d + exp_r_3_d) / (4.0f * d);
|
|
|
|
|
}
|
|
|
|
|
|
Cycles: merge of cycles-x branch, a major update to the renderer
This includes much improved GPU rendering performance, viewport interactivity,
new shadow catcher, revamped sampling settings, subsurface scattering anisotropy,
new GPU volume sampling, improved PMJ sampling pattern, and more.
Some features have also been removed or changed, breaking backwards compatibility.
Including the removal of the OpenCL backend, for which alternatives are under
development.
Release notes and code docs:
https://wiki.blender.org/wiki/Reference/Release_Notes/3.0/Cycles
https://wiki.blender.org/wiki/Source/Render/Cycles
Credits:
* Sergey Sharybin
* Brecht Van Lommel
* Patrick Mours (OptiX backend)
* Christophe Hery (subsurface scattering anisotropy)
* William Leeson (PMJ sampling pattern)
* Alaska (various fixes and tweaks)
* Thomas Dinges (various fixes)
For the full commit history, see the cycles-x branch. This squashes together
all the changes since intermediate changes would often fail building or tests.
Ref T87839, T87837, T87836
Fixes T90734, T89353, T80267, T80267, T77185, T69800
2021-09-20 17:59:20 +02:00
|
|
|
static float eval_profile(float r, float param)
|
2017-11-22 04:51:21 +01:00
|
|
|
{
|
|
|
|
|
r = fabsf(r);
|
Cycles: merge of cycles-x branch, a major update to the renderer
This includes much improved GPU rendering performance, viewport interactivity,
new shadow catcher, revamped sampling settings, subsurface scattering anisotropy,
new GPU volume sampling, improved PMJ sampling pattern, and more.
Some features have also been removed or changed, breaking backwards compatibility.
Including the removal of the OpenCL backend, for which alternatives are under
development.
Release notes and code docs:
https://wiki.blender.org/wiki/Reference/Release_Notes/3.0/Cycles
https://wiki.blender.org/wiki/Source/Render/Cycles
Credits:
* Sergey Sharybin
* Brecht Van Lommel
* Patrick Mours (OptiX backend)
* Christophe Hery (subsurface scattering anisotropy)
* William Leeson (PMJ sampling pattern)
* Alaska (various fixes and tweaks)
* Thomas Dinges (various fixes)
For the full commit history, see the cycles-x branch. This squashes together
all the changes since intermediate changes would often fail building or tests.
Ref T87839, T87837, T87836
Fixes T90734, T89353, T80267, T80267, T77185, T69800
2021-09-20 17:59:20 +02:00
|
|
|
return burley_profile(r, param) / BURLEY_TRUNCATE_CDF;
|
2017-11-22 04:51:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Resolution for each sample of the precomputed kernel profile */
|
2022-04-14 18:47:58 +02:00
|
|
|
# define INTEGRAL_RESOLUTION 32
|
Cycles: merge of cycles-x branch, a major update to the renderer
This includes much improved GPU rendering performance, viewport interactivity,
new shadow catcher, revamped sampling settings, subsurface scattering anisotropy,
new GPU volume sampling, improved PMJ sampling pattern, and more.
Some features have also been removed or changed, breaking backwards compatibility.
Including the removal of the OpenCL backend, for which alternatives are under
development.
Release notes and code docs:
https://wiki.blender.org/wiki/Reference/Release_Notes/3.0/Cycles
https://wiki.blender.org/wiki/Source/Render/Cycles
Credits:
* Sergey Sharybin
* Brecht Van Lommel
* Patrick Mours (OptiX backend)
* Christophe Hery (subsurface scattering anisotropy)
* William Leeson (PMJ sampling pattern)
* Alaska (various fixes and tweaks)
* Thomas Dinges (various fixes)
For the full commit history, see the cycles-x branch. This squashes together
all the changes since intermediate changes would often fail building or tests.
Ref T87839, T87837, T87836
Fixes T90734, T89353, T80267, T80267, T77185, T69800
2021-09-20 17:59:20 +02:00
|
|
|
static float eval_integral(float x0, float x1, float param)
|
2017-11-17 02:00:48 +01:00
|
|
|
{
|
|
|
|
|
const float range = x1 - x0;
|
|
|
|
|
const float step = range / INTEGRAL_RESOLUTION;
|
|
|
|
|
float integral = 0.0f;
|
|
|
|
|
|
2019-09-08 00:12:26 +10:00
|
|
|
for (int i = 0; i < INTEGRAL_RESOLUTION; i++) {
|
2017-11-17 02:00:48 +01:00
|
|
|
float x = x0 + range * ((float)i + 0.5f) / (float)INTEGRAL_RESOLUTION;
|
Cycles: merge of cycles-x branch, a major update to the renderer
This includes much improved GPU rendering performance, viewport interactivity,
new shadow catcher, revamped sampling settings, subsurface scattering anisotropy,
new GPU volume sampling, improved PMJ sampling pattern, and more.
Some features have also been removed or changed, breaking backwards compatibility.
Including the removal of the OpenCL backend, for which alternatives are under
development.
Release notes and code docs:
https://wiki.blender.org/wiki/Reference/Release_Notes/3.0/Cycles
https://wiki.blender.org/wiki/Source/Render/Cycles
Credits:
* Sergey Sharybin
* Brecht Van Lommel
* Patrick Mours (OptiX backend)
* Christophe Hery (subsurface scattering anisotropy)
* William Leeson (PMJ sampling pattern)
* Alaska (various fixes and tweaks)
* Thomas Dinges (various fixes)
For the full commit history, see the cycles-x branch. This squashes together
all the changes since intermediate changes would often fail building or tests.
Ref T87839, T87837, T87836
Fixes T90734, T89353, T80267, T80267, T77185, T69800
2021-09-20 17:59:20 +02:00
|
|
|
float y = eval_profile(x, param);
|
2017-11-17 02:00:48 +01:00
|
|
|
integral += y * step;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return integral;
|
|
|
|
|
}
|
2022-04-14 18:47:58 +02:00
|
|
|
# undef INTEGRAL_RESOLUTION
|
2017-11-17 02:00:48 +01:00
|
|
|
|
Cycles: merge of cycles-x branch, a major update to the renderer
This includes much improved GPU rendering performance, viewport interactivity,
new shadow catcher, revamped sampling settings, subsurface scattering anisotropy,
new GPU volume sampling, improved PMJ sampling pattern, and more.
Some features have also been removed or changed, breaking backwards compatibility.
Including the removal of the OpenCL backend, for which alternatives are under
development.
Release notes and code docs:
https://wiki.blender.org/wiki/Reference/Release_Notes/3.0/Cycles
https://wiki.blender.org/wiki/Source/Render/Cycles
Credits:
* Sergey Sharybin
* Brecht Van Lommel
* Patrick Mours (OptiX backend)
* Christophe Hery (subsurface scattering anisotropy)
* William Leeson (PMJ sampling pattern)
* Alaska (various fixes and tweaks)
* Thomas Dinges (various fixes)
For the full commit history, see the cycles-x branch. This squashes together
all the changes since intermediate changes would often fail building or tests.
Ref T87839, T87837, T87836
Fixes T90734, T89353, T80267, T80267, T77185, T69800
2021-09-20 17:59:20 +02:00
|
|
|
static void compute_sss_kernel(GPUSssKernelData *kd, const float radii[3], int sample_len)
|
2017-11-16 21:28:40 +01:00
|
|
|
{
|
2017-11-22 04:51:21 +01:00
|
|
|
float rad[3];
|
|
|
|
|
/* Minimum radius */
|
|
|
|
|
rad[0] = MAX2(radii[0], 1e-15f);
|
|
|
|
|
rad[1] = MAX2(radii[1], 1e-15f);
|
|
|
|
|
rad[2] = MAX2(radii[2], 1e-15f);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2022-04-14 18:47:58 +02:00
|
|
|
kd->avg_inv_radius = 3.0f / (rad[0] + rad[1] + rad[2]);
|
|
|
|
|
|
2017-11-16 21:28:40 +01:00
|
|
|
/* Christensen-Burley fitting */
|
|
|
|
|
float l[3], d[3];
|
2019-04-17 06:17:24 +02:00
|
|
|
|
Cycles: merge of cycles-x branch, a major update to the renderer
This includes much improved GPU rendering performance, viewport interactivity,
new shadow catcher, revamped sampling settings, subsurface scattering anisotropy,
new GPU volume sampling, improved PMJ sampling pattern, and more.
Some features have also been removed or changed, breaking backwards compatibility.
Including the removal of the OpenCL backend, for which alternatives are under
development.
Release notes and code docs:
https://wiki.blender.org/wiki/Reference/Release_Notes/3.0/Cycles
https://wiki.blender.org/wiki/Source/Render/Cycles
Credits:
* Sergey Sharybin
* Brecht Van Lommel
* Patrick Mours (OptiX backend)
* Christophe Hery (subsurface scattering anisotropy)
* William Leeson (PMJ sampling pattern)
* Alaska (various fixes and tweaks)
* Thomas Dinges (various fixes)
For the full commit history, see the cycles-x branch. This squashes together
all the changes since intermediate changes would often fail building or tests.
Ref T87839, T87837, T87836
Fixes T90734, T89353, T80267, T80267, T77185, T69800
2021-09-20 17:59:20 +02:00
|
|
|
mul_v3_v3fl(l, rad, 0.25f * M_1_PI);
|
|
|
|
|
const float A = 1.0f;
|
|
|
|
|
const float s = 1.9f - A + 3.5f * (A - 0.8f) * (A - 0.8f);
|
|
|
|
|
/* XXX 0.6f Out of nowhere to match cycles! Empirical! Can be tweak better. */
|
|
|
|
|
mul_v3_v3fl(d, l, 0.6f / s);
|
|
|
|
|
mul_v3_v3fl(rad, d, BURLEY_TRUNCATE);
|
|
|
|
|
kd->max_radius = MAX3(rad[0], rad[1], rad[2]);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
Cycles: merge of cycles-x branch, a major update to the renderer
This includes much improved GPU rendering performance, viewport interactivity,
new shadow catcher, revamped sampling settings, subsurface scattering anisotropy,
new GPU volume sampling, improved PMJ sampling pattern, and more.
Some features have also been removed or changed, breaking backwards compatibility.
Including the removal of the OpenCL backend, for which alternatives are under
development.
Release notes and code docs:
https://wiki.blender.org/wiki/Reference/Release_Notes/3.0/Cycles
https://wiki.blender.org/wiki/Source/Render/Cycles
Credits:
* Sergey Sharybin
* Brecht Van Lommel
* Patrick Mours (OptiX backend)
* Christophe Hery (subsurface scattering anisotropy)
* William Leeson (PMJ sampling pattern)
* Alaska (various fixes and tweaks)
* Thomas Dinges (various fixes)
For the full commit history, see the cycles-x branch. This squashes together
all the changes since intermediate changes would often fail building or tests.
Ref T87839, T87837, T87836
Fixes T90734, T89353, T80267, T80267, T77185, T69800
2021-09-20 17:59:20 +02:00
|
|
|
copy_v3_v3(kd->param, d);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2017-11-16 21:28:40 +01:00
|
|
|
/* Compute samples locations on the 1d kernel [-1..1] */
|
2018-07-08 13:14:49 +02:00
|
|
|
sss_calculate_offsets(kd, sample_len, SSS_EXPONENT);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2017-11-14 00:49:54 +01:00
|
|
|
/* Weights sum for normalization */
|
|
|
|
|
float sum[3] = {0.0f, 0.0f, 0.0f};
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2017-11-16 21:28:40 +01:00
|
|
|
/* Compute integral of each sample footprint */
|
2018-07-08 13:14:49 +02:00
|
|
|
for (int i = 0; i < sample_len; i++) {
|
2017-11-14 00:49:54 +01:00
|
|
|
float x0, x1;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2017-11-14 00:49:54 +01:00
|
|
|
if (i == 0) {
|
2017-11-20 22:04:14 +01:00
|
|
|
x0 = kd->kernel[0][3] - fabsf(kd->kernel[0][3] - kd->kernel[1][3]) / 2.0f;
|
2017-11-14 00:49:54 +01:00
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
x0 = (kd->kernel[i - 1][3] + kd->kernel[i][3]) / 2.0f;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-07-08 13:14:49 +02:00
|
|
|
if (i == sample_len - 1) {
|
|
|
|
|
x1 = kd->kernel[sample_len - 1][3] +
|
|
|
|
|
fabsf(kd->kernel[sample_len - 2][3] - kd->kernel[sample_len - 1][3]) / 2.0f;
|
2017-11-14 00:49:54 +01:00
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
x1 = (kd->kernel[i][3] + kd->kernel[i + 1][3]) / 2.0f;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2017-11-22 04:51:21 +01:00
|
|
|
x0 *= kd->max_radius;
|
|
|
|
|
x1 *= kd->max_radius;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
Cycles: merge of cycles-x branch, a major update to the renderer
This includes much improved GPU rendering performance, viewport interactivity,
new shadow catcher, revamped sampling settings, subsurface scattering anisotropy,
new GPU volume sampling, improved PMJ sampling pattern, and more.
Some features have also been removed or changed, breaking backwards compatibility.
Including the removal of the OpenCL backend, for which alternatives are under
development.
Release notes and code docs:
https://wiki.blender.org/wiki/Reference/Release_Notes/3.0/Cycles
https://wiki.blender.org/wiki/Source/Render/Cycles
Credits:
* Sergey Sharybin
* Brecht Van Lommel
* Patrick Mours (OptiX backend)
* Christophe Hery (subsurface scattering anisotropy)
* William Leeson (PMJ sampling pattern)
* Alaska (various fixes and tweaks)
* Thomas Dinges (various fixes)
For the full commit history, see the cycles-x branch. This squashes together
all the changes since intermediate changes would often fail building or tests.
Ref T87839, T87837, T87836
Fixes T90734, T89353, T80267, T80267, T77185, T69800
2021-09-20 17:59:20 +02:00
|
|
|
kd->kernel[i][0] = eval_integral(x0, x1, kd->param[0]);
|
|
|
|
|
kd->kernel[i][1] = eval_integral(x0, x1, kd->param[1]);
|
|
|
|
|
kd->kernel[i][2] = eval_integral(x0, x1, kd->param[2]);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2017-11-14 00:49:54 +01:00
|
|
|
sum[0] += kd->kernel[i][0];
|
|
|
|
|
sum[1] += kd->kernel[i][1];
|
|
|
|
|
sum[2] += kd->kernel[i][2];
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-09-08 00:12:26 +10:00
|
|
|
for (int i = 0; i < 3; i++) {
|
2017-11-16 21:28:40 +01:00
|
|
|
if (sum[i] > 0.0f) {
|
|
|
|
|
/* Normalize */
|
2018-07-08 13:14:49 +02:00
|
|
|
for (int j = 0; j < sample_len; j++) {
|
2017-11-22 04:51:21 +01:00
|
|
|
kd->kernel[j][i] /= sum[i];
|
2017-11-16 21:28:40 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
/* Avoid 0 kernel sum. */
|
2018-07-08 13:14:49 +02:00
|
|
|
kd->kernel[sample_len / 2][i] = 1.0f;
|
2017-11-16 21:28:40 +01:00
|
|
|
}
|
2017-11-14 00:49:54 +01:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2017-11-14 00:49:54 +01:00
|
|
|
/* Put center sample at the start of the array (to sample first) */
|
|
|
|
|
float tmpv[4];
|
2018-07-08 13:14:49 +02:00
|
|
|
copy_v4_v4(tmpv, kd->kernel[sample_len / 2]);
|
|
|
|
|
for (int i = sample_len / 2; i > 0; i--) {
|
2017-11-14 00:49:54 +01:00
|
|
|
copy_v4_v4(kd->kernel[i], kd->kernel[i - 1]);
|
|
|
|
|
}
|
|
|
|
|
copy_v4_v4(kd->kernel[0], tmpv);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-07-08 13:14:49 +02:00
|
|
|
kd->samples = sample_len;
|
2017-11-22 04:51:21 +01:00
|
|
|
}
|
|
|
|
|
|
2022-04-14 18:47:58 +02:00
|
|
|
# define INTEGRAL_RESOLUTION 512
|
2017-11-22 04:51:21 +01:00
|
|
|
static void compute_sss_translucence_kernel(const GPUSssKernelData *kd,
|
|
|
|
|
int resolution,
|
|
|
|
|
float **output)
|
|
|
|
|
{
|
|
|
|
|
float(*texels)[4];
|
2020-08-08 13:29:21 +10:00
|
|
|
texels = MEM_callocN(sizeof(float[4]) * resolution, "compute_sss_translucence_kernel");
|
2017-11-22 04:51:21 +01:00
|
|
|
*output = (float *)texels;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2017-11-22 04:51:21 +01:00
|
|
|
/* Last texel should be black, hence the - 1. */
|
2019-09-08 00:12:26 +10:00
|
|
|
for (int i = 0; i < resolution - 1; i++) {
|
2017-11-22 04:51:21 +01:00
|
|
|
/* Distance from surface. */
|
|
|
|
|
float d = kd->max_radius * ((float)i + 0.00001f) / ((float)resolution);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-08-02 15:22:54 +10:00
|
|
|
/* For each distance d we compute the radiance incoming from an hypothetical parallel plane. */
|
|
|
|
|
/* Compute radius of the footprint on the hypothetical plane. */
|
2017-11-22 04:51:21 +01:00
|
|
|
float r_fp = sqrtf(kd->max_radius * kd->max_radius - d * d);
|
|
|
|
|
float r_step = r_fp / INTEGRAL_RESOLUTION;
|
|
|
|
|
float area_accum = 0.0f;
|
|
|
|
|
for (float r = 0.0f; r < r_fp; r += r_step) {
|
|
|
|
|
/* Compute distance to the "shading" point through the medium. */
|
|
|
|
|
/* r_step * 0.5f to put sample between the area borders */
|
|
|
|
|
float dist = hypotf(r + r_step * 0.5f, d);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2017-11-22 04:51:21 +01:00
|
|
|
float profile[3];
|
Cycles: merge of cycles-x branch, a major update to the renderer
This includes much improved GPU rendering performance, viewport interactivity,
new shadow catcher, revamped sampling settings, subsurface scattering anisotropy,
new GPU volume sampling, improved PMJ sampling pattern, and more.
Some features have also been removed or changed, breaking backwards compatibility.
Including the removal of the OpenCL backend, for which alternatives are under
development.
Release notes and code docs:
https://wiki.blender.org/wiki/Reference/Release_Notes/3.0/Cycles
https://wiki.blender.org/wiki/Source/Render/Cycles
Credits:
* Sergey Sharybin
* Brecht Van Lommel
* Patrick Mours (OptiX backend)
* Christophe Hery (subsurface scattering anisotropy)
* William Leeson (PMJ sampling pattern)
* Alaska (various fixes and tweaks)
* Thomas Dinges (various fixes)
For the full commit history, see the cycles-x branch. This squashes together
all the changes since intermediate changes would often fail building or tests.
Ref T87839, T87837, T87836
Fixes T90734, T89353, T80267, T80267, T77185, T69800
2021-09-20 17:59:20 +02:00
|
|
|
profile[0] = eval_profile(dist, kd->param[0]);
|
|
|
|
|
profile[1] = eval_profile(dist, kd->param[1]);
|
|
|
|
|
profile[2] = eval_profile(dist, kd->param[2]);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-09-24 18:46:51 +02:00
|
|
|
/* Since the profile and configuration are radially symmetrical we
|
2017-11-22 04:51:21 +01:00
|
|
|
* can just evaluate it once and weight it accordingly */
|
|
|
|
|
float r_next = r + r_step;
|
|
|
|
|
float disk_area = (M_PI * r_next * r_next) - (M_PI * r * r);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2017-11-22 04:51:21 +01:00
|
|
|
mul_v3_fl(profile, disk_area);
|
|
|
|
|
add_v3_v3(texels[i], profile);
|
|
|
|
|
area_accum += disk_area;
|
|
|
|
|
}
|
|
|
|
|
/* Normalize over the disk. */
|
|
|
|
|
mul_v3_fl(texels[i], 1.0f / (area_accum));
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2017-11-22 04:51:21 +01:00
|
|
|
/* Normalize */
|
|
|
|
|
for (int j = resolution - 2; j > 0; j--) {
|
|
|
|
|
texels[j][0] /= (texels[0][0] > 0.0f) ? texels[0][0] : 1.0f;
|
|
|
|
|
texels[j][1] /= (texels[0][1] > 0.0f) ? texels[0][1] : 1.0f;
|
|
|
|
|
texels[j][2] /= (texels[0][2] > 0.0f) ? texels[0][2] : 1.0f;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2017-11-22 04:51:21 +01:00
|
|
|
/* First texel should be white */
|
|
|
|
|
texels[0][0] = (texels[0][0] > 0.0f) ? 1.0f : 0.0f;
|
|
|
|
|
texels[0][1] = (texels[0][1] > 0.0f) ? 1.0f : 0.0f;
|
|
|
|
|
texels[0][2] = (texels[0][2] > 0.0f) ? 1.0f : 0.0f;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2017-11-22 04:51:21 +01:00
|
|
|
/* dim the last few texels for smoother transition */
|
|
|
|
|
mul_v3_fl(texels[resolution - 2], 0.25f);
|
|
|
|
|
mul_v3_fl(texels[resolution - 3], 0.5f);
|
|
|
|
|
mul_v3_fl(texels[resolution - 4], 0.75f);
|
2017-11-14 00:49:54 +01:00
|
|
|
}
|
2022-04-14 18:47:58 +02:00
|
|
|
# undef INTEGRAL_RESOLUTION
|
2017-11-14 00:49:54 +01:00
|
|
|
|
2022-04-14 18:47:58 +02:00
|
|
|
bool GPU_material_sss_profile_create(GPUMaterial *material, float radii[3])
|
2017-11-14 00:49:54 +01:00
|
|
|
{
|
2022-04-14 18:47:58 +02:00
|
|
|
/* Enable only once. */
|
|
|
|
|
if (material->sss_enabled) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2018-06-07 18:43:43 +02:00
|
|
|
copy_v3_v3(material->sss_radii, radii);
|
2017-11-14 00:49:54 +01:00
|
|
|
material->sss_dirty = true;
|
2018-06-07 18:43:43 +02:00
|
|
|
material->sss_enabled = true;
|
2017-11-14 00:49:54 +01:00
|
|
|
|
|
|
|
|
/* Update / Create UBO */
|
|
|
|
|
if (material->sss_profile == NULL) {
|
2020-08-20 23:09:37 +02:00
|
|
|
material->sss_profile = GPU_uniformbuf_create(sizeof(GPUSssKernelData));
|
2017-11-14 00:49:54 +01:00
|
|
|
}
|
2022-04-14 18:47:58 +02:00
|
|
|
return true;
|
2017-11-14 00:49:54 +01:00
|
|
|
}
|
|
|
|
|
|
2020-08-20 23:09:37 +02:00
|
|
|
struct GPUUniformBuf *GPU_material_sss_profile_get(GPUMaterial *material,
|
|
|
|
|
int sample_len,
|
|
|
|
|
GPUTexture **tex_profile)
|
2017-11-14 00:49:54 +01:00
|
|
|
{
|
2019-04-22 09:32:37 +10:00
|
|
|
if (!material->sss_enabled) {
|
2017-11-14 02:17:34 +01:00
|
|
|
return NULL;
|
2019-04-22 09:32:37 +10:00
|
|
|
}
|
2017-11-14 00:49:54 +01:00
|
|
|
|
2018-07-08 13:14:49 +02:00
|
|
|
if (material->sss_dirty || (material->sss_samples != sample_len)) {
|
2017-11-14 02:17:34 +01:00
|
|
|
GPUSssKernelData kd;
|
2017-11-14 00:49:54 +01:00
|
|
|
|
Cycles: merge of cycles-x branch, a major update to the renderer
This includes much improved GPU rendering performance, viewport interactivity,
new shadow catcher, revamped sampling settings, subsurface scattering anisotropy,
new GPU volume sampling, improved PMJ sampling pattern, and more.
Some features have also been removed or changed, breaking backwards compatibility.
Including the removal of the OpenCL backend, for which alternatives are under
development.
Release notes and code docs:
https://wiki.blender.org/wiki/Reference/Release_Notes/3.0/Cycles
https://wiki.blender.org/wiki/Source/Render/Cycles
Credits:
* Sergey Sharybin
* Brecht Van Lommel
* Patrick Mours (OptiX backend)
* Christophe Hery (subsurface scattering anisotropy)
* William Leeson (PMJ sampling pattern)
* Alaska (various fixes and tweaks)
* Thomas Dinges (various fixes)
For the full commit history, see the cycles-x branch. This squashes together
all the changes since intermediate changes would often fail building or tests.
Ref T87839, T87837, T87836
Fixes T90734, T89353, T80267, T80267, T77185, T69800
2021-09-20 17:59:20 +02:00
|
|
|
compute_sss_kernel(&kd, material->sss_radii, sample_len);
|
2017-11-14 00:49:54 +01:00
|
|
|
|
2017-11-14 02:17:34 +01:00
|
|
|
/* Update / Create UBO */
|
2020-08-20 23:09:37 +02:00
|
|
|
GPU_uniformbuf_update(material->sss_profile, &kd);
|
2017-11-14 00:49:54 +01:00
|
|
|
|
2017-11-22 04:51:21 +01:00
|
|
|
/* Update / Create Tex */
|
|
|
|
|
float *translucence_profile;
|
Cycles: merge of cycles-x branch, a major update to the renderer
This includes much improved GPU rendering performance, viewport interactivity,
new shadow catcher, revamped sampling settings, subsurface scattering anisotropy,
new GPU volume sampling, improved PMJ sampling pattern, and more.
Some features have also been removed or changed, breaking backwards compatibility.
Including the removal of the OpenCL backend, for which alternatives are under
development.
Release notes and code docs:
https://wiki.blender.org/wiki/Reference/Release_Notes/3.0/Cycles
https://wiki.blender.org/wiki/Source/Render/Cycles
Credits:
* Sergey Sharybin
* Brecht Van Lommel
* Patrick Mours (OptiX backend)
* Christophe Hery (subsurface scattering anisotropy)
* William Leeson (PMJ sampling pattern)
* Alaska (various fixes and tweaks)
* Thomas Dinges (various fixes)
For the full commit history, see the cycles-x branch. This squashes together
all the changes since intermediate changes would often fail building or tests.
Ref T87839, T87837, T87836
Fixes T90734, T89353, T80267, T80267, T77185, T69800
2021-09-20 17:59:20 +02:00
|
|
|
compute_sss_translucence_kernel(&kd, 64, &translucence_profile);
|
2017-11-22 04:51:21 +01:00
|
|
|
|
|
|
|
|
if (material->sss_tex_profile != NULL) {
|
|
|
|
|
GPU_texture_free(material->sss_tex_profile);
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-05 17:33:56 +02:00
|
|
|
material->sss_tex_profile = GPU_texture_create_1d(
|
|
|
|
|
"sss_tex_profile", 64, 1, GPU_RGBA16F, translucence_profile);
|
2017-11-22 04:51:21 +01:00
|
|
|
|
|
|
|
|
MEM_freeN(translucence_profile);
|
|
|
|
|
|
2018-07-08 13:14:49 +02:00
|
|
|
material->sss_samples = sample_len;
|
2017-11-14 02:17:34 +01:00
|
|
|
material->sss_dirty = false;
|
2017-07-14 17:40:54 +02:00
|
|
|
}
|
2017-11-22 04:51:21 +01:00
|
|
|
|
|
|
|
|
if (tex_profile != NULL) {
|
|
|
|
|
*tex_profile = material->sss_tex_profile;
|
|
|
|
|
}
|
2017-11-14 00:49:54 +01:00
|
|
|
return material->sss_profile;
|
2017-07-14 17:40:54 +02:00
|
|
|
}
|
|
|
|
|
|
2020-08-20 23:09:37 +02:00
|
|
|
struct GPUUniformBuf *GPU_material_create_sss_profile_ubo(void)
|
2018-11-05 20:09:04 +01:00
|
|
|
{
|
2020-08-20 23:09:37 +02:00
|
|
|
return GPU_uniformbuf_create(sizeof(GPUSssKernelData));
|
2018-11-05 20:09:04 +01:00
|
|
|
}
|
|
|
|
|
|
2022-04-14 18:47:58 +02:00
|
|
|
# undef SSS_EXPONENT
|
|
|
|
|
# undef SSS_SAMPLES
|
|
|
|
|
#endif
|
2020-02-14 10:47:20 +01:00
|
|
|
|
2022-04-14 18:47:58 +02:00
|
|
|
void GPU_material_output_surface(GPUMaterial *material, GPUNodeLink *link)
|
2020-02-14 10:47:20 +01:00
|
|
|
{
|
2022-04-14 18:47:58 +02:00
|
|
|
if (!material->graph.outlink_surface) {
|
|
|
|
|
material->graph.outlink_surface = link;
|
|
|
|
|
material->has_surface_output = true;
|
|
|
|
|
}
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
}
|
|
|
|
|
|
2022-04-14 18:47:58 +02:00
|
|
|
void GPU_material_output_volume(GPUMaterial *material, GPUNodeLink *link)
|
2020-03-11 14:58:19 +01:00
|
|
|
{
|
2022-04-14 18:47:58 +02:00
|
|
|
if (!material->graph.outlink_volume) {
|
|
|
|
|
material->graph.outlink_volume = link;
|
|
|
|
|
material->has_volume_output = true;
|
|
|
|
|
}
|
2020-03-11 14:58:19 +01:00
|
|
|
}
|
|
|
|
|
|
2022-04-14 18:47:58 +02:00
|
|
|
void GPU_material_output_displacement(GPUMaterial *material, GPUNodeLink *link)
|
Materials: add custom object properties as uniform attributes.
This patch allows the user to type a property name into the
Attribute node, which will then output the value of the property
for each individual object, allowing to e.g. customize shaders
by object without duplicating the shader.
In order to make supporting this easier for Eevee, it is necessary
to explicitly choose whether the attribute is varying or uniform
via a dropdown option of the Attribute node. The dropdown also
allows choosing whether instancing should be taken into account.
The Cycles design treats all attributes as one common namespace,
so the Blender interface converts the enum to a name prefix that
can't be entered using keyboard.
In Eevee, the attributes are provided to the shader via a UBO indexed
with resource_id, similar to the existing Object Info data. Unlike it,
however, it is necessary to maintain a separate buffer for every
requested combination of attributes.
This is done using a hash table with the attribute set as the key,
as it is expected that technically different but similar materials
may use the same set of attributes. In addition, in order to minimize
wasted memory, a sparse UBO pool is implemented, so that chunks that
don't contain any data don't have to be allocated.
The back-end Cycles code is already refactored and committed by Brecht.
Differential Revision: https://developer.blender.org/D2057
2020-08-05 19:14:40 +03:00
|
|
|
{
|
2022-04-14 18:47:58 +02:00
|
|
|
if (!material->graph.outlink_displacement) {
|
|
|
|
|
material->graph.outlink_displacement = link;
|
|
|
|
|
}
|
Materials: add custom object properties as uniform attributes.
This patch allows the user to type a property name into the
Attribute node, which will then output the value of the property
for each individual object, allowing to e.g. customize shaders
by object without duplicating the shader.
In order to make supporting this easier for Eevee, it is necessary
to explicitly choose whether the attribute is varying or uniform
via a dropdown option of the Attribute node. The dropdown also
allows choosing whether instancing should be taken into account.
The Cycles design treats all attributes as one common namespace,
so the Blender interface converts the enum to a name prefix that
can't be entered using keyboard.
In Eevee, the attributes are provided to the shader via a UBO indexed
with resource_id, similar to the existing Object Info data. Unlike it,
however, it is necessary to maintain a separate buffer for every
requested combination of attributes.
This is done using a hash table with the attribute set as the key,
as it is expected that technically different but similar materials
may use the same set of attributes. In addition, in order to minimize
wasted memory, a sparse UBO pool is implemented, so that chunks that
don't contain any data don't have to be allocated.
The back-end Cycles code is already refactored and committed by Brecht.
Differential Revision: https://developer.blender.org/D2057
2020-08-05 19:14:40 +03:00
|
|
|
}
|
|
|
|
|
|
2022-04-14 18:47:58 +02:00
|
|
|
void GPU_material_output_thickness(GPUMaterial *material, GPUNodeLink *link)
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
{
|
2022-04-14 18:47:58 +02:00
|
|
|
if (!material->graph.outlink_thickness) {
|
|
|
|
|
material->graph.outlink_thickness = link;
|
2019-04-22 09:32:37 +10:00
|
|
|
}
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
}
|
|
|
|
|
|
2020-12-04 08:13:54 +01:00
|
|
|
void GPU_material_add_output_link_aov(GPUMaterial *material, GPUNodeLink *link, int hash)
|
|
|
|
|
{
|
|
|
|
|
GPUNodeGraphOutputLink *aov_link = MEM_callocN(sizeof(GPUNodeGraphOutputLink), __func__);
|
|
|
|
|
aov_link->outlink = link;
|
|
|
|
|
aov_link->hash = hash;
|
|
|
|
|
BLI_addtail(&material->graph.outlink_aovs, aov_link);
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-14 18:47:58 +02:00
|
|
|
char *GPU_material_split_sub_function(GPUMaterial *material,
|
|
|
|
|
eGPUType return_type,
|
|
|
|
|
GPUNodeLink **link)
|
|
|
|
|
{
|
|
|
|
|
/* Force cast to return type. */
|
|
|
|
|
switch (return_type) {
|
|
|
|
|
case GPU_FLOAT:
|
|
|
|
|
GPU_link(material, "set_value", *link, link);
|
|
|
|
|
break;
|
|
|
|
|
case GPU_VEC3:
|
|
|
|
|
GPU_link(material, "set_rgb", *link, link);
|
|
|
|
|
break;
|
|
|
|
|
case GPU_VEC4:
|
|
|
|
|
GPU_link(material, "set_rgba", *link, link);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
BLI_assert(0);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
GPUNodeGraphFunctionLink *func_link = MEM_callocN(sizeof(GPUNodeGraphFunctionLink), __func__);
|
|
|
|
|
func_link->outlink = *link;
|
|
|
|
|
SNPRINTF(func_link->name, "ntree_fn%d", material->generated_function_len++);
|
|
|
|
|
BLI_addtail(&material->graph.material_functions, func_link);
|
|
|
|
|
|
|
|
|
|
/* Set value to break the link with the main graph. */
|
|
|
|
|
switch (return_type) {
|
|
|
|
|
case GPU_FLOAT:
|
|
|
|
|
GPU_link(material, "set_value_one", link);
|
|
|
|
|
break;
|
|
|
|
|
case GPU_VEC3:
|
|
|
|
|
GPU_link(material, "set_rgb_one", link);
|
|
|
|
|
break;
|
|
|
|
|
case GPU_VEC4:
|
|
|
|
|
GPU_link(material, "set_rgba_one", link);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
BLI_assert(0);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
return func_link->name;
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-27 13:55:29 +01:00
|
|
|
GPUNodeGraph *gpu_material_node_graph(GPUMaterial *material)
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
{
|
2020-02-27 13:55:29 +01:00
|
|
|
return &material->graph;
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
}
|
|
|
|
|
|
2022-04-14 18:47:58 +02:00
|
|
|
eGPUMaterialStatus GPU_material_status(GPUMaterial *mat)
|
2019-08-23 14:36:22 +02:00
|
|
|
{
|
2022-04-14 18:47:58 +02:00
|
|
|
return mat->status;
|
2019-08-23 14:36:22 +02:00
|
|
|
}
|
|
|
|
|
|
2022-04-14 18:47:58 +02:00
|
|
|
void GPU_material_status_set(GPUMaterial *mat, eGPUMaterialStatus status)
|
2018-03-05 00:54:31 +01:00
|
|
|
{
|
2022-04-14 18:47:58 +02:00
|
|
|
mat->status = status;
|
2018-03-05 00:54:31 +01:00
|
|
|
}
|
|
|
|
|
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
/* Code generation */
|
|
|
|
|
|
2020-03-11 14:58:19 +01:00
|
|
|
bool GPU_material_has_surface_output(GPUMaterial *mat)
|
|
|
|
|
{
|
|
|
|
|
return mat->has_surface_output;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool GPU_material_has_volume_output(GPUMaterial *mat)
|
2017-10-27 16:07:44 +02:00
|
|
|
{
|
2020-03-11 14:58:19 +01:00
|
|
|
return mat->has_volume_output;
|
2017-10-27 16:07:44 +02:00
|
|
|
}
|
|
|
|
|
|
2022-04-14 18:47:58 +02:00
|
|
|
void GPU_material_flag_set(GPUMaterial *mat, eGPUMaterialFlag flag)
|
2017-10-27 16:07:44 +02:00
|
|
|
{
|
2022-04-14 18:47:58 +02:00
|
|
|
mat->flag |= flag;
|
2017-10-27 16:07:44 +02:00
|
|
|
}
|
|
|
|
|
|
2022-04-14 18:47:58 +02:00
|
|
|
bool GPU_material_flag_get(const GPUMaterial *mat, eGPUMaterialFlag flag)
|
2018-08-03 18:53:36 +02:00
|
|
|
{
|
2022-04-14 18:47:58 +02:00
|
|
|
return (mat->flag & flag) != 0;
|
2018-08-03 18:53:36 +02:00
|
|
|
}
|
|
|
|
|
|
2022-04-14 18:47:58 +02:00
|
|
|
eGPUMaterialFlag GPU_material_flag(const GPUMaterial *mat)
|
2018-08-03 18:53:36 +02:00
|
|
|
{
|
2022-04-14 18:47:58 +02:00
|
|
|
return mat->flag;
|
2018-08-03 18:53:36 +02:00
|
|
|
}
|
|
|
|
|
|
2022-04-14 18:47:58 +02:00
|
|
|
/* Note: Consumes the flags. */
|
|
|
|
|
bool GPU_material_recalc_flag_get(GPUMaterial *mat)
|
2017-04-27 22:27:09 +02:00
|
|
|
{
|
2022-04-14 18:47:58 +02:00
|
|
|
bool updated = (mat->flag & GPU_MATFLAG_UPDATED) != 0;
|
|
|
|
|
mat->flag &= ~GPU_MATFLAG_UPDATED;
|
|
|
|
|
return updated;
|
|
|
|
|
}
|
2017-04-27 22:27:09 +02:00
|
|
|
|
2022-04-14 18:47:58 +02:00
|
|
|
uint64_t GPU_material_uuid_get(GPUMaterial *mat)
|
|
|
|
|
{
|
|
|
|
|
return mat->uuid;
|
2017-06-28 10:50:33 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
GPUMaterial *GPU_material_from_nodetree(Scene *scene,
|
2022-04-14 18:47:58 +02:00
|
|
|
Material *ma,
|
|
|
|
|
bNodeTree *ntree,
|
2018-06-07 11:58:15 +02:00
|
|
|
ListBase *gpumaterials,
|
2020-07-30 13:55:13 +02:00
|
|
|
const char *name,
|
2022-04-14 18:47:58 +02:00
|
|
|
uint64_t shader_uuid,
|
|
|
|
|
bool is_volume_shader,
|
|
|
|
|
bool is_lookdev,
|
|
|
|
|
GPUCodegenCallbackFn callback,
|
|
|
|
|
void *thunk)
|
2017-06-28 10:50:33 +10:00
|
|
|
{
|
2022-04-14 18:47:58 +02:00
|
|
|
/* Search if this material is not already compiled. */
|
|
|
|
|
LISTBASE_FOREACH (LinkData *, link, gpumaterials) {
|
|
|
|
|
GPUMaterial *mat = (GPUMaterial *)link->data;
|
|
|
|
|
if (mat->uuid == shader_uuid) {
|
|
|
|
|
return mat;
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-06-02 16:58:07 +02:00
|
|
|
|
2018-09-20 14:47:10 +00:00
|
|
|
GPUMaterial *mat = MEM_callocN(sizeof(GPUMaterial), "GPUMaterial");
|
2019-05-11 14:37:27 +02:00
|
|
|
mat->ma = ma;
|
2017-05-01 18:09:50 +02:00
|
|
|
mat->scene = scene;
|
2022-04-14 18:47:58 +02:00
|
|
|
mat->uuid = shader_uuid;
|
|
|
|
|
mat->flag = GPU_MATFLAG_UPDATED;
|
2020-03-11 14:58:19 +01:00
|
|
|
mat->is_volume_shader = is_volume_shader;
|
2022-04-14 18:47:58 +02:00
|
|
|
mat->graph.used_libraries = BLI_gset_new(
|
|
|
|
|
BLI_ghashutil_ptrhash, BLI_ghashutil_ptrcmp, "GPUNodeGraph.used_libraries");
|
2018-08-02 18:31:38 +02:00
|
|
|
#ifndef NDEBUG
|
|
|
|
|
BLI_snprintf(mat->name, sizeof(mat->name), "%s", name);
|
|
|
|
|
#else
|
|
|
|
|
UNUSED_VARS(name);
|
|
|
|
|
#endif
|
2022-04-14 18:47:58 +02:00
|
|
|
if (is_lookdev) {
|
|
|
|
|
mat->flag |= GPU_MATFLAG_LOOKDEV_HACK;
|
|
|
|
|
}
|
2017-04-27 22:27:09 +02:00
|
|
|
|
2022-04-14 18:47:58 +02:00
|
|
|
/* Localize tree to create links for reroute and mute. */
|
2018-08-01 19:25:58 +02:00
|
|
|
bNodeTree *localtree = ntreeLocalize(ntree);
|
2022-04-14 18:47:58 +02:00
|
|
|
ntreeGPUMaterialNodes(localtree, mat);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-08-10 15:13:39 +02:00
|
|
|
gpu_material_ramp_texture_build(mat);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2022-04-14 18:47:58 +02:00
|
|
|
{
|
2018-06-07 11:58:15 +02:00
|
|
|
/* Create source code and search pass cache for an already compiled version. */
|
2022-04-14 18:47:58 +02:00
|
|
|
mat->pass = GPU_generate_pass(mat, &mat->graph, callback, thunk);
|
2019-05-16 16:43:41 +02:00
|
|
|
|
2018-06-07 11:58:15 +02:00
|
|
|
if (mat->pass == NULL) {
|
|
|
|
|
/* We had a cache hit and the shader has already failed to compile. */
|
|
|
|
|
mat->status = GPU_MAT_FAILED;
|
2020-02-14 10:47:20 +01:00
|
|
|
gpu_node_graph_free(&mat->graph);
|
2018-06-07 11:58:15 +02:00
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
GPUShader *sh = GPU_pass_shader_get(mat->pass);
|
|
|
|
|
if (sh != NULL) {
|
|
|
|
|
/* We had a cache hit and the shader is already compiled. */
|
|
|
|
|
mat->status = GPU_MAT_SUCCESS;
|
2020-02-14 10:47:20 +01:00
|
|
|
gpu_node_graph_free_nodes(&mat->graph);
|
2018-06-07 11:58:15 +02:00
|
|
|
}
|
|
|
|
|
else {
|
2022-04-14 18:47:58 +02:00
|
|
|
mat->status = GPU_MAT_CREATED;
|
2018-06-07 11:58:15 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2022-04-14 18:47:58 +02:00
|
|
|
/* Only free after GPU_pass_shader_get where GPUUniformBuf read data from the local tree. */
|
2018-12-14 15:20:33 +01:00
|
|
|
ntreeFreeLocalTree(localtree);
|
2021-08-11 16:56:11 +10:00
|
|
|
BLI_assert(!localtree->id.py_instance); /* Or call #BKE_libblock_free_data_py. */
|
2018-08-01 19:25:58 +02:00
|
|
|
MEM_freeN(localtree);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2022-04-14 18:47:58 +02:00
|
|
|
/* Note that even if building the shader fails in some way, we still keep
|
2018-06-07 11:58:15 +02:00
|
|
|
* it to avoid trying to compile again and again, and simply do not use
|
2022-04-14 18:47:58 +02:00
|
|
|
* the actual shader on drawing. */
|
|
|
|
|
LinkData *link = MEM_callocN(sizeof(LinkData), "GPUMaterialLink");
|
2017-04-27 22:27:09 +02:00
|
|
|
link->data = mat;
|
|
|
|
|
BLI_addtail(gpumaterials, link);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2017-04-27 22:27:09 +02:00
|
|
|
return mat;
|
|
|
|
|
}
|
2014-11-24 17:18:56 +01:00
|
|
|
|
2018-06-07 11:58:15 +02:00
|
|
|
void GPU_material_compile(GPUMaterial *mat)
|
2018-03-05 00:54:31 +01:00
|
|
|
{
|
2019-08-01 17:32:42 +10:00
|
|
|
bool success;
|
2019-06-05 13:06:11 -03:00
|
|
|
|
2018-06-07 11:58:15 +02:00
|
|
|
BLI_assert(mat->status == GPU_MAT_QUEUED);
|
|
|
|
|
BLI_assert(mat->pass);
|
|
|
|
|
|
|
|
|
|
/* NOTE: The shader may have already been compiled here since we are
|
|
|
|
|
* sharing GPUShader across GPUMaterials. In this case it's a no-op. */
|
2018-08-02 18:31:38 +02:00
|
|
|
#ifndef NDEBUG
|
2019-08-01 17:32:42 +10:00
|
|
|
success = GPU_pass_compile(mat->pass, mat->name);
|
2018-08-02 18:31:38 +02:00
|
|
|
#else
|
2019-08-01 17:32:42 +10:00
|
|
|
success = GPU_pass_compile(mat->pass, __func__);
|
2018-08-02 18:31:38 +02:00
|
|
|
#endif
|
|
|
|
|
|
2022-04-14 18:47:58 +02:00
|
|
|
mat->flag |= GPU_MATFLAG_UPDATED;
|
|
|
|
|
|
2019-08-01 17:32:42 +10:00
|
|
|
if (success) {
|
2019-06-05 13:06:11 -03:00
|
|
|
GPUShader *sh = GPU_pass_shader_get(mat->pass);
|
|
|
|
|
if (sh != NULL) {
|
|
|
|
|
mat->status = GPU_MAT_SUCCESS;
|
2020-02-14 10:47:20 +01:00
|
|
|
gpu_node_graph_free_nodes(&mat->graph);
|
2019-06-05 13:06:11 -03:00
|
|
|
}
|
2018-03-05 00:54:31 +01:00
|
|
|
}
|
2018-03-13 03:49:04 +01:00
|
|
|
else {
|
|
|
|
|
mat->status = GPU_MAT_FAILED;
|
2018-06-07 11:58:15 +02:00
|
|
|
GPU_pass_release(mat->pass);
|
|
|
|
|
mat->pass = NULL;
|
2020-02-14 10:47:20 +01:00
|
|
|
gpu_node_graph_free(&mat->graph);
|
2018-03-13 03:49:04 +01:00
|
|
|
}
|
2018-03-05 00:54:31 +01:00
|
|
|
}
|
|
|
|
|
|
2018-06-25 12:32:48 +02:00
|
|
|
void GPU_materials_free(Main *bmain)
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
{
|
2020-12-30 15:25:13 +01:00
|
|
|
LISTBASE_FOREACH (Material *, ma, &bmain->materials) {
|
2014-11-24 17:18:56 +01:00
|
|
|
GPU_material_free(&ma->gpumaterial);
|
2019-04-22 09:32:37 +10:00
|
|
|
}
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
|
2020-12-30 15:25:13 +01:00
|
|
|
LISTBASE_FOREACH (World *, wo, &bmain->worlds) {
|
2014-12-18 02:14:51 +01:00
|
|
|
GPU_material_free(&wo->gpumaterial);
|
2019-04-22 09:32:37 +10:00
|
|
|
}
|
2018-06-04 09:09:12 +02:00
|
|
|
|
2022-04-14 18:47:58 +02:00
|
|
|
// BKE_world_defaults_free_gpu();
|
2020-02-06 13:05:45 +01:00
|
|
|
BKE_material_defaults_free_gpu();
|
2011-09-09 11:55:38 +00:00
|
|
|
}
|