2011-02-23 10:52:22 +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
|
|
|
* 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
|
2011-11-29 10:54:47 +00:00
|
|
|
* of the License, or (at your option) any later version.
|
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
|
|
|
*
|
|
|
|
* 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,
|
2010-02-12 13:34:04 +00:00
|
|
|
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
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
|
|
|
*
|
|
|
|
* The Original Code is Copyright (C) 2005 Blender Foundation.
|
|
|
|
* All rights reserved.
|
|
|
|
*/
|
|
|
|
|
2019-02-18 08:08:12 +11:00
|
|
|
/** \file
|
|
|
|
* \ingroup gpu
|
2014-01-19 23:14:24 +11:00
|
|
|
*
|
|
|
|
* Convert material node-trees to GLSL.
|
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 "MEM_guardedalloc.h"
|
|
|
|
|
|
|
|
#include "DNA_customdata_types.h"
|
|
|
|
#include "DNA_image_types.h"
|
|
|
|
|
|
|
|
#include "BLI_blenlib.h"
|
2018-03-11 23:43:09 +01:00
|
|
|
#include "BLI_hash_mm2a.h"
|
2018-06-07 11:58:15 +02:00
|
|
|
#include "BLI_link_utils.h"
|
2011-01-07 18:36:47 +00:00
|
|
|
#include "BLI_utildefines.h"
|
|
|
|
#include "BLI_dynstr.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 "BLI_ghash.h"
|
2018-06-07 11:58:15 +02:00
|
|
|
#include "BLI_threads.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-11 23:43:09 +01:00
|
|
|
#include "PIL_time.h"
|
|
|
|
|
2020-02-12 12:48:44 +01:00
|
|
|
#include "BKE_material.h"
|
|
|
|
|
2015-12-06 21:20:19 +01:00
|
|
|
#include "GPU_extensions.h"
|
2015-02-16 21:19:12 +01:00
|
|
|
#include "GPU_glew.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"
|
2017-07-14 17:40:54 +02:00
|
|
|
#include "GPU_uniformbuffer.h"
|
2019-08-14 22:18:47 +02:00
|
|
|
#include "GPU_vertex_format.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
|
|
|
|
2015-03-23 15:29:42 -04:00
|
|
|
#include "BLI_sys_types.h" /* for intptr_t support */
|
2008-09-06 16:53:44 +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 "gpu_codegen.h"
|
2019-08-23 14:36:22 +02:00
|
|
|
#include "gpu_material_library.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
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
|
2019-05-31 01:45:41 +02:00
|
|
|
extern char datatoc_gpu_shader_common_obinfos_lib_glsl[];
|
|
|
|
extern char datatoc_common_view_lib_glsl[];
|
|
|
|
|
2018-03-11 23:43:09 +01:00
|
|
|
/* -------------------- GPUPass Cache ------------------ */
|
|
|
|
/**
|
|
|
|
* Internal shader cache: This prevent the shader recompilation / stall when
|
|
|
|
* using undo/redo AND also allows for GPUPass reuse if the Shader code is the
|
|
|
|
* same for 2 different Materials. Unused GPUPasses are free by Garbage collection.
|
2019-03-19 15:17:46 +11:00
|
|
|
*/
|
2018-03-11 23:43:09 +01:00
|
|
|
|
2018-06-07 11:58:15 +02:00
|
|
|
/* Only use one linklist that contains the GPUPasses grouped by hash. */
|
|
|
|
static GPUPass *pass_cache = NULL;
|
|
|
|
static SpinLock pass_cache_spin;
|
2018-03-11 23:43:09 +01:00
|
|
|
|
2019-01-29 07:46:25 +11:00
|
|
|
static uint32_t gpu_pass_hash(const char *frag_gen, const char *defs, GPUVertAttrLayers *attrs)
|
2018-03-11 23:43:09 +01:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
BLI_HashMurmur2A hm2a;
|
|
|
|
BLI_hash_mm2a_init(&hm2a, 0);
|
|
|
|
BLI_hash_mm2a_add(&hm2a, (uchar *)frag_gen, strlen(frag_gen));
|
|
|
|
if (attrs) {
|
|
|
|
for (int att_idx = 0; att_idx < attrs->totlayer; att_idx++) {
|
|
|
|
char *name = attrs->layer[att_idx].name;
|
|
|
|
BLI_hash_mm2a_add(&hm2a, (uchar *)name, strlen(name));
|
|
|
|
}
|
|
|
|
}
|
2019-04-22 09:32:37 +10:00
|
|
|
if (defs) {
|
2019-04-17 06:17:24 +02:00
|
|
|
BLI_hash_mm2a_add(&hm2a, (uchar *)defs, strlen(defs));
|
2019-04-22 09:32:37 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
return BLI_hash_mm2a_end(&hm2a);
|
2018-03-11 23:43:09 +01:00
|
|
|
}
|
|
|
|
|
2018-06-07 11:58:15 +02:00
|
|
|
/* Search by hash only. Return first pass with the same hash.
|
|
|
|
* There is hash collision if (pass->next && pass->next->hash == hash) */
|
|
|
|
static GPUPass *gpu_pass_cache_lookup(uint32_t hash)
|
2018-03-11 23:43:09 +01:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
BLI_spin_lock(&pass_cache_spin);
|
|
|
|
/* Could be optimized with a Lookup table. */
|
|
|
|
for (GPUPass *pass = pass_cache; pass; pass = pass->next) {
|
|
|
|
if (pass->hash == hash) {
|
|
|
|
BLI_spin_unlock(&pass_cache_spin);
|
|
|
|
return pass;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
BLI_spin_unlock(&pass_cache_spin);
|
|
|
|
return NULL;
|
2018-06-07 11:58:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Check all possible passes with the same hash. */
|
2019-04-17 06:17:24 +02:00
|
|
|
static GPUPass *gpu_pass_cache_resolve_collision(GPUPass *pass,
|
|
|
|
const char *vert,
|
|
|
|
const char *geom,
|
|
|
|
const char *frag,
|
|
|
|
const char *defs,
|
|
|
|
uint32_t hash)
|
2018-06-07 11:58:15 +02:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
BLI_spin_lock(&pass_cache_spin);
|
|
|
|
/* Collision, need to strcmp the whole shader. */
|
|
|
|
for (; pass && (pass->hash == hash); pass = pass->next) {
|
|
|
|
if ((defs != NULL) && (strcmp(pass->defines, defs) != 0)) { /* Pass */
|
|
|
|
}
|
|
|
|
else if ((geom != NULL) && (strcmp(pass->geometrycode, geom) != 0)) { /* Pass */
|
|
|
|
}
|
|
|
|
else if ((strcmp(pass->fragmentcode, frag) == 0) && (strcmp(pass->vertexcode, vert) == 0)) {
|
|
|
|
BLI_spin_unlock(&pass_cache_spin);
|
|
|
|
return pass;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
BLI_spin_unlock(&pass_cache_spin);
|
|
|
|
return NULL;
|
2018-03-11 23:43:09 +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
|
|
|
/* GLSL code generation */
|
|
|
|
|
2010-12-03 17:05:21 +00:00
|
|
|
static void codegen_convert_datatype(DynStr *ds, int from, int to, const char *tmp, int id)
|
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-04-17 06:17:24 +02:00
|
|
|
char name[1024];
|
|
|
|
|
|
|
|
BLI_snprintf(name, sizeof(name), "%s%d", tmp, id);
|
|
|
|
|
|
|
|
if (from == to) {
|
|
|
|
BLI_dynstr_append(ds, name);
|
|
|
|
}
|
|
|
|
else if (to == GPU_FLOAT) {
|
2019-04-22 09:32:37 +10:00
|
|
|
if (from == GPU_VEC4) {
|
GPU: Split gpu_shader_material into multiple files.
This patch continue the efforts to split the `gpu_shader_material` file
started in D5569.
Dependency resolution is now recursive. Each shading node gets its own
file. Additionally, some utility files are added to be shared between
files, like `math_util`, `color_util`, and `hash`. Some files are always
included because they may be used in the execution function, like
`world_normals`.
Some glsl functions appeared to be unused, so they were removed, like
`output_node`, `bits_to_01`, and `exp_blender`. Other functions have
been renamed to be more general and get used as utils, like `texco_norm`
which became `vector_normalize`.
A lot of the opengl tests fails, but those same tests also fail in
master, so this is probably unrelated to this patch.
Reviewers: brecht
Differential Revision: https://developer.blender.org/D5616
2019-08-30 17:23:04 +02:00
|
|
|
BLI_dynstr_appendf(ds, "dot(%s.rgb, vec3(0.2126, 0.7152, 0.0722))", name);
|
2019-04-22 09:32:37 +10:00
|
|
|
}
|
|
|
|
else if (from == GPU_VEC3) {
|
2019-04-17 06:17:24 +02:00
|
|
|
BLI_dynstr_appendf(ds, "(%s.r + %s.g + %s.b) / 3.0", name, name, name);
|
2019-04-22 09:32:37 +10:00
|
|
|
}
|
|
|
|
else if (from == GPU_VEC2) {
|
2019-04-17 06:17:24 +02:00
|
|
|
BLI_dynstr_appendf(ds, "%s.r", name);
|
2019-04-22 09:32:37 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
else if (to == GPU_VEC2) {
|
2019-04-22 09:32:37 +10:00
|
|
|
if (from == GPU_VEC4) {
|
2019-04-17 06:17:24 +02:00
|
|
|
BLI_dynstr_appendf(ds, "vec2((%s.r + %s.g + %s.b) / 3.0, %s.a)", name, name, name, name);
|
2019-04-22 09:32:37 +10:00
|
|
|
}
|
|
|
|
else if (from == GPU_VEC3) {
|
2019-04-17 06:17:24 +02:00
|
|
|
BLI_dynstr_appendf(ds, "vec2((%s.r + %s.g + %s.b) / 3.0, 1.0)", name, name, name);
|
2019-04-22 09:32:37 +10:00
|
|
|
}
|
|
|
|
else if (from == GPU_FLOAT) {
|
2019-04-17 06:17:24 +02:00
|
|
|
BLI_dynstr_appendf(ds, "vec2(%s, 1.0)", name);
|
2019-04-22 09:32:37 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
else if (to == GPU_VEC3) {
|
2019-04-22 09:32:37 +10:00
|
|
|
if (from == GPU_VEC4) {
|
2019-04-17 06:17:24 +02:00
|
|
|
BLI_dynstr_appendf(ds, "%s.rgb", name);
|
2019-04-22 09:32:37 +10:00
|
|
|
}
|
|
|
|
else if (from == GPU_VEC2) {
|
2019-04-17 06:17:24 +02:00
|
|
|
BLI_dynstr_appendf(ds, "vec3(%s.r, %s.r, %s.r)", name, name, name);
|
2019-04-22 09:32:37 +10:00
|
|
|
}
|
|
|
|
else if (from == GPU_FLOAT) {
|
2019-04-17 06:17:24 +02:00
|
|
|
BLI_dynstr_appendf(ds, "vec3(%s, %s, %s)", name, name, name);
|
2019-04-22 09:32:37 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
else if (to == GPU_VEC4) {
|
2019-04-22 09:32:37 +10:00
|
|
|
if (from == GPU_VEC3) {
|
2019-04-17 06:17:24 +02:00
|
|
|
BLI_dynstr_appendf(ds, "vec4(%s, 1.0)", name);
|
2019-04-22 09:32:37 +10:00
|
|
|
}
|
|
|
|
else if (from == GPU_VEC2) {
|
2019-04-17 06:17:24 +02:00
|
|
|
BLI_dynstr_appendf(ds, "vec4(%s.r, %s.r, %s.r, %s.g)", name, name, name, name);
|
2019-04-22 09:32:37 +10:00
|
|
|
}
|
|
|
|
else if (from == GPU_FLOAT) {
|
2019-04-17 06:17:24 +02:00
|
|
|
BLI_dynstr_appendf(ds, "vec4(%s, %s, %s, 1.0)", name, name, name);
|
2019-04-22 09:32:37 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
else if (to == GPU_CLOSURE) {
|
2019-04-22 09:32:37 +10:00
|
|
|
if (from == GPU_VEC4) {
|
2019-04-17 06:17:24 +02:00
|
|
|
BLI_dynstr_appendf(ds, "closure_emission(%s.rgb)", name);
|
2019-04-22 09:32:37 +10:00
|
|
|
}
|
|
|
|
else if (from == GPU_VEC3) {
|
2019-04-17 06:17:24 +02:00
|
|
|
BLI_dynstr_appendf(ds, "closure_emission(%s.rgb)", name);
|
2019-04-22 09:32:37 +10:00
|
|
|
}
|
|
|
|
else if (from == GPU_VEC2) {
|
2019-04-17 06:17:24 +02:00
|
|
|
BLI_dynstr_appendf(ds, "closure_emission(%s.rrr)", name);
|
2019-04-22 09:32:37 +10:00
|
|
|
}
|
|
|
|
else if (from == GPU_FLOAT) {
|
2019-04-17 06:17:24 +02:00
|
|
|
BLI_dynstr_appendf(ds, "closure_emission(vec3(%s, %s, %s))", name, name, name);
|
2019-04-22 09:32:37 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
BLI_dynstr_append(ds, name);
|
|
|
|
}
|
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-01-23 14:15:43 +11:00
|
|
|
static void codegen_print_datatype(DynStr *ds, const eGPUType type, float *data)
|
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-04-17 06:17:24 +02:00
|
|
|
int i;
|
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-12 12:48:44 +01:00
|
|
|
BLI_dynstr_appendf(ds, "%s(", gpu_data_type_to_string(type));
|
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-04-17 06:17:24 +02:00
|
|
|
for (i = 0; i < type; i++) {
|
|
|
|
BLI_dynstr_appendf(ds, "%.12f", data[i]);
|
2019-04-22 09:32:37 +10:00
|
|
|
if (i == type - 1) {
|
2019-04-17 06:17:24 +02:00
|
|
|
BLI_dynstr_append(ds, ")");
|
2019-04-22 09:32:37 +10:00
|
|
|
}
|
|
|
|
else {
|
2019-04-17 06:17:24 +02:00
|
|
|
BLI_dynstr_append(ds, ", ");
|
2019-04-22 09:32:37 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02: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
|
|
|
}
|
|
|
|
|
|
|
|
static int codegen_input_has_texture(GPUInput *input)
|
|
|
|
{
|
2019-04-22 09:32:37 +10:00
|
|
|
if (input->link) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return 0;
|
2019-04-22 09:32:37 +10:00
|
|
|
}
|
|
|
|
else {
|
2019-04-17 06:17:24 +02:00
|
|
|
return (input->source == GPU_SOURCE_TEX);
|
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-02-12 12:48:44 +01:00
|
|
|
static const char *gpu_builtin_name(eGPUBuiltin builtin)
|
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-04-22 09:32:37 +10:00
|
|
|
if (builtin == GPU_VIEW_MATRIX) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return "unfviewmat";
|
2019-04-22 09:32:37 +10:00
|
|
|
}
|
|
|
|
else if (builtin == GPU_OBJECT_MATRIX) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return "unfobmat";
|
2019-04-22 09:32:37 +10:00
|
|
|
}
|
|
|
|
else if (builtin == GPU_INVERSE_VIEW_MATRIX) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return "unfinvviewmat";
|
2019-04-22 09:32:37 +10:00
|
|
|
}
|
|
|
|
else if (builtin == GPU_INVERSE_OBJECT_MATRIX) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return "unfinvobmat";
|
2019-04-22 09:32:37 +10:00
|
|
|
}
|
|
|
|
else if (builtin == GPU_LOC_TO_VIEW_MATRIX) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return "unflocaltoviewmat";
|
2019-04-22 09:32:37 +10:00
|
|
|
}
|
|
|
|
else if (builtin == GPU_INVERSE_LOC_TO_VIEW_MATRIX) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return "unfinvlocaltoviewmat";
|
2019-04-22 09:32:37 +10:00
|
|
|
}
|
|
|
|
else if (builtin == GPU_VIEW_POSITION) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return "varposition";
|
2019-04-22 09:32:37 +10:00
|
|
|
}
|
2019-05-08 19:33:54 +02:00
|
|
|
else if (builtin == GPU_WORLD_NORMAL) {
|
|
|
|
return "varwnormal";
|
|
|
|
}
|
2019-04-22 09:32:37 +10:00
|
|
|
else if (builtin == GPU_VIEW_NORMAL) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return "varnormal";
|
2019-04-22 09:32:37 +10:00
|
|
|
}
|
2019-08-22 14:26:09 +02:00
|
|
|
else if (builtin == GPU_OBJECT_COLOR) {
|
|
|
|
return "unfobjectcolor";
|
2019-04-22 09:32:37 +10:00
|
|
|
}
|
|
|
|
else if (builtin == GPU_AUTO_BUMPSCALE) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return "unfobautobumpscale";
|
2019-04-22 09:32:37 +10:00
|
|
|
}
|
|
|
|
else if (builtin == GPU_CAMERA_TEXCO_FACTORS) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return "unfcameratexfactors";
|
2019-04-22 09:32:37 +10:00
|
|
|
}
|
|
|
|
else if (builtin == GPU_PARTICLE_SCALAR_PROPS) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return "unfparticlescalarprops";
|
2019-04-22 09:32:37 +10:00
|
|
|
}
|
|
|
|
else if (builtin == GPU_PARTICLE_LOCATION) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return "unfparticleco";
|
2019-04-22 09:32:37 +10:00
|
|
|
}
|
|
|
|
else if (builtin == GPU_PARTICLE_VELOCITY) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return "unfparticlevel";
|
2019-04-22 09:32:37 +10:00
|
|
|
}
|
|
|
|
else if (builtin == GPU_PARTICLE_ANG_VELOCITY) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return "unfparticleangvel";
|
2019-04-22 09:32:37 +10:00
|
|
|
}
|
|
|
|
else if (builtin == GPU_OBJECT_INFO) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return "unfobjectinfo";
|
2019-04-22 09:32:37 +10:00
|
|
|
}
|
|
|
|
else if (builtin == GPU_VOLUME_DENSITY) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return "sampdensity";
|
2019-04-22 09:32:37 +10:00
|
|
|
}
|
|
|
|
else if (builtin == GPU_VOLUME_FLAME) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return "sampflame";
|
2019-04-22 09:32:37 +10:00
|
|
|
}
|
|
|
|
else if (builtin == GPU_VOLUME_TEMPERATURE) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return "unftemperature";
|
2019-04-22 09:32:37 +10:00
|
|
|
}
|
|
|
|
else if (builtin == GPU_BARYCENTRIC_TEXCO) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return "unfbarycentrictex";
|
2019-04-22 09:32:37 +10:00
|
|
|
}
|
|
|
|
else if (builtin == GPU_BARYCENTRIC_DIST) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return "unfbarycentricdist";
|
2019-04-22 09:32:37 +10:00
|
|
|
}
|
|
|
|
else {
|
2019-04-17 06:17:24 +02:00
|
|
|
return "";
|
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
|
|
|
}
|
|
|
|
|
2015-01-24 17:07:38 +01:00
|
|
|
/* assign only one texid per buffer to avoid sampling the same texture twice */
|
Add support for tiled images and the UDIM naming scheme
This patch contains the work that I did during my week at the Code Quest - adding support for tiled images to Blender.
With this patch, images now contain a list of tiles. By default, this just contains one tile, but if the source type is set to Tiled, the user can add additional tiles. When acquiring an ImBuf, the tile to be loaded is specified in the ImageUser.
Therefore, code that is not yet aware of tiles will just access the default tile as usual.
The filenames of the additional tiles are derived from the original filename according to the UDIM naming scheme - the filename contains an index that is calculated as (1001 + 10*<y coordinate of the tile> + <x coordinate of the tile>), where the x coordinate never goes above 9.
Internally, the various tiles are stored in a cache just like sequences. When acquired for the first time, the code will try to load the corresponding file from disk. Alternatively, a new operator can be used to initialize the tile similar to the New Image operator.
The following features are supported so far:
- Automatic detection and loading of all tiles when opening the first tile (1001)
- Saving all tiles
- Adding and removing tiles
- Filling tiles with generated images
- Drawing all tiles in the Image Editor
- Viewing a tiled grid even if no image is selected
- Rendering tiled images in Eevee
- Rendering tiled images in Cycles (in SVM mode)
- Automatically skipping loading of unused tiles in Cycles
- 2D texture painting (also across tiles)
- 3D texture painting (also across tiles, only limitation: individual faces can not cross tile borders)
- Assigning custom labels to individual tiles (drawn in the Image Editor instead of the ID)
- Different resolutions between tiles
There still are some missing features that will be added later (see T72390):
- Workbench engine support
- Packing/Unpacking support
- Baking support
- Cycles OSL support
- many other Blender features that rely on images
Thanks to Brecht for the review and to all who tested the intermediate versions!
Differential Revision: https://developer.blender.org/D3509
2019-12-12 16:06:08 +01:00
|
|
|
static void codegen_set_texid(GHash *bindhash, GPUInput *input, int *texid, void *key1, int key2)
|
2015-01-24 17:07:38 +01:00
|
|
|
{
|
Add support for tiled images and the UDIM naming scheme
This patch contains the work that I did during my week at the Code Quest - adding support for tiled images to Blender.
With this patch, images now contain a list of tiles. By default, this just contains one tile, but if the source type is set to Tiled, the user can add additional tiles. When acquiring an ImBuf, the tile to be loaded is specified in the ImageUser.
Therefore, code that is not yet aware of tiles will just access the default tile as usual.
The filenames of the additional tiles are derived from the original filename according to the UDIM naming scheme - the filename contains an index that is calculated as (1001 + 10*<y coordinate of the tile> + <x coordinate of the tile>), where the x coordinate never goes above 9.
Internally, the various tiles are stored in a cache just like sequences. When acquired for the first time, the code will try to load the corresponding file from disk. Alternatively, a new operator can be used to initialize the tile similar to the New Image operator.
The following features are supported so far:
- Automatic detection and loading of all tiles when opening the first tile (1001)
- Saving all tiles
- Adding and removing tiles
- Filling tiles with generated images
- Drawing all tiles in the Image Editor
- Viewing a tiled grid even if no image is selected
- Rendering tiled images in Eevee
- Rendering tiled images in Cycles (in SVM mode)
- Automatically skipping loading of unused tiles in Cycles
- 2D texture painting (also across tiles)
- 3D texture painting (also across tiles, only limitation: individual faces can not cross tile borders)
- Assigning custom labels to individual tiles (drawn in the Image Editor instead of the ID)
- Different resolutions between tiles
There still are some missing features that will be added later (see T72390):
- Workbench engine support
- Packing/Unpacking support
- Baking support
- Cycles OSL support
- many other Blender features that rely on images
Thanks to Brecht for the review and to all who tested the intermediate versions!
Differential Revision: https://developer.blender.org/D3509
2019-12-12 16:06:08 +01:00
|
|
|
GHashPair pair = {key1, POINTER_FROM_INT(key2)};
|
|
|
|
if (BLI_ghash_haskey(bindhash, &pair)) {
|
2019-04-17 06:17:24 +02:00
|
|
|
/* Reuse existing texid */
|
Add support for tiled images and the UDIM naming scheme
This patch contains the work that I did during my week at the Code Quest - adding support for tiled images to Blender.
With this patch, images now contain a list of tiles. By default, this just contains one tile, but if the source type is set to Tiled, the user can add additional tiles. When acquiring an ImBuf, the tile to be loaded is specified in the ImageUser.
Therefore, code that is not yet aware of tiles will just access the default tile as usual.
The filenames of the additional tiles are derived from the original filename according to the UDIM naming scheme - the filename contains an index that is calculated as (1001 + 10*<y coordinate of the tile> + <x coordinate of the tile>), where the x coordinate never goes above 9.
Internally, the various tiles are stored in a cache just like sequences. When acquired for the first time, the code will try to load the corresponding file from disk. Alternatively, a new operator can be used to initialize the tile similar to the New Image operator.
The following features are supported so far:
- Automatic detection and loading of all tiles when opening the first tile (1001)
- Saving all tiles
- Adding and removing tiles
- Filling tiles with generated images
- Drawing all tiles in the Image Editor
- Viewing a tiled grid even if no image is selected
- Rendering tiled images in Eevee
- Rendering tiled images in Cycles (in SVM mode)
- Automatically skipping loading of unused tiles in Cycles
- 2D texture painting (also across tiles)
- 3D texture painting (also across tiles, only limitation: individual faces can not cross tile borders)
- Assigning custom labels to individual tiles (drawn in the Image Editor instead of the ID)
- Different resolutions between tiles
There still are some missing features that will be added later (see T72390):
- Workbench engine support
- Packing/Unpacking support
- Baking support
- Cycles OSL support
- many other Blender features that rely on images
Thanks to Brecht for the review and to all who tested the intermediate versions!
Differential Revision: https://developer.blender.org/D3509
2019-12-12 16:06:08 +01:00
|
|
|
input->texid = POINTER_AS_INT(BLI_ghash_lookup(bindhash, &pair));
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* Allocate new texid */
|
|
|
|
input->texid = *texid;
|
|
|
|
(*texid)++;
|
|
|
|
input->bindtex = true;
|
Add support for tiled images and the UDIM naming scheme
This patch contains the work that I did during my week at the Code Quest - adding support for tiled images to Blender.
With this patch, images now contain a list of tiles. By default, this just contains one tile, but if the source type is set to Tiled, the user can add additional tiles. When acquiring an ImBuf, the tile to be loaded is specified in the ImageUser.
Therefore, code that is not yet aware of tiles will just access the default tile as usual.
The filenames of the additional tiles are derived from the original filename according to the UDIM naming scheme - the filename contains an index that is calculated as (1001 + 10*<y coordinate of the tile> + <x coordinate of the tile>), where the x coordinate never goes above 9.
Internally, the various tiles are stored in a cache just like sequences. When acquired for the first time, the code will try to load the corresponding file from disk. Alternatively, a new operator can be used to initialize the tile similar to the New Image operator.
The following features are supported so far:
- Automatic detection and loading of all tiles when opening the first tile (1001)
- Saving all tiles
- Adding and removing tiles
- Filling tiles with generated images
- Drawing all tiles in the Image Editor
- Viewing a tiled grid even if no image is selected
- Rendering tiled images in Eevee
- Rendering tiled images in Cycles (in SVM mode)
- Automatically skipping loading of unused tiles in Cycles
- 2D texture painting (also across tiles)
- 3D texture painting (also across tiles, only limitation: individual faces can not cross tile borders)
- Assigning custom labels to individual tiles (drawn in the Image Editor instead of the ID)
- Different resolutions between tiles
There still are some missing features that will be added later (see T72390):
- Workbench engine support
- Packing/Unpacking support
- Baking support
- Cycles OSL support
- many other Blender features that rely on images
Thanks to Brecht for the review and to all who tested the intermediate versions!
Differential Revision: https://developer.blender.org/D3509
2019-12-12 16:06:08 +01:00
|
|
|
void *key = BLI_ghashutil_pairalloc(key1, POINTER_FROM_INT(key2));
|
2019-04-17 06:17:24 +02:00
|
|
|
BLI_ghash_insert(bindhash, key, POINTER_FROM_INT(input->texid));
|
|
|
|
}
|
2015-01-24 17:07:38 +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
|
|
|
static void codegen_set_unique_ids(ListBase *nodes)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
GHash *bindhash;
|
|
|
|
GPUNode *node;
|
|
|
|
GPUInput *input;
|
|
|
|
GPUOutput *output;
|
|
|
|
int id = 1, texid = 0;
|
|
|
|
|
Add support for tiled images and the UDIM naming scheme
This patch contains the work that I did during my week at the Code Quest - adding support for tiled images to Blender.
With this patch, images now contain a list of tiles. By default, this just contains one tile, but if the source type is set to Tiled, the user can add additional tiles. When acquiring an ImBuf, the tile to be loaded is specified in the ImageUser.
Therefore, code that is not yet aware of tiles will just access the default tile as usual.
The filenames of the additional tiles are derived from the original filename according to the UDIM naming scheme - the filename contains an index that is calculated as (1001 + 10*<y coordinate of the tile> + <x coordinate of the tile>), where the x coordinate never goes above 9.
Internally, the various tiles are stored in a cache just like sequences. When acquired for the first time, the code will try to load the corresponding file from disk. Alternatively, a new operator can be used to initialize the tile similar to the New Image operator.
The following features are supported so far:
- Automatic detection and loading of all tiles when opening the first tile (1001)
- Saving all tiles
- Adding and removing tiles
- Filling tiles with generated images
- Drawing all tiles in the Image Editor
- Viewing a tiled grid even if no image is selected
- Rendering tiled images in Eevee
- Rendering tiled images in Cycles (in SVM mode)
- Automatically skipping loading of unused tiles in Cycles
- 2D texture painting (also across tiles)
- 3D texture painting (also across tiles, only limitation: individual faces can not cross tile borders)
- Assigning custom labels to individual tiles (drawn in the Image Editor instead of the ID)
- Different resolutions between tiles
There still are some missing features that will be added later (see T72390):
- Workbench engine support
- Packing/Unpacking support
- Baking support
- Cycles OSL support
- many other Blender features that rely on images
Thanks to Brecht for the review and to all who tested the intermediate versions!
Differential Revision: https://developer.blender.org/D3509
2019-12-12 16:06:08 +01:00
|
|
|
bindhash = BLI_ghash_pair_new("codegen_set_unique_ids1 gh");
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
for (node = nodes->first; node; node = node->next) {
|
|
|
|
for (input = node->inputs.first; input; input = input->next) {
|
|
|
|
/* set id for unique names of uniform variables */
|
|
|
|
input->id = id++;
|
|
|
|
|
|
|
|
/* set texid used for settings texture slot */
|
|
|
|
if (codegen_input_has_texture(input)) {
|
|
|
|
input->bindtex = false;
|
|
|
|
if (input->ima) {
|
|
|
|
/* input is texture from image */
|
Fix T73133: UDIM texture count in Eevee is limited by OpenGL
Based on @fclem's suggestion in D6421, this commit implements support for
storing all tiles of a UDIM texture in a single 2D array texture on the GPU.
Previously, Eevee was binding one OpenGL texture per tile, quickly running
into hardware limits with nontrivial UDIM texture sets.
Workbench meanwhile had no UDIM support at all, as reusing the per-tile
approach would require splitting the mesh by tile as well as texture.
With this commit, both Workbench as well as Eevee now support huge numbers
of tiles, with the eventual limits being GPU memory and ultimately
GL_MAX_ARRAY_TEXTURE_LAYERS, which tends to be in the 1000s on modern GPUs.
Initially my plan was to have one array texture per unique size, but managing
the different textures and keeping everything consistent ended up being way
too complex.
Therefore, we now use a simpler version that allocates a texture that
is large enough to fit the largest tile and then packs all tiles into as many
layers as necessary.
As a result, each UDIM texture only binds two textures (one for the actual
images, one for metadata) regardless of how many tiles are used.
Note that this rolls back per-tile GPUTextures, meaning that we again have
per-Image GPUTextures like we did before the original UDIM commit,
but now with four instead of two types.
Reviewed By: fclem
Differential Revision: https://developer.blender.org/D6456
2020-01-14 00:33:21 +01:00
|
|
|
codegen_set_texid(bindhash, input, &texid, input->ima, input->type);
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
else if (input->coba) {
|
|
|
|
/* input is color band texture, check coba pointer */
|
Add support for tiled images and the UDIM naming scheme
This patch contains the work that I did during my week at the Code Quest - adding support for tiled images to Blender.
With this patch, images now contain a list of tiles. By default, this just contains one tile, but if the source type is set to Tiled, the user can add additional tiles. When acquiring an ImBuf, the tile to be loaded is specified in the ImageUser.
Therefore, code that is not yet aware of tiles will just access the default tile as usual.
The filenames of the additional tiles are derived from the original filename according to the UDIM naming scheme - the filename contains an index that is calculated as (1001 + 10*<y coordinate of the tile> + <x coordinate of the tile>), where the x coordinate never goes above 9.
Internally, the various tiles are stored in a cache just like sequences. When acquired for the first time, the code will try to load the corresponding file from disk. Alternatively, a new operator can be used to initialize the tile similar to the New Image operator.
The following features are supported so far:
- Automatic detection and loading of all tiles when opening the first tile (1001)
- Saving all tiles
- Adding and removing tiles
- Filling tiles with generated images
- Drawing all tiles in the Image Editor
- Viewing a tiled grid even if no image is selected
- Rendering tiled images in Eevee
- Rendering tiled images in Cycles (in SVM mode)
- Automatically skipping loading of unused tiles in Cycles
- 2D texture painting (also across tiles)
- 3D texture painting (also across tiles, only limitation: individual faces can not cross tile borders)
- Assigning custom labels to individual tiles (drawn in the Image Editor instead of the ID)
- Different resolutions between tiles
There still are some missing features that will be added later (see T72390):
- Workbench engine support
- Packing/Unpacking support
- Baking support
- Cycles OSL support
- many other Blender features that rely on images
Thanks to Brecht for the review and to all who tested the intermediate versions!
Differential Revision: https://developer.blender.org/D3509
2019-12-12 16:06:08 +01:00
|
|
|
codegen_set_texid(bindhash, input, &texid, input->coba, 0);
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* Either input->ima or input->coba should be non-NULL. */
|
|
|
|
BLI_assert(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (output = node->outputs.first; output; output = output->next) {
|
|
|
|
/* set id for unique names of tmp variables storing output */
|
|
|
|
output->id = id++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Add support for tiled images and the UDIM naming scheme
This patch contains the work that I did during my week at the Code Quest - adding support for tiled images to Blender.
With this patch, images now contain a list of tiles. By default, this just contains one tile, but if the source type is set to Tiled, the user can add additional tiles. When acquiring an ImBuf, the tile to be loaded is specified in the ImageUser.
Therefore, code that is not yet aware of tiles will just access the default tile as usual.
The filenames of the additional tiles are derived from the original filename according to the UDIM naming scheme - the filename contains an index that is calculated as (1001 + 10*<y coordinate of the tile> + <x coordinate of the tile>), where the x coordinate never goes above 9.
Internally, the various tiles are stored in a cache just like sequences. When acquired for the first time, the code will try to load the corresponding file from disk. Alternatively, a new operator can be used to initialize the tile similar to the New Image operator.
The following features are supported so far:
- Automatic detection and loading of all tiles when opening the first tile (1001)
- Saving all tiles
- Adding and removing tiles
- Filling tiles with generated images
- Drawing all tiles in the Image Editor
- Viewing a tiled grid even if no image is selected
- Rendering tiled images in Eevee
- Rendering tiled images in Cycles (in SVM mode)
- Automatically skipping loading of unused tiles in Cycles
- 2D texture painting (also across tiles)
- 3D texture painting (also across tiles, only limitation: individual faces can not cross tile borders)
- Assigning custom labels to individual tiles (drawn in the Image Editor instead of the ID)
- Different resolutions between tiles
There still are some missing features that will be added later (see T72390):
- Workbench engine support
- Packing/Unpacking support
- Baking support
- Cycles OSL support
- many other Blender features that rely on images
Thanks to Brecht for the review and to all who tested the intermediate versions!
Differential Revision: https://developer.blender.org/D3509
2019-12-12 16:06:08 +01:00
|
|
|
BLI_ghash_free(bindhash, BLI_ghashutil_pairfree, NULL);
|
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
|
|
|
}
|
|
|
|
|
2017-07-14 17:40:54 +02:00
|
|
|
/**
|
|
|
|
* It will create an UBO for GPUMaterial if there is any GPU_DYNAMIC_UBO.
|
|
|
|
*/
|
|
|
|
static int codegen_process_uniforms_functions(GPUMaterial *material, DynStr *ds, ListBase *nodes)
|
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-04-17 06:17:24 +02:00
|
|
|
GPUNode *node;
|
|
|
|
GPUInput *input;
|
|
|
|
const char *name;
|
|
|
|
int builtins = 0;
|
|
|
|
ListBase ubo_inputs = {NULL, NULL};
|
|
|
|
|
|
|
|
/* print uniforms */
|
|
|
|
for (node = nodes->first; node; node = node->next) {
|
|
|
|
for (input = node->inputs.first; input; input = input->next) {
|
|
|
|
if (input->source == GPU_SOURCE_TEX) {
|
|
|
|
/* create exactly one sampler for each texture */
|
|
|
|
if (codegen_input_has_texture(input) && input->bindtex) {
|
Fix T73133: UDIM texture count in Eevee is limited by OpenGL
Based on @fclem's suggestion in D6421, this commit implements support for
storing all tiles of a UDIM texture in a single 2D array texture on the GPU.
Previously, Eevee was binding one OpenGL texture per tile, quickly running
into hardware limits with nontrivial UDIM texture sets.
Workbench meanwhile had no UDIM support at all, as reusing the per-tile
approach would require splitting the mesh by tile as well as texture.
With this commit, both Workbench as well as Eevee now support huge numbers
of tiles, with the eventual limits being GPU memory and ultimately
GL_MAX_ARRAY_TEXTURE_LAYERS, which tends to be in the 1000s on modern GPUs.
Initially my plan was to have one array texture per unique size, but managing
the different textures and keeping everything consistent ended up being way
too complex.
Therefore, we now use a simpler version that allocates a texture that
is large enough to fit the largest tile and then packs all tiles into as many
layers as necessary.
As a result, each UDIM texture only binds two textures (one for the actual
images, one for metadata) regardless of how many tiles are used.
Note that this rolls back per-tile GPUTextures, meaning that we again have
per-Image GPUTextures like we did before the original UDIM commit,
but now with four instead of two types.
Reviewed By: fclem
Differential Revision: https://developer.blender.org/D6456
2020-01-14 00:33:21 +01:00
|
|
|
const char *type;
|
|
|
|
if (input->coba || input->type == GPU_TEX1D_ARRAY) {
|
|
|
|
type = "sampler1DArray";
|
|
|
|
}
|
|
|
|
else if (input->type == GPU_TEX2D_ARRAY) {
|
|
|
|
type = "sampler2DArray";
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
BLI_assert(input->type == GPU_TEX2D);
|
|
|
|
type = "sampler2D";
|
|
|
|
}
|
|
|
|
BLI_dynstr_appendf(ds, "uniform %s samp%d;\n", type, input->texid);
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (input->source == GPU_SOURCE_BUILTIN) {
|
|
|
|
/* only define each builtin uniform/varying once */
|
|
|
|
if (!(builtins & input->builtin)) {
|
|
|
|
builtins |= input->builtin;
|
2020-02-12 12:48:44 +01:00
|
|
|
name = gpu_builtin_name(input->builtin);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-02-12 12:48:44 +01:00
|
|
|
if (BLI_str_startswith(name, "samp")) {
|
2019-04-17 06:17:24 +02:00
|
|
|
if ((input->builtin == GPU_VOLUME_DENSITY) || (input->builtin == GPU_VOLUME_FLAME)) {
|
|
|
|
BLI_dynstr_appendf(ds, "uniform sampler3D %s;\n", name);
|
|
|
|
}
|
|
|
|
}
|
2020-02-12 12:48:44 +01:00
|
|
|
else if (BLI_str_startswith(name, "unf")) {
|
|
|
|
BLI_dynstr_appendf(ds, "uniform %s %s;\n", gpu_data_type_to_string(input->type), name);
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
else {
|
2020-02-12 12:48:44 +01:00
|
|
|
BLI_dynstr_appendf(ds, "in %s %s;\n", gpu_data_type_to_string(input->type), name);
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (input->source == GPU_SOURCE_STRUCT) {
|
|
|
|
/* Add other struct here if needed. */
|
|
|
|
BLI_dynstr_appendf(ds, "Closure strct%d = CLOSURE_DEFAULT;\n", input->id);
|
|
|
|
}
|
|
|
|
else if (input->source == GPU_SOURCE_UNIFORM) {
|
|
|
|
if (!input->link) {
|
|
|
|
/* We handle the UBOuniforms separately. */
|
|
|
|
BLI_addtail(&ubo_inputs, BLI_genericNodeN(input));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (input->source == GPU_SOURCE_CONSTANT) {
|
2020-02-12 12:48:44 +01:00
|
|
|
BLI_dynstr_appendf(
|
|
|
|
ds, "const %s cons%d = ", gpu_data_type_to_string(input->type), input->id);
|
2019-04-17 06:17:24 +02:00
|
|
|
codegen_print_datatype(ds, input->type, input->vec);
|
|
|
|
BLI_dynstr_append(ds, ";\n");
|
|
|
|
}
|
|
|
|
else if (input->source == GPU_SOURCE_ATTR && input->attr_first) {
|
2020-02-12 12:48:44 +01:00
|
|
|
BLI_dynstr_appendf(
|
|
|
|
ds, "in %s var%d;\n", gpu_data_type_to_string(input->type), input->attr_id);
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Handle the UBO block separately. */
|
|
|
|
if ((material != NULL) && !BLI_listbase_is_empty(&ubo_inputs)) {
|
|
|
|
GPU_material_uniform_buffer_create(material, &ubo_inputs);
|
|
|
|
|
|
|
|
/* Inputs are sorted */
|
|
|
|
BLI_dynstr_appendf(ds, "\nlayout (std140) uniform %s {\n", GPU_UBO_BLOCK_NAME);
|
|
|
|
|
|
|
|
for (LinkData *link = ubo_inputs.first; link; link = link->next) {
|
|
|
|
input = link->data;
|
2020-02-12 12:48:44 +01:00
|
|
|
BLI_dynstr_appendf(ds, "\t%s unf%d;\n", gpu_data_type_to_string(input->type), input->id);
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
BLI_dynstr_append(ds, "};\n");
|
|
|
|
BLI_freelistN(&ubo_inputs);
|
|
|
|
}
|
|
|
|
|
|
|
|
BLI_dynstr_append(ds, "\n");
|
|
|
|
|
|
|
|
return builtins;
|
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
|
|
|
}
|
|
|
|
|
|
|
|
static void codegen_declare_tmps(DynStr *ds, ListBase *nodes)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
GPUNode *node;
|
|
|
|
GPUOutput *output;
|
|
|
|
|
|
|
|
for (node = nodes->first; node; node = node->next) {
|
|
|
|
/* declare temporary variables for node output storage */
|
|
|
|
for (output = node->outputs.first; output; output = output->next) {
|
|
|
|
if (output->type == GPU_CLOSURE) {
|
|
|
|
BLI_dynstr_appendf(ds, "\tClosure tmp%d;\n", output->id);
|
|
|
|
}
|
|
|
|
else {
|
2020-02-12 12:48:44 +01:00
|
|
|
BLI_dynstr_appendf(ds, "\t%s tmp%d;\n", gpu_data_type_to_string(output->type), output->id);
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
BLI_dynstr_append(ds, "\n");
|
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
|
|
|
}
|
|
|
|
|
|
|
|
static void codegen_call_functions(DynStr *ds, ListBase *nodes, GPUOutput *finaloutput)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
GPUNode *node;
|
|
|
|
GPUInput *input;
|
|
|
|
GPUOutput *output;
|
|
|
|
|
|
|
|
for (node = nodes->first; node; node = node->next) {
|
|
|
|
BLI_dynstr_appendf(ds, "\t%s(", node->name);
|
|
|
|
|
|
|
|
for (input = node->inputs.first; input; input = input->next) {
|
|
|
|
if (input->source == GPU_SOURCE_TEX) {
|
|
|
|
BLI_dynstr_appendf(ds, "samp%d", input->texid);
|
|
|
|
}
|
|
|
|
else if (input->source == GPU_SOURCE_OUTPUT) {
|
|
|
|
codegen_convert_datatype(
|
|
|
|
ds, input->link->output->type, input->type, "tmp", input->link->output->id);
|
|
|
|
}
|
|
|
|
else if (input->source == GPU_SOURCE_BUILTIN) {
|
|
|
|
/* TODO(fclem) get rid of that. */
|
2019-04-22 09:32:37 +10:00
|
|
|
if (input->builtin == GPU_INVERSE_VIEW_MATRIX) {
|
2019-04-17 06:17:24 +02:00
|
|
|
BLI_dynstr_append(ds, "viewinv");
|
2019-04-22 09:32:37 +10:00
|
|
|
}
|
|
|
|
else if (input->builtin == GPU_VIEW_MATRIX) {
|
2019-04-17 06:17:24 +02:00
|
|
|
BLI_dynstr_append(ds, "viewmat");
|
2019-04-22 09:32:37 +10:00
|
|
|
}
|
|
|
|
else if (input->builtin == GPU_CAMERA_TEXCO_FACTORS) {
|
2019-04-17 06:17:24 +02:00
|
|
|
BLI_dynstr_append(ds, "camtexfac");
|
2019-04-22 09:32:37 +10:00
|
|
|
}
|
|
|
|
else if (input->builtin == GPU_LOC_TO_VIEW_MATRIX) {
|
2019-04-17 06:17:24 +02:00
|
|
|
BLI_dynstr_append(ds, "localtoviewmat");
|
2019-04-22 09:32:37 +10:00
|
|
|
}
|
|
|
|
else if (input->builtin == GPU_INVERSE_LOC_TO_VIEW_MATRIX) {
|
2019-04-17 06:17:24 +02:00
|
|
|
BLI_dynstr_append(ds, "invlocaltoviewmat");
|
2019-04-22 09:32:37 +10:00
|
|
|
}
|
|
|
|
else if (input->builtin == GPU_BARYCENTRIC_DIST) {
|
2019-04-17 06:17:24 +02:00
|
|
|
BLI_dynstr_append(ds, "barycentricDist");
|
2019-04-22 09:32:37 +10:00
|
|
|
}
|
|
|
|
else if (input->builtin == GPU_BARYCENTRIC_TEXCO) {
|
2019-04-17 06:17:24 +02:00
|
|
|
BLI_dynstr_append(ds, "barytexco");
|
2019-04-22 09:32:37 +10:00
|
|
|
}
|
|
|
|
else if (input->builtin == GPU_OBJECT_MATRIX) {
|
2019-04-17 06:17:24 +02:00
|
|
|
BLI_dynstr_append(ds, "objmat");
|
2019-04-22 09:32:37 +10:00
|
|
|
}
|
2019-05-31 01:45:41 +02:00
|
|
|
else if (input->builtin == GPU_OBJECT_INFO) {
|
|
|
|
BLI_dynstr_append(ds, "ObjectInfo");
|
|
|
|
}
|
|
|
|
else if (input->builtin == GPU_OBJECT_COLOR) {
|
|
|
|
BLI_dynstr_append(ds, "ObjectColor");
|
|
|
|
}
|
2019-04-22 09:32:37 +10:00
|
|
|
else if (input->builtin == GPU_INVERSE_OBJECT_MATRIX) {
|
2019-04-17 06:17:24 +02:00
|
|
|
BLI_dynstr_append(ds, "objinv");
|
2019-04-22 09:32:37 +10:00
|
|
|
}
|
|
|
|
else if (input->builtin == GPU_VIEW_POSITION) {
|
2019-04-17 06:17:24 +02:00
|
|
|
BLI_dynstr_append(ds, "viewposition");
|
2019-04-22 09:32:37 +10:00
|
|
|
}
|
|
|
|
else if (input->builtin == GPU_VIEW_NORMAL) {
|
2019-04-17 06:17:24 +02:00
|
|
|
BLI_dynstr_append(ds, "facingnormal");
|
2019-04-22 09:32:37 +10:00
|
|
|
}
|
2019-05-08 19:33:54 +02:00
|
|
|
else if (input->builtin == GPU_WORLD_NORMAL) {
|
|
|
|
BLI_dynstr_append(ds, "facingwnormal");
|
|
|
|
}
|
2019-04-22 09:32:37 +10:00
|
|
|
else {
|
2020-02-12 12:48:44 +01:00
|
|
|
BLI_dynstr_append(ds, gpu_builtin_name(input->builtin));
|
2019-04-22 09:32:37 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
else if (input->source == GPU_SOURCE_STRUCT) {
|
|
|
|
BLI_dynstr_appendf(ds, "strct%d", input->id);
|
|
|
|
}
|
|
|
|
else if (input->source == GPU_SOURCE_UNIFORM) {
|
|
|
|
BLI_dynstr_appendf(ds, "unf%d", input->id);
|
|
|
|
}
|
|
|
|
else if (input->source == GPU_SOURCE_CONSTANT) {
|
|
|
|
BLI_dynstr_appendf(ds, "cons%d", input->id);
|
|
|
|
}
|
|
|
|
else if (input->source == GPU_SOURCE_ATTR) {
|
|
|
|
BLI_dynstr_appendf(ds, "var%d", input->attr_id);
|
|
|
|
}
|
|
|
|
|
|
|
|
BLI_dynstr_append(ds, ", ");
|
|
|
|
}
|
|
|
|
|
|
|
|
for (output = node->outputs.first; output; output = output->next) {
|
|
|
|
BLI_dynstr_appendf(ds, "tmp%d", output->id);
|
2019-04-22 09:32:37 +10:00
|
|
|
if (output->next) {
|
2019-04-17 06:17:24 +02:00
|
|
|
BLI_dynstr_append(ds, ", ");
|
2019-04-22 09:32:37 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
BLI_dynstr_append(ds, ");\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
BLI_dynstr_appendf(ds, "\n\treturn tmp%d", finaloutput->id);
|
|
|
|
BLI_dynstr_append(ds, ";\n");
|
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-04-17 06:17:24 +02:00
|
|
|
static char *code_generate_fragment(GPUMaterial *material,
|
|
|
|
ListBase *nodes,
|
|
|
|
GPUOutput *output,
|
|
|
|
int *rbuiltins)
|
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-04-17 06:17:24 +02:00
|
|
|
DynStr *ds = BLI_dynstr_new();
|
|
|
|
char *code;
|
|
|
|
int builtins;
|
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
|
|
|
|
2015-03-23 15:29:42 -04:00
|
|
|
#if 0
|
2019-04-17 06:17:24 +02:00
|
|
|
BLI_dynstr_append(ds, FUNCTION_PROTOTYPES);
|
2015-03-23 15:29:42 -04:00
|
|
|
#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
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
codegen_set_unique_ids(nodes);
|
|
|
|
*rbuiltins = builtins = codegen_process_uniforms_functions(material, ds, nodes);
|
|
|
|
|
2019-05-31 01:45:41 +02:00
|
|
|
if (builtins & (GPU_OBJECT_INFO | GPU_OBJECT_COLOR)) {
|
|
|
|
BLI_dynstr_append(ds, datatoc_gpu_shader_common_obinfos_lib_glsl);
|
|
|
|
}
|
|
|
|
|
2019-04-22 09:32:37 +10:00
|
|
|
if (builtins & GPU_BARYCENTRIC_TEXCO) {
|
2019-04-17 06:17:24 +02:00
|
|
|
BLI_dynstr_append(ds, "in vec2 barycentricTexCo;\n");
|
2019-04-22 09:32:37 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-04-22 09:32:37 +10:00
|
|
|
if (builtins & GPU_BARYCENTRIC_DIST) {
|
2019-04-17 06:17:24 +02:00
|
|
|
BLI_dynstr_append(ds, "flat in vec3 barycentricDist;\n");
|
2019-04-22 09:32:37 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
BLI_dynstr_append(ds, "Closure nodetree_exec(void)\n{\n");
|
|
|
|
|
|
|
|
if (builtins & GPU_BARYCENTRIC_TEXCO) {
|
|
|
|
BLI_dynstr_append(ds, "#ifdef HAIR_SHADER\n");
|
|
|
|
BLI_dynstr_append(ds,
|
|
|
|
"\tvec2 barytexco = vec2((fract(barycentricTexCo.y) != 0.0)\n"
|
|
|
|
"\t ? barycentricTexCo.x\n"
|
|
|
|
"\t : 1.0 - barycentricTexCo.x,\n"
|
|
|
|
"\t 0.0);\n");
|
|
|
|
BLI_dynstr_append(ds, "#else\n");
|
|
|
|
BLI_dynstr_append(ds, "\tvec2 barytexco = barycentricTexCo;\n");
|
|
|
|
BLI_dynstr_append(ds, "#endif\n");
|
|
|
|
}
|
|
|
|
/* TODO(fclem) get rid of that. */
|
2019-04-22 09:32:37 +10:00
|
|
|
if (builtins & GPU_VIEW_MATRIX) {
|
2019-04-17 06:17:24 +02:00
|
|
|
BLI_dynstr_append(ds, "\t#define viewmat ViewMatrix\n");
|
2019-04-22 09:32:37 +10:00
|
|
|
}
|
|
|
|
if (builtins & GPU_CAMERA_TEXCO_FACTORS) {
|
2019-04-17 06:17:24 +02:00
|
|
|
BLI_dynstr_append(ds, "\t#define camtexfac CameraTexCoFactors\n");
|
2019-04-22 09:32:37 +10:00
|
|
|
}
|
|
|
|
if (builtins & GPU_OBJECT_MATRIX) {
|
2019-04-17 06:17:24 +02:00
|
|
|
BLI_dynstr_append(ds, "\t#define objmat ModelMatrix\n");
|
2019-04-22 09:32:37 +10:00
|
|
|
}
|
|
|
|
if (builtins & GPU_INVERSE_OBJECT_MATRIX) {
|
2019-04-17 06:17:24 +02:00
|
|
|
BLI_dynstr_append(ds, "\t#define objinv ModelMatrixInverse\n");
|
2019-04-22 09:32:37 +10:00
|
|
|
}
|
|
|
|
if (builtins & GPU_INVERSE_VIEW_MATRIX) {
|
2019-04-17 06:17:24 +02:00
|
|
|
BLI_dynstr_append(ds, "\t#define viewinv ViewMatrixInverse\n");
|
2019-04-22 09:32:37 +10:00
|
|
|
}
|
|
|
|
if (builtins & GPU_LOC_TO_VIEW_MATRIX) {
|
2019-05-11 13:59:10 +02:00
|
|
|
BLI_dynstr_append(ds, "\t#define localtoviewmat (ViewMatrix * ModelMatrix)\n");
|
2019-04-22 09:32:37 +10:00
|
|
|
}
|
|
|
|
if (builtins & GPU_INVERSE_LOC_TO_VIEW_MATRIX) {
|
2019-05-11 13:59:10 +02:00
|
|
|
BLI_dynstr_append(ds,
|
|
|
|
"\t#define invlocaltoviewmat (ModelMatrixInverse * ViewMatrixInverse)\n");
|
2019-04-22 09:32:37 +10:00
|
|
|
}
|
|
|
|
if (builtins & GPU_VIEW_NORMAL) {
|
2019-05-02 14:32:12 +02:00
|
|
|
BLI_dynstr_append(ds, "#ifdef HAIR_SHADER\n");
|
|
|
|
BLI_dynstr_append(ds, "\tvec3 n;\n");
|
|
|
|
BLI_dynstr_append(ds, "\tworld_normals_get(n);\n");
|
|
|
|
BLI_dynstr_append(ds, "\tvec3 facingnormal = transform_direction(ViewMatrix, n);\n");
|
|
|
|
BLI_dynstr_append(ds, "#else\n");
|
2019-05-08 19:33:54 +02:00
|
|
|
BLI_dynstr_append(ds, "\tvec3 facingnormal = gl_FrontFacing ? viewNormal: -viewNormal;\n");
|
2019-05-02 14:32:12 +02:00
|
|
|
BLI_dynstr_append(ds, "#endif\n");
|
2019-04-22 09:32:37 +10:00
|
|
|
}
|
2019-05-08 19:33:54 +02:00
|
|
|
if (builtins & GPU_WORLD_NORMAL) {
|
|
|
|
BLI_dynstr_append(ds, "\tvec3 facingwnormal;\n");
|
|
|
|
if (builtins & GPU_VIEW_NORMAL) {
|
|
|
|
BLI_dynstr_append(ds, "#ifdef HAIR_SHADER\n");
|
|
|
|
BLI_dynstr_append(ds, "\tfacingwnormal = n;\n");
|
|
|
|
BLI_dynstr_append(ds, "#else\n");
|
|
|
|
BLI_dynstr_append(ds, "\tworld_normals_get(facingwnormal);\n");
|
|
|
|
BLI_dynstr_append(ds, "#endif\n");
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
BLI_dynstr_append(ds, "\tworld_normals_get(facingwnormal);\n");
|
|
|
|
}
|
|
|
|
}
|
2019-04-22 09:32:37 +10:00
|
|
|
if (builtins & GPU_VIEW_POSITION) {
|
2019-04-17 06:17:24 +02:00
|
|
|
BLI_dynstr_append(ds, "\t#define viewposition viewPosition\n");
|
2019-04-22 09:32:37 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
codegen_declare_tmps(ds, nodes);
|
|
|
|
codegen_call_functions(ds, nodes, output);
|
|
|
|
|
|
|
|
BLI_dynstr_append(ds, "}\n");
|
|
|
|
|
2019-04-22 01:45:43 +10:00
|
|
|
/* XXX This cannot go into gpu_shader_material.glsl because main()
|
|
|
|
* would be parsed and generate error */
|
2019-04-17 06:17:24 +02:00
|
|
|
/* Old glsl mode compat. */
|
2019-08-14 14:28:57 +02:00
|
|
|
/* TODO(fclem) This is only used by world shader now. get rid of it? */
|
2019-04-17 06:17:24 +02:00
|
|
|
BLI_dynstr_append(ds, "#ifndef NODETREE_EXEC\n");
|
|
|
|
BLI_dynstr_append(ds, "out vec4 fragColor;\n");
|
|
|
|
BLI_dynstr_append(ds, "void main()\n");
|
|
|
|
BLI_dynstr_append(ds, "{\n");
|
|
|
|
BLI_dynstr_append(ds, "\tClosure cl = nodetree_exec();\n");
|
2019-08-14 14:28:57 +02:00
|
|
|
BLI_dynstr_append(ds,
|
|
|
|
"\tfragColor = vec4(cl.radiance, "
|
|
|
|
"saturate(1.0 - avg(cl.transmittance)));\n");
|
2019-04-17 06:17:24 +02:00
|
|
|
BLI_dynstr_append(ds, "}\n");
|
|
|
|
BLI_dynstr_append(ds, "#endif\n\n");
|
|
|
|
|
|
|
|
/* create shader */
|
|
|
|
code = BLI_dynstr_get_cstring(ds);
|
|
|
|
BLI_dynstr_free(ds);
|
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
|
|
|
|
2015-03-23 15:29:42 -04:00
|
|
|
#if 0
|
2019-05-31 23:21:16 +10:00
|
|
|
if (G.debug & G_DEBUG) {
|
2019-04-17 08:24:14 +02:00
|
|
|
printf("%s\n", code);
|
2019-05-31 23:21:16 +10:00
|
|
|
}
|
2015-03-23 15:29:42 -04:00
|
|
|
#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
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
return code;
|
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-01-29 07:46:25 +11:00
|
|
|
static const char *attr_prefix_get(CustomDataType type)
|
2017-05-01 18:09:50 +02:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
switch (type) {
|
|
|
|
case CD_ORCO:
|
|
|
|
return "orco";
|
|
|
|
case CD_MTFACE:
|
|
|
|
return "u";
|
|
|
|
case CD_TANGENT:
|
|
|
|
return "t";
|
|
|
|
case CD_MCOL:
|
|
|
|
return "c";
|
|
|
|
case CD_AUTO_FROM_NAME:
|
|
|
|
return "a";
|
|
|
|
default:
|
|
|
|
BLI_assert(false && "GPUVertAttr Prefix type not found : This should not happen!");
|
|
|
|
return "";
|
|
|
|
}
|
2017-05-01 18:09:50 +02:00
|
|
|
}
|
|
|
|
|
Remove Blender Internal and legacy viewport from Blender 2.8.
Brecht authored this commit, but he gave me the honours to actually
do it. Here it goes; Blender Internal. Bye bye, you did great!
* Point density, voxel data, ocean, environment map textures were removed,
as these only worked within BI rendering. Note that the ocean modifier
and the Cycles point density shader node continue to work.
* Dynamic paint using material shading was removed, as this only worked
with BI. If we ever wanted to support this again probably it should go
through the baking API.
* GPU shader export through the Python API was removed. This only worked
for the old BI GLSL shaders, which no longer exists. Doing something
similar for Eevee would be significantly more complicated because it
uses a lot of multiplass rendering and logic outside the shader, it's
probably impractical.
* Collada material import / export code is mostly gone, as it only worked
for BI materials. We need to add Cycles / Eevee material support at some
point.
* The mesh noise operator was removed since it only worked with BI
material texture slots. A displacement modifier can be used instead.
* The delete texture paint slot operator was removed since it only worked
for BI material texture slots. Could be added back with node support.
* Not all legacy viewport features are supported in the new viewport, but
their code was removed. If we need to bring anything back we can look at
older git revisions.
* There is some legacy viewport code that I could not remove yet, and some
that I probably missed.
* Shader node execution code was left mostly intact, even though it is not
used anywhere now. We may eventually use this to replace the texture
nodes with Cycles / Eevee shader nodes.
* The Cycles Bake panel now includes settings for baking multires normal
and displacement maps. The underlying code needs to be merged properly,
and we plan to add back support for multires AO baking and add support
to Cycles baking for features like vertex color, displacement, and other
missing baking features.
* This commit removes DNA and the Python API for BI material, lamp, world
and scene settings. This breaks a lot of addons.
* There is more DNA that can be removed or renamed, where Cycles or Eevee
are reusing some old BI properties but the names are not really correct
anymore.
* Texture slots for materials, lamps and world were removed. They remain
for brushes, particles and freestyle linestyles.
* 'BLENDER_RENDER' remains in the COMPAT_ENGINES of UI panels. Cycles and
other renderers use this to find all panels to show, minus a few panels
that they have their own replacement for.
2018-04-19 17:34:44 +02:00
|
|
|
static char *code_generate_vertex(ListBase *nodes, const char *vert_code, bool use_geom)
|
2017-05-01 18:09:50 +02:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
DynStr *ds = BLI_dynstr_new();
|
|
|
|
GPUNode *node;
|
|
|
|
GPUInput *input;
|
|
|
|
char *code;
|
|
|
|
int builtins = 0;
|
|
|
|
|
|
|
|
/* Hairs uv and col attributes are passed by bufferTextures. */
|
|
|
|
BLI_dynstr_append(ds,
|
|
|
|
"#ifdef HAIR_SHADER\n"
|
|
|
|
"#define DEFINE_ATTR(type, attr) uniform samplerBuffer attr\n"
|
|
|
|
"#else\n"
|
|
|
|
"#define DEFINE_ATTR(type, attr) in type attr\n"
|
|
|
|
"#endif\n");
|
|
|
|
|
|
|
|
for (node = nodes->first; node; node = node->next) {
|
|
|
|
for (input = node->inputs.first; input; input = input->next) {
|
|
|
|
if (input->source == GPU_SOURCE_BUILTIN) {
|
|
|
|
builtins |= input->builtin;
|
|
|
|
}
|
|
|
|
if (input->source == GPU_SOURCE_ATTR && input->attr_first) {
|
|
|
|
/* XXX FIXME : see notes in mesh_render_data_create() */
|
|
|
|
/* NOTE : Replicate changes to mesh_render_data_create() in draw_cache_impl_mesh.c */
|
|
|
|
if (input->attr_type == CD_ORCO) {
|
|
|
|
/* OPTI : orco is computed from local positions, but only if no modifier is present. */
|
2019-05-31 01:45:41 +02:00
|
|
|
BLI_dynstr_append(ds, datatoc_gpu_shader_common_obinfos_lib_glsl);
|
2019-04-17 06:17:24 +02:00
|
|
|
BLI_dynstr_append(ds, "DEFINE_ATTR(vec4, orco);\n");
|
|
|
|
}
|
|
|
|
else if (input->attr_name[0] == '\0') {
|
|
|
|
BLI_dynstr_appendf(ds,
|
|
|
|
"DEFINE_ATTR(%s, %s);\n",
|
2020-02-12 12:48:44 +01:00
|
|
|
gpu_data_type_to_string(input->type),
|
2019-04-17 06:17:24 +02:00
|
|
|
attr_prefix_get(input->attr_type));
|
|
|
|
BLI_dynstr_appendf(
|
|
|
|
ds, "#define att%d %s\n", input->attr_id, attr_prefix_get(input->attr_type));
|
|
|
|
}
|
|
|
|
else {
|
2019-08-14 22:18:47 +02:00
|
|
|
char attr_safe_name[GPU_MAX_SAFE_ATTRIB_NAME];
|
|
|
|
GPU_vertformat_safe_attrib_name(
|
|
|
|
input->attr_name, attr_safe_name, GPU_MAX_SAFE_ATTRIB_NAME);
|
2019-04-17 06:17:24 +02:00
|
|
|
BLI_dynstr_appendf(ds,
|
2019-08-14 22:18:47 +02:00
|
|
|
"DEFINE_ATTR(%s, %s%s);\n",
|
2020-02-12 12:48:44 +01:00
|
|
|
gpu_data_type_to_string(input->type),
|
2019-04-17 06:17:24 +02:00
|
|
|
attr_prefix_get(input->attr_type),
|
2019-08-14 22:18:47 +02:00
|
|
|
attr_safe_name);
|
|
|
|
BLI_dynstr_appendf(ds,
|
|
|
|
"#define att%d %s%s\n",
|
|
|
|
input->attr_id,
|
|
|
|
attr_prefix_get(input->attr_type),
|
|
|
|
attr_safe_name);
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
BLI_dynstr_appendf(ds,
|
|
|
|
"out %s var%d%s;\n",
|
2020-02-12 12:48:44 +01:00
|
|
|
gpu_data_type_to_string(input->type),
|
2019-04-17 06:17:24 +02:00
|
|
|
input->attr_id,
|
|
|
|
use_geom ? "g" : "");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (builtins & GPU_BARYCENTRIC_TEXCO) {
|
|
|
|
BLI_dynstr_append(ds, "#ifdef HAIR_SHADER\n");
|
|
|
|
BLI_dynstr_appendf(ds, "out vec2 barycentricTexCo%s;\n", use_geom ? "g" : "");
|
|
|
|
BLI_dynstr_append(ds, "#endif\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (builtins & GPU_BARYCENTRIC_DIST) {
|
|
|
|
BLI_dynstr_append(ds, "out vec3 barycentricPosg;\n");
|
|
|
|
}
|
|
|
|
|
2019-05-14 00:48:17 +02:00
|
|
|
BLI_dynstr_append(ds, "\n#define USE_ATTR\n");
|
|
|
|
|
|
|
|
/* Prototype, defined later (this is because of matrices definition). */
|
|
|
|
BLI_dynstr_append(ds, "void pass_attr(in vec3 position);\n");
|
|
|
|
|
|
|
|
BLI_dynstr_append(ds, "\n");
|
|
|
|
|
|
|
|
if (use_geom) {
|
|
|
|
/* XXX HACK: Eevee specific. */
|
|
|
|
char *vert_new, *vert_new2;
|
|
|
|
vert_new = BLI_str_replaceN(vert_code, "worldPosition", "worldPositiong");
|
|
|
|
vert_new2 = vert_new;
|
|
|
|
vert_new = BLI_str_replaceN(vert_new2, "viewPosition", "viewPositiong");
|
|
|
|
MEM_freeN(vert_new2);
|
|
|
|
vert_new2 = vert_new;
|
|
|
|
vert_new = BLI_str_replaceN(vert_new2, "worldNormal", "worldNormalg");
|
|
|
|
MEM_freeN(vert_new2);
|
|
|
|
vert_new2 = vert_new;
|
|
|
|
vert_new = BLI_str_replaceN(vert_new2, "viewNormal", "viewNormalg");
|
|
|
|
MEM_freeN(vert_new2);
|
|
|
|
|
|
|
|
BLI_dynstr_append(ds, vert_new);
|
|
|
|
|
|
|
|
MEM_freeN(vert_new);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
BLI_dynstr_append(ds, vert_code);
|
|
|
|
}
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
BLI_dynstr_append(ds, "\n");
|
|
|
|
|
2019-05-31 01:45:41 +02:00
|
|
|
BLI_dynstr_append(ds, use_geom ? "RESOURCE_ID_VARYING_GEOM\n" : "RESOURCE_ID_VARYING\n");
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* Prototype because defined later. */
|
|
|
|
BLI_dynstr_append(ds,
|
|
|
|
"vec2 hair_get_customdata_vec2(const samplerBuffer);\n"
|
|
|
|
"vec3 hair_get_customdata_vec3(const samplerBuffer);\n"
|
|
|
|
"vec4 hair_get_customdata_vec4(const samplerBuffer);\n"
|
|
|
|
"vec3 hair_get_strand_pos(void);\n"
|
|
|
|
"int hair_get_base_id(void);\n"
|
|
|
|
"\n");
|
|
|
|
|
|
|
|
BLI_dynstr_append(ds, "void pass_attr(in vec3 position) {\n");
|
|
|
|
|
2019-05-31 01:45:41 +02:00
|
|
|
BLI_dynstr_append(ds, use_geom ? "\tPASS_RESOURCE_ID_GEOM\n" : "\tPASS_RESOURCE_ID\n");
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
BLI_dynstr_append(ds, "#ifdef HAIR_SHADER\n");
|
|
|
|
|
|
|
|
if (builtins & GPU_BARYCENTRIC_TEXCO) {
|
|
|
|
/* To match cycles without breaking into individual segment we encode if we need to invert
|
|
|
|
* the first component into the second component. We invert if the barycentricTexCo.y
|
|
|
|
* is NOT 0.0 or 1.0. */
|
|
|
|
BLI_dynstr_append(ds, "\tint _base_id = hair_get_base_id();\n");
|
|
|
|
BLI_dynstr_appendf(
|
|
|
|
ds, "\tbarycentricTexCo%s.x = float((_base_id %% 2) == 1);\n", use_geom ? "g" : "");
|
|
|
|
BLI_dynstr_appendf(
|
|
|
|
ds, "\tbarycentricTexCo%s.y = float(((_base_id %% 4) %% 3) > 0);\n", use_geom ? "g" : "");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (builtins & GPU_BARYCENTRIC_DIST) {
|
|
|
|
BLI_dynstr_append(ds, "\tbarycentricPosg = position;\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
for (node = nodes->first; node; node = node->next) {
|
|
|
|
for (input = node->inputs.first; input; input = input->next) {
|
|
|
|
if (input->source == GPU_SOURCE_ATTR && input->attr_first) {
|
|
|
|
if (input->attr_type == CD_TANGENT) {
|
|
|
|
/* Not supported by hairs */
|
|
|
|
BLI_dynstr_appendf(ds, "\tvar%d%s = vec4(0.0);\n", input->attr_id, use_geom ? "g" : "");
|
|
|
|
}
|
|
|
|
else if (input->attr_type == CD_ORCO) {
|
|
|
|
BLI_dynstr_appendf(ds,
|
2019-05-31 01:45:41 +02:00
|
|
|
"\tvar%d%s = OrcoTexCoFactors[0].xyz + (ModelMatrixInverse * "
|
|
|
|
"vec4(hair_get_strand_pos(), 1.0)).xyz * OrcoTexCoFactors[1].xyz;\n",
|
2019-04-17 06:17:24 +02:00
|
|
|
input->attr_id,
|
|
|
|
use_geom ? "g" : "");
|
|
|
|
/* TODO: fix ORCO with modifiers. */
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
BLI_dynstr_appendf(ds,
|
|
|
|
"\tvar%d%s = hair_get_customdata_%s(att%d);\n",
|
|
|
|
input->attr_id,
|
|
|
|
use_geom ? "g" : "",
|
2020-02-12 12:48:44 +01:00
|
|
|
gpu_data_type_to_string(input->type),
|
2019-04-17 06:17:24 +02:00
|
|
|
input->attr_id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
BLI_dynstr_append(ds, "#else /* MESH_SHADER */\n");
|
|
|
|
|
|
|
|
/* GPU_BARYCENTRIC_TEXCO cannot be computed based on gl_VertexID
|
|
|
|
* for MESH_SHADER because of indexed drawing. In this case a
|
|
|
|
* geometry shader is needed. */
|
|
|
|
|
|
|
|
if (builtins & GPU_BARYCENTRIC_DIST) {
|
|
|
|
BLI_dynstr_append(ds, "\tbarycentricPosg = (ModelMatrix * vec4(position, 1.0)).xyz;\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
for (node = nodes->first; node; node = node->next) {
|
|
|
|
for (input = node->inputs.first; input; input = input->next) {
|
|
|
|
if (input->source == GPU_SOURCE_ATTR && input->attr_first) {
|
|
|
|
if (input->attr_type == CD_TANGENT) { /* silly exception */
|
|
|
|
BLI_dynstr_appendf(ds,
|
2019-05-08 23:21:09 +02:00
|
|
|
"\tvar%d%s.xyz = transpose(mat3(ModelMatrixInverse)) * att%d.xyz;\n",
|
2019-04-17 06:17:24 +02:00
|
|
|
input->attr_id,
|
|
|
|
use_geom ? "g" : "",
|
|
|
|
input->attr_id);
|
|
|
|
BLI_dynstr_appendf(
|
|
|
|
ds, "\tvar%d%s.w = att%d.w;\n", input->attr_id, use_geom ? "g" : "", input->attr_id);
|
|
|
|
/* Normalize only if vector is not null. */
|
|
|
|
BLI_dynstr_appendf(ds,
|
|
|
|
"\tfloat lvar%d = dot(var%d%s.xyz, var%d%s.xyz);\n",
|
|
|
|
input->attr_id,
|
|
|
|
input->attr_id,
|
|
|
|
use_geom ? "g" : "",
|
|
|
|
input->attr_id,
|
|
|
|
use_geom ? "g" : "");
|
|
|
|
BLI_dynstr_appendf(ds,
|
|
|
|
"\tvar%d%s.xyz *= (lvar%d > 0.0) ? inversesqrt(lvar%d) : 1.0;\n",
|
|
|
|
input->attr_id,
|
|
|
|
use_geom ? "g" : "",
|
|
|
|
input->attr_id,
|
|
|
|
input->attr_id);
|
|
|
|
}
|
|
|
|
else if (input->attr_type == CD_ORCO) {
|
|
|
|
BLI_dynstr_appendf(ds,
|
2019-05-31 01:45:41 +02:00
|
|
|
"\tvar%d%s = OrcoTexCoFactors[0].xyz + position *"
|
|
|
|
" OrcoTexCoFactors[1].xyz;\n",
|
2019-04-17 06:17:24 +02:00
|
|
|
input->attr_id,
|
|
|
|
use_geom ? "g" : "");
|
|
|
|
/* See mesh_create_loop_orco() for explanation. */
|
|
|
|
BLI_dynstr_appendf(ds,
|
|
|
|
"\tif (orco.w == 0.0) { var%d%s = orco.xyz * 0.5 + 0.5; }\n",
|
|
|
|
input->attr_id,
|
|
|
|
use_geom ? "g" : "");
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
BLI_dynstr_appendf(
|
|
|
|
ds, "\tvar%d%s = att%d;\n", input->attr_id, use_geom ? "g" : "", input->attr_id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
BLI_dynstr_append(ds, "#endif /* HAIR_SHADER */\n");
|
|
|
|
|
|
|
|
BLI_dynstr_append(ds, "}\n");
|
|
|
|
|
|
|
|
code = BLI_dynstr_get_cstring(ds);
|
|
|
|
|
|
|
|
BLI_dynstr_free(ds);
|
2017-05-01 18:09:50 +02:00
|
|
|
|
|
|
|
#if 0
|
2019-05-31 23:21:16 +10:00
|
|
|
if (G.debug & G_DEBUG) {
|
2019-04-17 08:24:14 +02:00
|
|
|
printf("%s\n", code);
|
2019-05-31 23:21:16 +10:00
|
|
|
}
|
2017-05-01 18:09:50 +02:00
|
|
|
#endif
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
return code;
|
2017-05-01 18:09:50 +02:00
|
|
|
}
|
|
|
|
|
2019-02-28 13:56:03 +01:00
|
|
|
static char *code_generate_geometry(ListBase *nodes, const char *geom_code, const char *defines)
|
2017-06-28 21:05:43 +02:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
DynStr *ds = BLI_dynstr_new();
|
|
|
|
GPUNode *node;
|
|
|
|
GPUInput *input;
|
|
|
|
char *code;
|
|
|
|
int builtins = 0;
|
|
|
|
|
|
|
|
/* XXX we should not make specific eevee cases here. */
|
|
|
|
bool is_hair_shader = (strstr(defines, "HAIR_SHADER") != NULL);
|
|
|
|
|
|
|
|
/* Create prototype because attributes cannot be declared before layout. */
|
|
|
|
BLI_dynstr_append(ds, "void pass_attr(in int vert);\n");
|
|
|
|
BLI_dynstr_append(ds, "void calc_barycentric_distances(vec3 pos0, vec3 pos1, vec3 pos2);\n");
|
|
|
|
BLI_dynstr_append(ds, "#define USE_ATTR\n");
|
|
|
|
|
|
|
|
/* Generate varying declarations. */
|
|
|
|
for (node = nodes->first; node; node = node->next) {
|
|
|
|
for (input = node->inputs.first; input; input = input->next) {
|
|
|
|
if (input->source == GPU_SOURCE_BUILTIN) {
|
|
|
|
builtins |= input->builtin;
|
|
|
|
}
|
|
|
|
if (input->source == GPU_SOURCE_ATTR && input->attr_first) {
|
2020-02-12 12:48:44 +01:00
|
|
|
BLI_dynstr_appendf(
|
|
|
|
ds, "in %s var%dg[];\n", gpu_data_type_to_string(input->type), input->attr_id);
|
|
|
|
BLI_dynstr_appendf(
|
|
|
|
ds, "out %s var%d;\n", gpu_data_type_to_string(input->type), input->attr_id);
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (builtins & GPU_BARYCENTRIC_TEXCO) {
|
|
|
|
BLI_dynstr_append(ds, "#ifdef HAIR_SHADER\n");
|
|
|
|
BLI_dynstr_append(ds, "in vec2 barycentricTexCog[];\n");
|
|
|
|
BLI_dynstr_append(ds, "#endif\n");
|
|
|
|
|
|
|
|
BLI_dynstr_append(ds, "out vec2 barycentricTexCo;\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (builtins & GPU_BARYCENTRIC_DIST) {
|
|
|
|
BLI_dynstr_append(ds, "in vec3 barycentricPosg[];\n");
|
|
|
|
BLI_dynstr_append(ds, "flat out vec3 barycentricDist;\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (geom_code == NULL) {
|
|
|
|
/* Force geometry usage if GPU_BARYCENTRIC_DIST or GPU_BARYCENTRIC_TEXCO are used.
|
|
|
|
* Note: GPU_BARYCENTRIC_TEXCO only requires it if the shader is not drawing hairs. */
|
|
|
|
if ((builtins & (GPU_BARYCENTRIC_DIST | GPU_BARYCENTRIC_TEXCO)) == 0 || is_hair_shader) {
|
|
|
|
/* Early out */
|
|
|
|
BLI_dynstr_free(ds);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* Force geom shader usage */
|
|
|
|
/* TODO put in external file. */
|
|
|
|
BLI_dynstr_append(ds, "layout(triangles) in;\n");
|
|
|
|
BLI_dynstr_append(ds, "layout(triangle_strip, max_vertices=3) out;\n");
|
|
|
|
|
|
|
|
BLI_dynstr_append(ds, "in vec3 worldPositiong[];\n");
|
|
|
|
BLI_dynstr_append(ds, "in vec3 viewPositiong[];\n");
|
|
|
|
BLI_dynstr_append(ds, "in vec3 worldNormalg[];\n");
|
|
|
|
BLI_dynstr_append(ds, "in vec3 viewNormalg[];\n");
|
|
|
|
|
|
|
|
BLI_dynstr_append(ds, "out vec3 worldPosition;\n");
|
|
|
|
BLI_dynstr_append(ds, "out vec3 viewPosition;\n");
|
|
|
|
BLI_dynstr_append(ds, "out vec3 worldNormal;\n");
|
|
|
|
BLI_dynstr_append(ds, "out vec3 viewNormal;\n");
|
|
|
|
|
2019-05-31 01:45:41 +02:00
|
|
|
BLI_dynstr_append(ds, datatoc_common_view_lib_glsl);
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
BLI_dynstr_append(ds, "void main(){\n");
|
|
|
|
|
|
|
|
if (builtins & GPU_BARYCENTRIC_DIST) {
|
|
|
|
BLI_dynstr_append(ds,
|
|
|
|
"\tcalc_barycentric_distances(barycentricPosg[0], barycentricPosg[1], "
|
|
|
|
"barycentricPosg[2]);\n");
|
|
|
|
}
|
|
|
|
|
2020-01-16 15:29:07 +01:00
|
|
|
for (int i = 0; i < 3; i++) {
|
|
|
|
BLI_dynstr_appendf(ds, "\tgl_Position = gl_in[%d].gl_Position;\n", i);
|
|
|
|
BLI_dynstr_appendf(ds, "\tgl_ClipDistance[0] = gl_in[%d].gl_ClipDistance[0];\n", i);
|
|
|
|
BLI_dynstr_appendf(ds, "\tpass_attr(%d);\n", i);
|
|
|
|
BLI_dynstr_append(ds, "\tEmitVertex();\n");
|
|
|
|
}
|
2019-09-07 00:00:48 +02:00
|
|
|
BLI_dynstr_append(ds, "}\n");
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
BLI_dynstr_append(ds, geom_code);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (builtins & GPU_BARYCENTRIC_DIST) {
|
|
|
|
BLI_dynstr_append(ds, "void calc_barycentric_distances(vec3 pos0, vec3 pos1, vec3 pos2) {\n");
|
|
|
|
BLI_dynstr_append(ds, "\tvec3 edge21 = pos2 - pos1;\n");
|
|
|
|
BLI_dynstr_append(ds, "\tvec3 edge10 = pos1 - pos0;\n");
|
|
|
|
BLI_dynstr_append(ds, "\tvec3 edge02 = pos0 - pos2;\n");
|
|
|
|
BLI_dynstr_append(ds, "\tvec3 d21 = normalize(edge21);\n");
|
|
|
|
BLI_dynstr_append(ds, "\tvec3 d10 = normalize(edge10);\n");
|
|
|
|
BLI_dynstr_append(ds, "\tvec3 d02 = normalize(edge02);\n");
|
|
|
|
|
|
|
|
BLI_dynstr_append(ds, "\tfloat d = dot(d21, edge02);\n");
|
|
|
|
BLI_dynstr_append(ds, "\tbarycentricDist.x = sqrt(dot(edge02, edge02) - d * d);\n");
|
|
|
|
BLI_dynstr_append(ds, "\td = dot(d02, edge10);\n");
|
|
|
|
BLI_dynstr_append(ds, "\tbarycentricDist.y = sqrt(dot(edge10, edge10) - d * d);\n");
|
|
|
|
BLI_dynstr_append(ds, "\td = dot(d10, edge21);\n");
|
|
|
|
BLI_dynstr_append(ds, "\tbarycentricDist.z = sqrt(dot(edge21, edge21) - d * d);\n");
|
|
|
|
BLI_dynstr_append(ds, "}\n");
|
|
|
|
}
|
|
|
|
|
2019-05-31 01:45:41 +02:00
|
|
|
BLI_dynstr_append(ds, "RESOURCE_ID_VARYING\n");
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* Generate varying assignments. */
|
|
|
|
BLI_dynstr_append(ds, "void pass_attr(in int vert) {\n");
|
|
|
|
|
2019-05-31 01:45:41 +02:00
|
|
|
BLI_dynstr_append(ds, "\tPASS_RESOURCE_ID(vert)\n");
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* XXX HACK: Eevee specific. */
|
|
|
|
if (geom_code == NULL) {
|
|
|
|
BLI_dynstr_append(ds, "\tworldPosition = worldPositiong[vert];\n");
|
|
|
|
BLI_dynstr_append(ds, "\tviewPosition = viewPositiong[vert];\n");
|
|
|
|
BLI_dynstr_append(ds, "\tworldNormal = worldNormalg[vert];\n");
|
|
|
|
BLI_dynstr_append(ds, "\tviewNormal = viewNormalg[vert];\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (builtins & GPU_BARYCENTRIC_TEXCO) {
|
|
|
|
BLI_dynstr_append(ds, "#ifdef HAIR_SHADER\n");
|
|
|
|
BLI_dynstr_append(ds, "\tbarycentricTexCo = barycentricTexCog[vert];\n");
|
|
|
|
BLI_dynstr_append(ds, "#else\n");
|
|
|
|
BLI_dynstr_append(ds, "\tbarycentricTexCo.x = float((vert % 3) == 0);\n");
|
|
|
|
BLI_dynstr_append(ds, "\tbarycentricTexCo.y = float((vert % 3) == 1);\n");
|
|
|
|
BLI_dynstr_append(ds, "#endif\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
for (node = nodes->first; node; node = node->next) {
|
|
|
|
for (input = node->inputs.first; input; input = input->next) {
|
|
|
|
if (input->source == GPU_SOURCE_ATTR && input->attr_first) {
|
|
|
|
/* TODO let shader choose what to do depending on what the attribute is. */
|
|
|
|
BLI_dynstr_appendf(ds, "\tvar%d = var%dg[vert];\n", input->attr_id, input->attr_id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
BLI_dynstr_append(ds, "}\n");
|
|
|
|
|
|
|
|
code = BLI_dynstr_get_cstring(ds);
|
|
|
|
BLI_dynstr_free(ds);
|
|
|
|
|
|
|
|
return code;
|
2017-06-28 21:05:43 +02:00
|
|
|
}
|
|
|
|
|
2018-06-07 11:58:15 +02:00
|
|
|
GPUShader *GPU_pass_shader_get(GPUPass *pass)
|
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-04-17 06:17:24 +02:00
|
|
|
return pass->shader;
|
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-12 12:48:44 +01:00
|
|
|
/* Vertex Attributes */
|
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-12 12:48:44 +01:00
|
|
|
static void gpu_nodes_get_vertex_attrs(ListBase *nodes, GPUVertAttrLayers *attrs)
|
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-04-17 06:17:24 +02:00
|
|
|
GPUNode *node;
|
|
|
|
GPUInput *input;
|
|
|
|
int a;
|
|
|
|
|
|
|
|
/* convert attributes requested by node inputs to an array of layers,
|
|
|
|
* checking for duplicates and assigning id's starting from zero. */
|
|
|
|
|
|
|
|
memset(attrs, 0, sizeof(*attrs));
|
|
|
|
|
|
|
|
for (node = nodes->first; node; node = node->next) {
|
|
|
|
for (input = node->inputs.first; input; input = input->next) {
|
|
|
|
if (input->source == GPU_SOURCE_ATTR) {
|
|
|
|
for (a = 0; a < attrs->totlayer; a++) {
|
|
|
|
if (attrs->layer[a].type == input->attr_type &&
|
|
|
|
STREQ(attrs->layer[a].name, input->attr_name)) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (a < GPU_MAX_ATTR) {
|
|
|
|
if (a == attrs->totlayer) {
|
|
|
|
input->attr_id = attrs->totlayer++;
|
|
|
|
input->attr_first = true;
|
|
|
|
|
|
|
|
attrs->layer[a].type = input->attr_type;
|
|
|
|
attrs->layer[a].attr_id = input->attr_id;
|
|
|
|
BLI_strncpy(attrs->layer[a].name, input->attr_name, sizeof(attrs->layer[a].name));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
input->attr_id = attrs->layer[a].attr_id;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
|
|
|
/* Pass create/free */
|
|
|
|
|
2018-06-07 11:58:15 +02:00
|
|
|
static bool gpu_pass_is_valid(GPUPass *pass)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
/* Shader is not null if compilation is successful. */
|
|
|
|
return (pass->compiled == false || pass->shader != NULL);
|
2018-06-07 11:58:15 +02:00
|
|
|
}
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
GPUPass *GPU_generate_pass(GPUMaterial *material,
|
2020-02-12 12:48:44 +01:00
|
|
|
GPUNodeGraph *graph,
|
2019-04-17 06:17:24 +02:00
|
|
|
const char *vert_code,
|
|
|
|
const char *geom_code,
|
|
|
|
const char *frag_lib,
|
|
|
|
const char *defines)
|
2017-04-27 22:27:09 +02:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
char *vertexcode, *geometrycode, *fragmentcode;
|
|
|
|
GPUPass *pass = NULL, *pass_hash = NULL;
|
|
|
|
|
2020-02-12 12:48:44 +01:00
|
|
|
/* Prune the unused nodes and extract attributes before compiling so the
|
|
|
|
* generated VBOs are ready to accept the future shader. */
|
2020-02-12 12:48:44 +01:00
|
|
|
gpu_node_graph_prune_unused(graph);
|
|
|
|
gpu_nodes_get_vertex_attrs(&graph->nodes, &graph->attrs);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
/* generate code */
|
2020-02-12 12:48:44 +01:00
|
|
|
char *fragmentgen = code_generate_fragment(
|
|
|
|
material, &graph->nodes, graph->outlink->output, &graph->builtins);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
/* Cache lookup: Reuse shaders already compiled */
|
2020-02-12 12:48:44 +01:00
|
|
|
uint32_t hash = gpu_pass_hash(fragmentgen, defines, &graph->attrs);
|
2019-04-17 06:17:24 +02:00
|
|
|
pass_hash = gpu_pass_cache_lookup(hash);
|
|
|
|
|
|
|
|
if (pass_hash && (pass_hash->next == NULL || pass_hash->next->hash != hash)) {
|
|
|
|
/* No collision, just return the pass. */
|
|
|
|
MEM_freeN(fragmentgen);
|
|
|
|
if (!gpu_pass_is_valid(pass_hash)) {
|
|
|
|
/* Shader has already been created but failed to compile. */
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
pass_hash->refcount += 1;
|
|
|
|
return pass_hash;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Either the shader is not compiled or there is a hash collision...
|
|
|
|
* continue generating the shader strings. */
|
2020-02-12 12:48:44 +01:00
|
|
|
GSet *used_libraries = gpu_material_used_libraries(material);
|
|
|
|
char *tmp = gpu_material_library_generate_code(used_libraries, frag_lib);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-02-12 12:48:44 +01:00
|
|
|
geometrycode = code_generate_geometry(&graph->nodes, geom_code, defines);
|
|
|
|
vertexcode = code_generate_vertex(&graph->nodes, vert_code, (geometrycode != NULL));
|
2019-04-17 06:17:24 +02:00
|
|
|
fragmentcode = BLI_strdupcat(tmp, fragmentgen);
|
|
|
|
|
|
|
|
MEM_freeN(fragmentgen);
|
|
|
|
MEM_freeN(tmp);
|
|
|
|
|
|
|
|
if (pass_hash) {
|
|
|
|
/* Cache lookup: Reuse shaders already compiled */
|
|
|
|
pass = gpu_pass_cache_resolve_collision(
|
|
|
|
pass_hash, vertexcode, geometrycode, fragmentcode, defines, hash);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pass) {
|
|
|
|
/* Cache hit. Reuse the same GPUPass and GPUShader. */
|
|
|
|
if (!gpu_pass_is_valid(pass)) {
|
|
|
|
/* Shader has already been created but failed to compile. */
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
MEM_SAFE_FREE(vertexcode);
|
|
|
|
MEM_SAFE_FREE(fragmentcode);
|
|
|
|
MEM_SAFE_FREE(geometrycode);
|
|
|
|
|
|
|
|
pass->refcount += 1;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* We still create a pass even if shader compilation
|
|
|
|
* fails to avoid trying to compile again and again. */
|
|
|
|
pass = MEM_callocN(sizeof(GPUPass), "GPUPass");
|
|
|
|
pass->shader = NULL;
|
|
|
|
pass->refcount = 1;
|
|
|
|
pass->hash = hash;
|
|
|
|
pass->vertexcode = vertexcode;
|
|
|
|
pass->fragmentcode = fragmentcode;
|
|
|
|
pass->geometrycode = geometrycode;
|
|
|
|
pass->defines = (defines) ? BLI_strdup(defines) : NULL;
|
|
|
|
pass->compiled = false;
|
|
|
|
|
|
|
|
BLI_spin_lock(&pass_cache_spin);
|
|
|
|
if (pass_hash != NULL) {
|
|
|
|
/* Add after the first pass having the same hash. */
|
|
|
|
pass->next = pass_hash->next;
|
|
|
|
pass_hash->next = pass;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* No other pass have same hash, just prepend to the list. */
|
|
|
|
BLI_LINKS_PREPEND(pass_cache, pass);
|
|
|
|
}
|
|
|
|
BLI_spin_unlock(&pass_cache_spin);
|
|
|
|
}
|
|
|
|
|
|
|
|
return pass;
|
2018-06-07 11:58:15 +02:00
|
|
|
}
|
|
|
|
|
2018-09-18 14:22:42 +02:00
|
|
|
static int count_active_texture_sampler(GPUShader *shader, char *source)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
char *code = source;
|
2019-12-16 15:49:19 +01:00
|
|
|
|
|
|
|
/* Remember this is per stage. */
|
|
|
|
GSet *sampler_ids = BLI_gset_int_new(__func__);
|
|
|
|
int num_samplers = 0;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
while ((code = strstr(code, "uniform "))) {
|
|
|
|
/* Move past "uniform". */
|
|
|
|
code += 7;
|
|
|
|
/* Skip following spaces. */
|
|
|
|
while (*code == ' ') {
|
|
|
|
code++;
|
|
|
|
}
|
|
|
|
/* Skip "i" from potential isamplers. */
|
|
|
|
if (*code == 'i') {
|
|
|
|
code++;
|
|
|
|
}
|
|
|
|
/* Skip following spaces. */
|
2020-02-12 12:48:44 +01:00
|
|
|
if (BLI_str_startswith(code, "sampler")) {
|
2019-04-17 06:17:24 +02:00
|
|
|
/* Move past "uniform". */
|
|
|
|
code += 7;
|
|
|
|
/* Skip sampler type suffix. */
|
|
|
|
while (*code != ' ' && *code != '\0') {
|
|
|
|
code++;
|
|
|
|
}
|
|
|
|
/* Skip following spaces. */
|
|
|
|
while (*code == ' ') {
|
|
|
|
code++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (*code != '\0') {
|
|
|
|
char sampler_name[64];
|
|
|
|
code = gpu_str_skip_token(code, sampler_name, sizeof(sampler_name));
|
|
|
|
int id = GPU_shader_get_uniform_ensure(shader, sampler_name);
|
|
|
|
|
|
|
|
if (id == -1) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
/* Catch duplicates. */
|
2019-12-16 15:49:19 +01:00
|
|
|
if (BLI_gset_add(sampler_ids, POINTER_FROM_INT(id))) {
|
|
|
|
num_samplers++;
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-16 15:49:19 +01:00
|
|
|
BLI_gset_free(sampler_ids, NULL);
|
|
|
|
|
|
|
|
return num_samplers;
|
2018-09-18 14:22:42 +02:00
|
|
|
}
|
|
|
|
|
2019-06-05 13:06:11 -03:00
|
|
|
static bool gpu_pass_shader_validate(GPUPass *pass, GPUShader *shader)
|
2018-09-18 14:22:42 +02:00
|
|
|
{
|
2019-06-05 13:06:11 -03:00
|
|
|
if (shader == NULL) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* NOTE: The only drawback of this method is that it will count a sampler
|
|
|
|
* used in the fragment shader and only declared (but not used) in the vertex
|
|
|
|
* shader as used by both. But this corner case is not happening for now. */
|
2019-06-05 13:06:11 -03:00
|
|
|
int vert_samplers_len = count_active_texture_sampler(shader, pass->vertexcode);
|
|
|
|
int frag_samplers_len = count_active_texture_sampler(shader, pass->fragmentcode);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
int total_samplers_len = vert_samplers_len + frag_samplers_len;
|
|
|
|
|
|
|
|
/* Validate against opengl limit. */
|
|
|
|
if ((frag_samplers_len > GPU_max_textures_frag()) ||
|
|
|
|
(vert_samplers_len > GPU_max_textures_vert())) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pass->geometrycode) {
|
2019-06-05 13:06:11 -03:00
|
|
|
int geom_samplers_len = count_active_texture_sampler(shader, pass->geometrycode);
|
2019-04-17 06:17:24 +02:00
|
|
|
total_samplers_len += geom_samplers_len;
|
|
|
|
if (geom_samplers_len > GPU_max_textures_geom()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return (total_samplers_len <= GPU_max_textures());
|
2018-09-18 14:22:42 +02:00
|
|
|
}
|
|
|
|
|
2019-06-05 13:06:11 -03:00
|
|
|
bool GPU_pass_compile(GPUPass *pass, const char *shname)
|
2018-06-07 11:58:15 +02:00
|
|
|
{
|
2019-08-01 17:32:42 +10:00
|
|
|
bool success = true;
|
2019-04-17 06:17:24 +02:00
|
|
|
if (!pass->compiled) {
|
2019-06-05 13:06:11 -03:00
|
|
|
GPUShader *shader = GPU_shader_create(
|
2019-04-17 06:17:24 +02:00
|
|
|
pass->vertexcode, pass->fragmentcode, pass->geometrycode, NULL, pass->defines, shname);
|
|
|
|
|
|
|
|
/* NOTE: Some drivers / gpu allows more active samplers than the opengl limit.
|
|
|
|
* We need to make sure to count active samplers to avoid undefined behavior. */
|
2019-06-05 13:06:11 -03:00
|
|
|
if (!gpu_pass_shader_validate(pass, shader)) {
|
2019-08-01 17:32:42 +10:00
|
|
|
success = false;
|
2019-06-05 13:06:11 -03:00
|
|
|
if (shader != NULL) {
|
2019-04-17 06:17:24 +02:00
|
|
|
fprintf(stderr, "GPUShader: error: too many samplers in shader.\n");
|
2019-06-05 13:06:11 -03:00
|
|
|
GPU_shader_free(shader);
|
|
|
|
shader = NULL;
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
}
|
2019-06-05 13:06:11 -03:00
|
|
|
else if (!BLI_thread_is_main() && GPU_context_local_shaders_workaround()) {
|
|
|
|
pass->binary.content = GPU_shader_get_binary(
|
|
|
|
shader, &pass->binary.format, &pass->binary.len);
|
|
|
|
GPU_shader_free(shader);
|
|
|
|
shader = NULL;
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
|
2019-06-05 13:06:11 -03:00
|
|
|
pass->shader = shader;
|
2019-04-17 06:17:24 +02:00
|
|
|
pass->compiled = true;
|
|
|
|
}
|
2019-06-05 13:06:11 -03:00
|
|
|
else if (pass->binary.content && BLI_thread_is_main()) {
|
|
|
|
pass->shader = GPU_shader_load_from_binary(
|
|
|
|
pass->binary.content, pass->binary.format, pass->binary.len, shname);
|
|
|
|
MEM_SAFE_FREE(pass->binary.content);
|
|
|
|
}
|
|
|
|
|
2019-08-01 17:32:42 +10:00
|
|
|
return success;
|
2017-04-27 22:27:09 +02:00
|
|
|
}
|
|
|
|
|
2018-03-11 23:43:09 +01:00
|
|
|
void GPU_pass_release(GPUPass *pass)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
BLI_assert(pass->refcount > 0);
|
|
|
|
pass->refcount--;
|
2018-03-11 23:43:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void gpu_pass_free(GPUPass *pass)
|
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-04-17 06:17:24 +02:00
|
|
|
BLI_assert(pass->refcount == 0);
|
|
|
|
if (pass->shader) {
|
|
|
|
GPU_shader_free(pass->shader);
|
|
|
|
}
|
|
|
|
MEM_SAFE_FREE(pass->fragmentcode);
|
|
|
|
MEM_SAFE_FREE(pass->geometrycode);
|
|
|
|
MEM_SAFE_FREE(pass->vertexcode);
|
|
|
|
MEM_SAFE_FREE(pass->defines);
|
2019-06-05 13:06:11 -03:00
|
|
|
if (pass->binary.content) {
|
|
|
|
MEM_freeN(pass->binary.content);
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
MEM_freeN(pass);
|
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
|
|
|
}
|
2016-07-27 10:59:09 +02:00
|
|
|
|
2018-03-11 23:43:09 +01:00
|
|
|
void GPU_pass_cache_garbage_collect(void)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
static int lasttime = 0;
|
|
|
|
const int shadercollectrate = 60; /* hardcoded for now. */
|
|
|
|
int ctime = (int)PIL_check_seconds_timer();
|
|
|
|
|
2019-04-22 09:32:37 +10:00
|
|
|
if (ctime < shadercollectrate + lasttime) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return;
|
2019-04-22 09:32:37 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
lasttime = ctime;
|
|
|
|
|
|
|
|
BLI_spin_lock(&pass_cache_spin);
|
|
|
|
GPUPass *next, **prev_pass = &pass_cache;
|
|
|
|
for (GPUPass *pass = pass_cache; pass; pass = next) {
|
|
|
|
next = pass->next;
|
|
|
|
if (pass->refcount == 0) {
|
|
|
|
/* Remove from list */
|
|
|
|
*prev_pass = next;
|
|
|
|
gpu_pass_free(pass);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
prev_pass = &pass->next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
BLI_spin_unlock(&pass_cache_spin);
|
2018-06-07 11:58:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void GPU_pass_cache_init(void)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
BLI_spin_init(&pass_cache_spin);
|
2018-03-11 23:43:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void GPU_pass_cache_free(void)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
BLI_spin_lock(&pass_cache_spin);
|
|
|
|
while (pass_cache) {
|
|
|
|
GPUPass *next = pass_cache->next;
|
|
|
|
gpu_pass_free(pass_cache);
|
|
|
|
pass_cache = next;
|
|
|
|
}
|
|
|
|
BLI_spin_unlock(&pass_cache_spin);
|
|
|
|
|
|
|
|
BLI_spin_end(&pass_cache_spin);
|
2018-03-11 23:43:09 +01:00
|
|
|
}
|
2020-02-12 12:48:44 +01:00
|
|
|
|
|
|
|
/* Module */
|
|
|
|
|
|
|
|
void gpu_codegen_init(void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void gpu_codegen_exit(void)
|
|
|
|
{
|
|
|
|
BKE_material_defaults_free_gpu();
|
|
|
|
GPU_shader_free_builtin_shaders();
|
|
|
|
}
|