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"
|
2011-01-07 18:36:47 +00:00
|
|
|
#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"
|
2020-03-19 09:33:03 +01:00
|
|
|
#include "BLI_hash_mm2a.h"
|
|
|
|
#include "BLI_link_utils.h"
|
2018-06-07 11:58:15 +02:00
|
|
|
#include "BLI_threads.h"
|
2020-03-19 09:33:03 +01:00
|
|
|
#include "BLI_utildefines.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"
|
|
|
|
|
2020-09-07 19:35:56 +02:00
|
|
|
#include "GPU_capabilities.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"
|
2020-08-20 23:09:37 +02:00
|
|
|
#include "GPU_uniform_buffer.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 <stdarg.h>
|
2020-03-19 09:33:03 +01:00
|
|
|
#include <string.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
|
|
|
|
2020-07-30 13:55:13 +02:00
|
|
|
extern char datatoc_gpu_shader_codegen_lib_glsl[];
|
2019-05-31 01:45:41 +02:00
|
|
|
extern char datatoc_gpu_shader_common_obinfos_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
|
|
|
|
2020-02-14 10:47:20 +01:00
|
|
|
static uint32_t gpu_pass_hash(const char *frag_gen, const char *defs, ListBase *attributes)
|
2018-03-11 23:43:09 +01:00
|
|
|
{
|
|
|
|
BLI_HashMurmur2A hm2a;
|
|
|
|
BLI_hash_mm2a_init(&hm2a, 0);
|
2018-09-12 12:18:35 +10:00
|
|
|
BLI_hash_mm2a_add(&hm2a, (uchar *)frag_gen, strlen(frag_gen));
|
2020-04-03 19:15:01 +02:00
|
|
|
LISTBASE_FOREACH (GPUMaterialAttribute *, attr, attributes) {
|
2020-02-14 10:47:20 +01:00
|
|
|
BLI_hash_mm2a_add(&hm2a, (uchar *)attr->name, strlen(attr->name));
|
2018-07-02 11:03:14 +02:00
|
|
|
}
|
2019-04-22 09:32:37 +10:00
|
|
|
if (defs) {
|
2018-09-12 12:18:35 +10: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
|
|
|
|
2018-03-11 23:43:09 +01:00
|
|
|
return BLI_hash_mm2a_end(&hm2a);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2018-06-07 11:58:15 +02:00
|
|
|
BLI_spin_lock(&pass_cache_spin);
|
|
|
|
/* Could be optimized with a Lookup table. */
|
|
|
|
for (GPUPass *pass = pass_cache; pass; pass = pass->next) {
|
2018-03-11 23:43:09 +01:00
|
|
|
if (pass->hash == hash) {
|
2018-06-07 11:58:15 +02:00
|
|
|
BLI_spin_unlock(&pass_cache_spin);
|
|
|
|
return pass;
|
2018-03-11 23:43:09 +01:00
|
|
|
}
|
|
|
|
}
|
2018-06-07 11:58:15 +02:00
|
|
|
BLI_spin_unlock(&pass_cache_spin);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check all possible passes with the same hash. */
|
|
|
|
static GPUPass *gpu_pass_cache_resolve_collision(GPUPass *pass,
|
|
|
|
const char *vert,
|
|
|
|
const char *geom,
|
|
|
|
const char *frag,
|
|
|
|
const char *defs,
|
|
|
|
uint32_t hash)
|
|
|
|
{
|
|
|
|
BLI_spin_lock(&pass_cache_spin);
|
|
|
|
/* Collision, need to strcmp the whole shader. */
|
|
|
|
for (; pass && (pass->hash == hash); pass = pass->next) {
|
2020-08-08 12:14:52 +10:00
|
|
|
if ((defs != NULL) && (!STREQ(pass->defines, defs))) { /* Pass */
|
2018-06-07 11:58:15 +02:00
|
|
|
}
|
2020-08-08 12:14:52 +10:00
|
|
|
else if ((geom != NULL) && (!STREQ(pass->geometrycode, geom))) { /* Pass */
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2020-08-08 12:14:52 +10:00
|
|
|
else if ((!STREQ(pass->fragmentcode, frag) == 0) && (STREQ(pass->vertexcode, vert))) {
|
2018-06-07 11:58:15 +02:00
|
|
|
BLI_spin_unlock(&pass_cache_spin);
|
|
|
|
return pass;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
BLI_spin_unlock(&pass_cache_spin);
|
2018-03-11 23:43:09 +01:00
|
|
|
return 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
|
|
|
/* 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
|
|
|
{
|
|
|
|
char name[1024];
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2011-08-30 10:07:50 +00:00
|
|
|
BLI_snprintf(name, sizeof(name), "%s%d", tmp, id);
|
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
|
|
|
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) {
|
2015-05-17 18:18:04 +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) {
|
2011-08-30 10:07:50 +00:00
|
|
|
BLI_dynstr_appendf(ds, "%s.r", name);
|
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
|
|
|
}
|
|
|
|
else if (to == GPU_VEC2) {
|
2019-04-22 09:32:37 +10:00
|
|
|
if (from == GPU_VEC4) {
|
2015-05-17 18:18:04 +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) {
|
2015-05-17 18:18:04 +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) {
|
2011-08-30 10:07:50 +00:00
|
|
|
BLI_dynstr_appendf(ds, "vec2(%s, 1.0)", name);
|
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
|
|
|
}
|
|
|
|
else if (to == GPU_VEC3) {
|
2019-04-22 09:32:37 +10:00
|
|
|
if (from == GPU_VEC4) {
|
2011-08-30 10:07:50 +00:00
|
|
|
BLI_dynstr_appendf(ds, "%s.rgb", name);
|
2019-04-22 09:32:37 +10:00
|
|
|
}
|
|
|
|
else if (from == GPU_VEC2) {
|
2011-08-30 10:07:50 +00: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) {
|
2011-08-30 10:07:50 +00:00
|
|
|
BLI_dynstr_appendf(ds, "vec3(%s, %s, %s)", name, name, name);
|
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
|
|
|
}
|
2018-06-13 19:24:17 +02:00
|
|
|
else if (to == GPU_VEC4) {
|
2019-04-22 09:32:37 +10:00
|
|
|
if (from == GPU_VEC3) {
|
2011-08-30 10:07:50 +00:00
|
|
|
BLI_dynstr_appendf(ds, "vec4(%s, 1.0)", name);
|
2019-04-22 09:32:37 +10:00
|
|
|
}
|
|
|
|
else if (from == GPU_VEC2) {
|
2011-08-30 10:07:50 +00: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) {
|
2011-08-30 10:07:50 +00:00
|
|
|
BLI_dynstr_appendf(ds, "vec4(%s, %s, %s, 1.0)", name, name, name);
|
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
|
|
|
}
|
2018-06-13 19:24:17 +02:00
|
|
|
else if (to == GPU_CLOSURE) {
|
2019-04-22 09:32:37 +10:00
|
|
|
if (from == GPU_VEC4) {
|
2018-06-13 19:24:17 +02:00
|
|
|
BLI_dynstr_appendf(ds, "closure_emission(%s.rgb)", name);
|
2019-04-22 09:32:37 +10:00
|
|
|
}
|
|
|
|
else if (from == GPU_VEC3) {
|
2018-06-13 19:24:17 +02:00
|
|
|
BLI_dynstr_appendf(ds, "closure_emission(%s.rgb)", name);
|
2019-04-22 09:32:37 +10:00
|
|
|
}
|
|
|
|
else if (from == GPU_VEC2) {
|
2018-06-13 19:24:17 +02:00
|
|
|
BLI_dynstr_appendf(ds, "closure_emission(%s.rrr)", name);
|
2019-04-22 09:32:37 +10:00
|
|
|
}
|
|
|
|
else if (from == GPU_FLOAT) {
|
2018-06-13 19:24:17 +02:00
|
|
|
BLI_dynstr_appendf(ds, "closure_emission(vec3(%s, %s, %s))", name, name, name);
|
2019-04-22 09:32:37 +10:00
|
|
|
}
|
2018-06-13 19:24:17 +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
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
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
|
|
|
|
2015-03-23 15:29:42 -04:00
|
|
|
for (i = 0; i < type; i++) {
|
2017-03-24 12:24:14 +01:00
|
|
|
BLI_dynstr_appendf(ds, "%.12f", data[i]);
|
2019-04-22 09:32:37 +10:00
|
|
|
if (i == type - 1) {
|
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
|
|
|
BLI_dynstr_append(ds, ")");
|
2019-04-22 09:32:37 +10:00
|
|
|
}
|
|
|
|
else {
|
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
|
|
|
BLI_dynstr_append(ds, ", ");
|
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) {
|
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
|
|
|
return "unfviewmat";
|
2019-04-22 09:32:37 +10:00
|
|
|
}
|
2020-08-07 12:39:35 +02:00
|
|
|
if (builtin == GPU_OBJECT_MATRIX) {
|
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
|
|
|
return "unfobmat";
|
2019-04-22 09:32:37 +10:00
|
|
|
}
|
2020-08-07 12:39:35 +02:00
|
|
|
if (builtin == GPU_INVERSE_VIEW_MATRIX) {
|
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
|
|
|
return "unfinvviewmat";
|
2019-04-22 09:32:37 +10:00
|
|
|
}
|
2020-08-07 12:39:35 +02:00
|
|
|
if (builtin == GPU_INVERSE_OBJECT_MATRIX) {
|
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
|
|
|
return "unfinvobmat";
|
2019-04-22 09:32:37 +10:00
|
|
|
}
|
2020-08-07 12:39:35 +02:00
|
|
|
if (builtin == GPU_LOC_TO_VIEW_MATRIX) {
|
Vector Transform node support for GLSL mode and the internal renderer
The Vector Transform node is a useful node which is present in the Cycles renderer.
{F144283}
This patch implements the Vector Transform node for GLSL mode and the internal renderer.
Example: {F273060}
Alexander (Blend4Web Team)
Reviewers: brecht, campbellbarton, sergey
Reviewed By: campbellbarton, sergey
Subscribers: psy-fi, duarteframos, RobM, lightbwk, sergey, AlexKowel, valentin_b4w, Evgeny_Rodygin, yurikovelenov
Projects: #bf_blender:_next
Differential Revision: https://developer.blender.org/D909
2016-01-23 15:27:36 +03:00
|
|
|
return "unflocaltoviewmat";
|
2019-04-22 09:32:37 +10:00
|
|
|
}
|
2020-08-07 12:39:35 +02:00
|
|
|
if (builtin == GPU_INVERSE_LOC_TO_VIEW_MATRIX) {
|
Vector Transform node support for GLSL mode and the internal renderer
The Vector Transform node is a useful node which is present in the Cycles renderer.
{F144283}
This patch implements the Vector Transform node for GLSL mode and the internal renderer.
Example: {F273060}
Alexander (Blend4Web Team)
Reviewers: brecht, campbellbarton, sergey
Reviewed By: campbellbarton, sergey
Subscribers: psy-fi, duarteframos, RobM, lightbwk, sergey, AlexKowel, valentin_b4w, Evgeny_Rodygin, yurikovelenov
Projects: #bf_blender:_next
Differential Revision: https://developer.blender.org/D909
2016-01-23 15:27:36 +03:00
|
|
|
return "unfinvlocaltoviewmat";
|
2019-04-22 09:32:37 +10:00
|
|
|
}
|
2020-08-07 12:39:35 +02:00
|
|
|
if (builtin == GPU_VIEW_POSITION) {
|
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
|
|
|
return "varposition";
|
2019-04-22 09:32:37 +10:00
|
|
|
}
|
2020-08-07 12:39:35 +02:00
|
|
|
if (builtin == GPU_WORLD_NORMAL) {
|
2019-05-08 19:33:54 +02:00
|
|
|
return "varwnormal";
|
|
|
|
}
|
2020-08-07 12:39:35 +02:00
|
|
|
if (builtin == GPU_VIEW_NORMAL) {
|
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
|
|
|
return "varnormal";
|
2019-04-22 09:32:37 +10:00
|
|
|
}
|
2020-08-07 12:39:35 +02:00
|
|
|
if (builtin == GPU_OBJECT_COLOR) {
|
2019-08-22 14:26:09 +02:00
|
|
|
return "unfobjectcolor";
|
2019-04-22 09:32:37 +10:00
|
|
|
}
|
2020-08-07 12:39:35 +02:00
|
|
|
if (builtin == GPU_AUTO_BUMPSCALE) {
|
2011-12-09 23:26:06 +00:00
|
|
|
return "unfobautobumpscale";
|
2019-04-22 09:32:37 +10:00
|
|
|
}
|
2020-08-07 12:39:35 +02:00
|
|
|
if (builtin == GPU_CAMERA_TEXCO_FACTORS) {
|
2015-02-02 14:25:44 +01:00
|
|
|
return "unfcameratexfactors";
|
2019-04-22 09:32:37 +10:00
|
|
|
}
|
2020-08-07 12:39:35 +02:00
|
|
|
if (builtin == GPU_PARTICLE_SCALAR_PROPS) {
|
2016-12-28 17:30:58 +01:00
|
|
|
return "unfparticlescalarprops";
|
2019-04-22 09:32:37 +10:00
|
|
|
}
|
2020-08-07 12:39:35 +02:00
|
|
|
if (builtin == GPU_PARTICLE_LOCATION) {
|
2016-12-28 17:30:58 +01:00
|
|
|
return "unfparticleco";
|
2019-04-22 09:32:37 +10:00
|
|
|
}
|
2020-08-07 12:39:35 +02:00
|
|
|
if (builtin == GPU_PARTICLE_VELOCITY) {
|
2016-12-28 17:30:58 +01:00
|
|
|
return "unfparticlevel";
|
2019-04-22 09:32:37 +10:00
|
|
|
}
|
2020-08-07 12:39:35 +02:00
|
|
|
if (builtin == GPU_PARTICLE_ANG_VELOCITY) {
|
2016-12-28 17:30:58 +01:00
|
|
|
return "unfparticleangvel";
|
2019-04-22 09:32:37 +10:00
|
|
|
}
|
2020-08-07 12:39:35 +02:00
|
|
|
if (builtin == GPU_OBJECT_INFO) {
|
2017-04-14 18:13:44 +03:00
|
|
|
return "unfobjectinfo";
|
2019-04-22 09:32:37 +10:00
|
|
|
}
|
2020-08-07 12:39:35 +02:00
|
|
|
if (builtin == GPU_BARYCENTRIC_TEXCO) {
|
2018-08-20 17:59:21 +02:00
|
|
|
return "unfbarycentrictex";
|
2019-04-22 09:32:37 +10:00
|
|
|
}
|
2020-08-07 12:39:35 +02:00
|
|
|
if (builtin == GPU_BARYCENTRIC_DIST) {
|
2018-09-20 17:41:07 +02:00
|
|
|
return "unfbarycentricdist";
|
2019-04-22 09:32:37 +10:00
|
|
|
}
|
2020-08-07 12:39:35 +02:00
|
|
|
return "";
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
}
|
|
|
|
|
2020-02-27 13:55:29 +01:00
|
|
|
static void codegen_set_unique_ids(GPUNodeGraph *graph)
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
{
|
2020-02-14 10:47:20 +01:00
|
|
|
int id = 1;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-07-25 18:48:57 +02:00
|
|
|
LISTBASE_FOREACH (GPUNode *, node, &graph->nodes) {
|
|
|
|
LISTBASE_FOREACH (GPUInput *, input, &node->inputs) {
|
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
|
|
|
/* set id for unique names of uniform variables */
|
|
|
|
input->id = id++;
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-07-25 18:48:57 +02:00
|
|
|
LISTBASE_FOREACH (GPUOutput *, output, &node->outputs) {
|
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
|
|
|
/* set id for unique names of tmp variables storing output */
|
|
|
|
output->id = id++;
|
2018-08-13 18:44:27 +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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-14 17:40:54 +02:00
|
|
|
/**
|
|
|
|
* It will create an UBO for GPUMaterial if there is any GPU_DYNAMIC_UBO.
|
|
|
|
*/
|
2020-02-27 13:55:29 +01:00
|
|
|
static int codegen_process_uniforms_functions(GPUMaterial *material,
|
|
|
|
DynStr *ds,
|
|
|
|
GPUNodeGraph *graph)
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
{
|
2010-12-03 17:05:21 +00:00
|
|
|
const char *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
|
|
|
int builtins = 0;
|
2017-07-14 17:40:54 +02:00
|
|
|
ListBase ubo_inputs = {NULL, NULL};
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-02-27 13:55:29 +01:00
|
|
|
/* Textures */
|
2020-04-03 19:15:01 +02:00
|
|
|
LISTBASE_FOREACH (GPUMaterialTexture *, tex, &graph->textures) {
|
2020-02-27 13:55:29 +01:00
|
|
|
if (tex->colorband) {
|
|
|
|
BLI_dynstr_appendf(ds, "uniform sampler1DArray %s;\n", tex->sampler_name);
|
|
|
|
}
|
|
|
|
else if (tex->tiled_mapping_name[0]) {
|
|
|
|
BLI_dynstr_appendf(ds, "uniform sampler2DArray %s;\n", tex->sampler_name);
|
|
|
|
BLI_dynstr_appendf(ds, "uniform sampler1DArray %s;\n", tex->tiled_mapping_name);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
BLI_dynstr_appendf(ds, "uniform sampler2D %s;\n", tex->sampler_name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-11 14:58:19 +01:00
|
|
|
/* Volume Grids */
|
2020-04-03 19:15:01 +02:00
|
|
|
LISTBASE_FOREACH (GPUMaterialVolumeGrid *, grid, &graph->volume_grids) {
|
2020-03-11 14:58:19 +01:00
|
|
|
BLI_dynstr_appendf(ds, "uniform sampler3D %s;\n", grid->sampler_name);
|
2020-03-17 16:27:08 +01:00
|
|
|
BLI_dynstr_appendf(ds, "uniform mat4 %s = mat4(0.0);\n", grid->transform_name);
|
2020-03-11 14:58:19 +01:00
|
|
|
}
|
|
|
|
|
2020-02-27 13:55:29 +01:00
|
|
|
/* Print other uniforms */
|
2020-07-25 18:48:57 +02:00
|
|
|
|
|
|
|
LISTBASE_FOREACH (GPUNode *, node, &graph->nodes) {
|
|
|
|
LISTBASE_FOREACH (GPUInput *, input, &node->inputs) {
|
2020-02-27 13:55:29 +01:00
|
|
|
if (input->source == GPU_SOURCE_BUILTIN) {
|
2015-11-23 00:13:57 -05:00
|
|
|
/* only define each builtin uniform/varying once */
|
2012-03-24 06:38:07 +00:00
|
|
|
if (!(builtins & input->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
|
|
|
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-03-11 14:58:19 +01:00
|
|
|
if (BLI_str_startswith(name, "unf")) {
|
2020-02-12 12:48:44 +01:00
|
|
|
BLI_dynstr_appendf(ds, "uniform %s %s;\n", gpu_data_type_to_string(input->type), 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
|
|
|
}
|
|
|
|
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);
|
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-09-14 01:02:10 +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);
|
|
|
|
}
|
2018-08-13 18:44:27 +02:00
|
|
|
else if (input->source == GPU_SOURCE_UNIFORM) {
|
|
|
|
if (!input->link) {
|
|
|
|
/* We handle the UBOuniforms separately. */
|
|
|
|
BLI_addtail(&ubo_inputs, BLI_genericNodeN(input));
|
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
|
|
|
}
|
2018-08-13 18:44:27 +02:00
|
|
|
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);
|
2018-08-13 18:44:27 +02:00
|
|
|
codegen_print_datatype(ds, input->type, input->vec);
|
|
|
|
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
|
|
|
|
2017-07-14 17:40:54 +02:00
|
|
|
/* Handle the UBO block separately. */
|
|
|
|
if ((material != NULL) && !BLI_listbase_is_empty(&ubo_inputs)) {
|
2018-06-07 19:40:47 +02:00
|
|
|
GPU_material_uniform_buffer_create(material, &ubo_inputs);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2017-07-14 17:40:54 +02:00
|
|
|
/* Inputs are sorted */
|
|
|
|
BLI_dynstr_appendf(ds, "\nlayout (std140) uniform %s {\n", GPU_UBO_BLOCK_NAME);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-04-03 19:15:01 +02:00
|
|
|
LISTBASE_FOREACH (LinkData *, link, &ubo_inputs) {
|
2020-07-25 18:48:57 +02:00
|
|
|
GPUInput *input = (GPUInput *)(link->data);
|
2020-07-30 13:55:13 +02:00
|
|
|
BLI_dynstr_appendf(ds, " %s unf%d;\n", gpu_data_type_to_string(input->type), input->id);
|
2017-07-14 17:40:54 +02:00
|
|
|
}
|
|
|
|
BLI_dynstr_append(ds, "};\n");
|
|
|
|
BLI_freelistN(&ubo_inputs);
|
|
|
|
}
|
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
|
|
|
BLI_dynstr_append(ds, "\n");
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-06-24 13:46:34 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2020-02-27 13:55:29 +01:00
|
|
|
static void codegen_declare_tmps(DynStr *ds, GPUNodeGraph *graph)
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
{
|
2020-07-25 18:48:57 +02:00
|
|
|
LISTBASE_FOREACH (GPUNode *, node, &graph->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
|
|
|
/* declare temporary variables for node output storage */
|
2020-07-25 18:48:57 +02:00
|
|
|
LISTBASE_FOREACH (GPUOutput *, output, &node->outputs) {
|
2017-09-14 01:02:10 +02:00
|
|
|
if (output->type == GPU_CLOSURE) {
|
2020-07-30 13:55:13 +02:00
|
|
|
BLI_dynstr_appendf(ds, " Closure tmp%d;\n", output->id);
|
2017-09-14 01:02:10 +02:00
|
|
|
}
|
|
|
|
else {
|
2020-07-30 13:55:13 +02:00
|
|
|
BLI_dynstr_appendf(ds, " %s tmp%d;\n", gpu_data_type_to_string(output->type), output->id);
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2017-09-14 01:02:10 +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
|
|
|
}
|
|
|
|
BLI_dynstr_append(ds, "\n");
|
|
|
|
}
|
|
|
|
|
2020-02-27 13:55:29 +01:00
|
|
|
static void codegen_call_functions(DynStr *ds, GPUNodeGraph *graph, GPUOutput *finaloutput)
|
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-07-25 18:48:57 +02:00
|
|
|
LISTBASE_FOREACH (GPUNode *, node, &graph->nodes) {
|
2020-07-30 13:55:13 +02:00
|
|
|
BLI_dynstr_appendf(ds, " %s(", node->name);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-07-25 18:48:57 +02:00
|
|
|
LISTBASE_FOREACH (GPUInput *, input, &node->inputs) {
|
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
|
|
|
if (input->source == GPU_SOURCE_TEX) {
|
2020-02-27 13:55:29 +01:00
|
|
|
BLI_dynstr_append(ds, input->texture->sampler_name);
|
|
|
|
}
|
|
|
|
else if (input->source == GPU_SOURCE_TEX_TILED_MAPPING) {
|
|
|
|
BLI_dynstr_append(ds, input->texture->tiled_mapping_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
|
|
|
}
|
2020-03-11 14:58:19 +01:00
|
|
|
else if (input->source == GPU_SOURCE_VOLUME_GRID) {
|
|
|
|
BLI_dynstr_append(ds, input->volume_grid->sampler_name);
|
|
|
|
}
|
2020-03-17 16:27:08 +01:00
|
|
|
else if (input->source == GPU_SOURCE_VOLUME_GRID_TRANSFORM) {
|
|
|
|
BLI_dynstr_append(ds, input->volume_grid->transform_name);
|
|
|
|
}
|
2018-08-13 18:44:27 +02:00
|
|
|
else if (input->source == GPU_SOURCE_OUTPUT) {
|
2018-07-18 23:09:31 +10:00
|
|
|
codegen_convert_datatype(
|
|
|
|
ds, input->link->output->type, input->type, "tmp", input->link->output->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
|
|
|
}
|
2013-06-24 13:46:34 +00:00
|
|
|
else if (input->source == GPU_SOURCE_BUILTIN) {
|
2020-09-19 14:32:41 +10:00
|
|
|
/* TODO(fclem): get rid of that. */
|
2019-04-22 09:32:37 +10:00
|
|
|
if (input->builtin == GPU_INVERSE_VIEW_MATRIX) {
|
2017-05-01 18:09:50 +02:00
|
|
|
BLI_dynstr_append(ds, "viewinv");
|
2019-04-22 09:32:37 +10:00
|
|
|
}
|
|
|
|
else if (input->builtin == GPU_VIEW_MATRIX) {
|
2017-06-01 13:22:30 +02:00
|
|
|
BLI_dynstr_append(ds, "viewmat");
|
2019-04-22 09:32:37 +10:00
|
|
|
}
|
|
|
|
else if (input->builtin == GPU_CAMERA_TEXCO_FACTORS) {
|
2017-05-07 15:22:25 +02:00
|
|
|
BLI_dynstr_append(ds, "camtexfac");
|
2019-04-22 09:32:37 +10:00
|
|
|
}
|
|
|
|
else if (input->builtin == GPU_LOC_TO_VIEW_MATRIX) {
|
2018-11-08 21:50:17 +01:00
|
|
|
BLI_dynstr_append(ds, "localtoviewmat");
|
2019-04-22 09:32:37 +10:00
|
|
|
}
|
|
|
|
else if (input->builtin == GPU_INVERSE_LOC_TO_VIEW_MATRIX) {
|
2018-11-08 21:50:17 +01:00
|
|
|
BLI_dynstr_append(ds, "invlocaltoviewmat");
|
2019-04-22 09:32:37 +10:00
|
|
|
}
|
|
|
|
else if (input->builtin == GPU_BARYCENTRIC_DIST) {
|
2018-09-20 17:41:07 +02:00
|
|
|
BLI_dynstr_append(ds, "barycentricDist");
|
2019-04-22 09:32:37 +10:00
|
|
|
}
|
|
|
|
else if (input->builtin == GPU_BARYCENTRIC_TEXCO) {
|
2018-08-20 17:59:21 +02:00
|
|
|
BLI_dynstr_append(ds, "barytexco");
|
2019-04-22 09:32:37 +10:00
|
|
|
}
|
|
|
|
else if (input->builtin == GPU_OBJECT_MATRIX) {
|
2017-05-18 14:29:57 +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) {
|
2017-05-04 17:39:50 +02:00
|
|
|
BLI_dynstr_append(ds, "objinv");
|
2019-04-22 09:32:37 +10:00
|
|
|
}
|
|
|
|
else if (input->builtin == GPU_VIEW_POSITION) {
|
2017-05-01 18:09:50 +02:00
|
|
|
BLI_dynstr_append(ds, "viewposition");
|
2019-04-22 09:32:37 +10:00
|
|
|
}
|
|
|
|
else if (input->builtin == GPU_VIEW_NORMAL) {
|
2013-06-24 13:46:34 +00: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
|
|
|
}
|
2013-06-24 13:46:34 +00:00
|
|
|
}
|
2017-09-14 01:02:10 +02:00
|
|
|
else if (input->source == GPU_SOURCE_STRUCT) {
|
|
|
|
BLI_dynstr_appendf(ds, "strct%d", input->id);
|
|
|
|
}
|
2018-08-13 18:44:27 +02:00
|
|
|
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);
|
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
|
|
|
else if (input->source == GPU_SOURCE_ATTR) {
|
2020-08-04 17:56:39 +03:00
|
|
|
codegen_convert_datatype(ds, input->attr->gputype, input->type, "var", input->attr->id);
|
2014-04-02 15:07:45 +03: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
|
|
|
BLI_dynstr_append(ds, ", ");
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-07-25 18:48:57 +02:00
|
|
|
LISTBASE_FOREACH (GPUOutput *, output, &node->outputs) {
|
2011-08-30 10:07:50 +00:00
|
|
|
BLI_dynstr_appendf(ds, "tmp%d", output->id);
|
2019-04-22 09:32:37 +10:00
|
|
|
if (output->next) {
|
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
|
|
|
BLI_dynstr_append(ds, ", ");
|
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
|
|
|
}
|
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
|
|
|
BLI_dynstr_append(ds, ");\n");
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-07-30 13:55:13 +02:00
|
|
|
BLI_dynstr_appendf(ds, "\n return tmp%d;\n", finaloutput->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
|
|
|
}
|
|
|
|
|
2020-07-30 13:55:13 +02:00
|
|
|
static char *code_generate_fragment(GPUMaterial *material,
|
|
|
|
GPUNodeGraph *graph,
|
|
|
|
const char *interface_str)
|
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
|
|
|
{
|
|
|
|
DynStr *ds = BLI_dynstr_new();
|
|
|
|
char *code;
|
2013-06-24 13:46:34 +00:00
|
|
|
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
|
|
|
|
2020-02-27 13:55:29 +01:00
|
|
|
codegen_set_unique_ids(graph);
|
2020-07-30 13:55:13 +02:00
|
|
|
|
|
|
|
/* Attributes, Shader stage interface. */
|
|
|
|
if (interface_str) {
|
|
|
|
BLI_dynstr_appendf(ds, "in codegenInterface {%s};\n\n", interface_str);
|
|
|
|
}
|
|
|
|
|
2020-02-27 13:55:29 +01:00
|
|
|
builtins = codegen_process_uniforms_functions(material, ds, graph);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
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) {
|
2020-07-30 13:55:13 +02:00
|
|
|
BLI_dynstr_append(ds, datatoc_gpu_shader_codegen_lib_glsl);
|
2019-04-22 09:32:37 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2017-07-03 21:39:52 +02:00
|
|
|
BLI_dynstr_append(ds, "Closure nodetree_exec(void)\n{\n");
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-08-20 17:59:21 +02:00
|
|
|
if (builtins & GPU_BARYCENTRIC_TEXCO) {
|
2020-07-30 13:55:13 +02:00
|
|
|
BLI_dynstr_append(ds, " vec2 barytexco = barycentric_resolve(barycentricTexCo);\n");
|
2018-08-20 17:59:21 +02:00
|
|
|
}
|
2020-09-19 14:32:41 +10:00
|
|
|
/* TODO(fclem): get rid of that. */
|
2019-04-22 09:32:37 +10:00
|
|
|
if (builtins & GPU_VIEW_MATRIX) {
|
2020-07-30 13:55:13 +02:00
|
|
|
BLI_dynstr_append(ds, " #define viewmat ViewMatrix\n");
|
2019-04-22 09:32:37 +10:00
|
|
|
}
|
|
|
|
if (builtins & GPU_CAMERA_TEXCO_FACTORS) {
|
2020-07-30 13:55:13 +02:00
|
|
|
BLI_dynstr_append(ds, " #define camtexfac CameraTexCoFactors\n");
|
2019-04-22 09:32:37 +10:00
|
|
|
}
|
|
|
|
if (builtins & GPU_OBJECT_MATRIX) {
|
2020-07-30 13:55:13 +02:00
|
|
|
BLI_dynstr_append(ds, " #define objmat ModelMatrix\n");
|
2019-04-22 09:32:37 +10:00
|
|
|
}
|
|
|
|
if (builtins & GPU_INVERSE_OBJECT_MATRIX) {
|
2020-07-30 13:55:13 +02:00
|
|
|
BLI_dynstr_append(ds, " #define objinv ModelMatrixInverse\n");
|
2019-04-22 09:32:37 +10:00
|
|
|
}
|
|
|
|
if (builtins & GPU_INVERSE_VIEW_MATRIX) {
|
2020-07-30 13:55:13 +02:00
|
|
|
BLI_dynstr_append(ds, " #define viewinv ViewMatrixInverse\n");
|
2019-04-22 09:32:37 +10:00
|
|
|
}
|
|
|
|
if (builtins & GPU_LOC_TO_VIEW_MATRIX) {
|
2020-07-30 13:55:13 +02:00
|
|
|
BLI_dynstr_append(ds, " #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,
|
2020-07-30 13:55:13 +02:00
|
|
|
" #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");
|
2020-07-30 13:55:13 +02:00
|
|
|
BLI_dynstr_append(ds, " vec3 n;\n");
|
|
|
|
BLI_dynstr_append(ds, " world_normals_get(n);\n");
|
|
|
|
BLI_dynstr_append(ds, " vec3 facingnormal = transform_direction(ViewMatrix, n);\n");
|
2019-05-02 14:32:12 +02:00
|
|
|
BLI_dynstr_append(ds, "#else\n");
|
2020-07-30 13:55:13 +02:00
|
|
|
BLI_dynstr_append(ds, " vec3 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) {
|
2020-07-30 13:55:13 +02:00
|
|
|
BLI_dynstr_append(ds, " vec3 facingwnormal;\n");
|
2019-05-08 19:33:54 +02:00
|
|
|
if (builtins & GPU_VIEW_NORMAL) {
|
|
|
|
BLI_dynstr_append(ds, "#ifdef HAIR_SHADER\n");
|
2020-07-30 13:55:13 +02:00
|
|
|
BLI_dynstr_append(ds, " facingwnormal = n;\n");
|
2019-05-08 19:33:54 +02:00
|
|
|
BLI_dynstr_append(ds, "#else\n");
|
2020-07-30 13:55:13 +02:00
|
|
|
BLI_dynstr_append(ds, " world_normals_get(facingwnormal);\n");
|
2019-05-08 19:33:54 +02:00
|
|
|
BLI_dynstr_append(ds, "#endif\n");
|
|
|
|
}
|
|
|
|
else {
|
2020-07-30 13:55:13 +02:00
|
|
|
BLI_dynstr_append(ds, " world_normals_get(facingwnormal);\n");
|
2019-05-08 19:33:54 +02:00
|
|
|
}
|
|
|
|
}
|
2019-04-22 09:32:37 +10:00
|
|
|
if (builtins & GPU_VIEW_POSITION) {
|
2020-07-30 13:55:13 +02:00
|
|
|
BLI_dynstr_append(ds, " #define viewposition viewPosition\n");
|
2019-04-22 09:32:37 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-02-27 13:55:29 +01:00
|
|
|
codegen_declare_tmps(ds, graph);
|
|
|
|
codegen_call_functions(ds, graph, graph->outlink->output);
|
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
|
|
|
BLI_dynstr_append(ds, "}\n");
|
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
|
|
|
/* create shader */
|
|
|
|
code = BLI_dynstr_get_cstring(ds);
|
|
|
|
BLI_dynstr_free(ds);
|
|
|
|
|
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
|
|
|
|
|
|
|
return code;
|
|
|
|
}
|
|
|
|
|
2019-01-29 07:46:25 +11:00
|
|
|
static const char *attr_prefix_get(CustomDataType type)
|
2017-05-01 18:09:50 +02:00
|
|
|
{
|
|
|
|
switch (type) {
|
|
|
|
case CD_ORCO:
|
|
|
|
return "orco";
|
|
|
|
case CD_MTFACE:
|
|
|
|
return "u";
|
|
|
|
case CD_TANGENT:
|
|
|
|
return "t";
|
|
|
|
case CD_MCOL:
|
|
|
|
return "c";
|
2020-07-15 18:52:01 +02:00
|
|
|
case CD_PROP_COLOR:
|
|
|
|
return "c";
|
2017-05-01 18:09:50 +02:00
|
|
|
case CD_AUTO_FROM_NAME:
|
|
|
|
return "a";
|
2018-07-18 00:12:21 +02:00
|
|
|
default:
|
|
|
|
BLI_assert(false && "GPUVertAttr Prefix type not found : This should not happen!");
|
|
|
|
return "";
|
2017-05-01 18:09:50 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-30 13:55:13 +02:00
|
|
|
/* We talk about shader stage interface, not to be mistaken with GPUShaderInterface. */
|
|
|
|
static char *code_generate_interface(GPUNodeGraph *graph, int builtins)
|
2017-05-01 18:09:50 +02:00
|
|
|
{
|
2020-07-30 13:55:13 +02:00
|
|
|
if (BLI_listbase_is_empty(&graph->attributes) &&
|
|
|
|
(builtins & (GPU_BARYCENTRIC_DIST | GPU_BARYCENTRIC_TEXCO)) == 0) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2017-05-01 18:09:50 +02:00
|
|
|
DynStr *ds = BLI_dynstr_new();
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-07-30 13:55:13 +02:00
|
|
|
BLI_dynstr_append(ds, "\n");
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-04-03 19:15:01 +02:00
|
|
|
LISTBASE_FOREACH (GPUMaterialAttribute *, attr, &graph->attributes) {
|
2020-07-30 13:55:13 +02:00
|
|
|
BLI_dynstr_appendf(ds, "%s var%d;\n", gpu_data_type_to_string(attr->gputype), attr->id);
|
|
|
|
}
|
|
|
|
if (builtins & GPU_BARYCENTRIC_TEXCO) {
|
|
|
|
BLI_dynstr_append(ds, "vec2 barycentricTexCo;\n");
|
|
|
|
}
|
|
|
|
if (builtins & GPU_BARYCENTRIC_DIST) {
|
|
|
|
BLI_dynstr_append(ds, "vec3 barycentricDist;\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
char *code = BLI_dynstr_get_cstring(ds);
|
|
|
|
|
|
|
|
BLI_dynstr_free(ds);
|
|
|
|
|
|
|
|
return code;
|
|
|
|
}
|
|
|
|
|
|
|
|
static char *code_generate_vertex(GPUNodeGraph *graph,
|
|
|
|
const char *interface_str,
|
|
|
|
const char *vert_code,
|
|
|
|
int builtins)
|
|
|
|
{
|
|
|
|
DynStr *ds = BLI_dynstr_new();
|
|
|
|
|
|
|
|
BLI_dynstr_append(ds, datatoc_gpu_shader_codegen_lib_glsl);
|
|
|
|
|
|
|
|
/* Inputs */
|
|
|
|
LISTBASE_FOREACH (GPUMaterialAttribute *, attr, &graph->attributes) {
|
|
|
|
const char *type_str = gpu_data_type_to_string(attr->gputype);
|
|
|
|
const char *prefix = attr_prefix_get(attr->type);
|
2020-02-27 13:55:29 +01:00
|
|
|
/* XXX FIXME : see notes in mesh_render_data_create() */
|
|
|
|
/* NOTE : Replicate changes to mesh_render_data_create() in draw_cache_impl_mesh.c */
|
|
|
|
if (attr->type == CD_ORCO) {
|
|
|
|
/* OPTI : orco is computed from local positions, but only if no modifier is present. */
|
|
|
|
BLI_dynstr_append(ds, datatoc_gpu_shader_common_obinfos_lib_glsl);
|
|
|
|
BLI_dynstr_append(ds, "DEFINE_ATTR(vec4, orco);\n");
|
|
|
|
}
|
|
|
|
else if (attr->name[0] == '\0') {
|
2020-07-30 13:55:13 +02:00
|
|
|
BLI_dynstr_appendf(ds, "DEFINE_ATTR(%s, %s);\n", type_str, prefix);
|
|
|
|
BLI_dynstr_appendf(ds, "#define att%d %s\n", attr->id, prefix);
|
2020-02-27 13:55:29 +01:00
|
|
|
}
|
|
|
|
else {
|
2020-04-03 16:59:34 +11:00
|
|
|
char attr_safe_name[GPU_MAX_SAFE_ATTR_NAME];
|
|
|
|
GPU_vertformat_safe_attr_name(attr->name, attr_safe_name, GPU_MAX_SAFE_ATTR_NAME);
|
2020-07-30 13:55:13 +02:00
|
|
|
BLI_dynstr_appendf(ds, "DEFINE_ATTR(%s, %s%s);\n", type_str, prefix, attr_safe_name);
|
|
|
|
BLI_dynstr_appendf(ds, "#define att%d %s%s\n", attr->id, prefix, attr_safe_name);
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-30 13:55:13 +02:00
|
|
|
/* Outputs interface */
|
|
|
|
if (interface_str) {
|
|
|
|
BLI_dynstr_appendf(ds, "out codegenInterface {%s};\n\n", interface_str);
|
2018-09-20 17:41:07 +02:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-07-30 13:55:13 +02:00
|
|
|
/* Prototype. Needed for hair functions. */
|
|
|
|
BLI_dynstr_append(ds, "void pass_attr(vec3 position, mat3 normalmat, mat4 modelmatinv);\n");
|
|
|
|
BLI_dynstr_append(ds, "#define USE_ATTR\n\n");
|
2019-05-14 00:48:17 +02:00
|
|
|
|
2020-07-30 13:55:13 +02:00
|
|
|
BLI_dynstr_append(ds, vert_code);
|
2020-09-01 00:52:57 +02:00
|
|
|
BLI_dynstr_append(ds, "\n\n");
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-07-30 13:55:13 +02:00
|
|
|
BLI_dynstr_append(ds, "void pass_attr(vec3 position, mat3 normalmat, mat4 modelmatinv) {\n");
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-02-28 13:56:03 +01:00
|
|
|
/* 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. */
|
2020-07-30 13:55:13 +02:00
|
|
|
if (builtins & GPU_BARYCENTRIC_TEXCO) {
|
|
|
|
BLI_dynstr_appendf(ds, " barycentricTexCo = barycentric_get();\n");
|
|
|
|
}
|
2018-09-20 17:41:07 +02:00
|
|
|
if (builtins & GPU_BARYCENTRIC_DIST) {
|
2020-07-30 13:55:13 +02:00
|
|
|
BLI_dynstr_appendf(ds, " barycentricDist = vec3(0);\n");
|
2018-09-20 17:41:07 +02:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-04-03 19:15:01 +02:00
|
|
|
LISTBASE_FOREACH (GPUMaterialAttribute *, attr, &graph->attributes) {
|
2020-02-27 13:55:29 +01:00
|
|
|
if (attr->type == CD_TANGENT) { /* silly exception */
|
2020-07-30 13:55:13 +02:00
|
|
|
BLI_dynstr_appendf(ds, " var%d = tangent_get(att%d, normalmat);\n", attr->id, attr->id);
|
2020-02-27 13:55:29 +01:00
|
|
|
}
|
|
|
|
else if (attr->type == CD_ORCO) {
|
2020-07-30 13:55:13 +02:00
|
|
|
BLI_dynstr_appendf(
|
|
|
|
ds, " var%d = orco_get(position, modelmatinv, OrcoTexCoFactors, orco);\n", attr->id);
|
2020-02-27 13:55:29 +01:00
|
|
|
}
|
|
|
|
else {
|
2020-07-30 13:55:13 +02:00
|
|
|
const char *type_str = gpu_data_type_to_string(attr->gputype);
|
|
|
|
BLI_dynstr_appendf(ds, " var%d = GET_ATTR(%s, att%d);\n", attr->id, type_str, attr->id);
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-01 18:09:50 +02:00
|
|
|
BLI_dynstr_append(ds, "}\n");
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-07-30 13:55:13 +02:00
|
|
|
char *code = BLI_dynstr_get_cstring(ds);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2017-05-01 18:09:50 +02:00
|
|
|
BLI_dynstr_free(ds);
|
|
|
|
|
|
|
|
#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
|
|
|
|
|
|
|
|
return code;
|
|
|
|
}
|
|
|
|
|
2020-02-27 13:55:29 +01:00
|
|
|
static char *code_generate_geometry(GPUNodeGraph *graph,
|
2020-07-30 13:55:13 +02:00
|
|
|
const char *interface_str,
|
2020-02-27 13:55:29 +01:00
|
|
|
const char *geom_code,
|
2020-07-30 13:55:13 +02:00
|
|
|
int builtins)
|
2017-06-28 21:05:43 +02:00
|
|
|
{
|
2020-07-30 13:55:13 +02:00
|
|
|
if (!geom_code) {
|
|
|
|
return NULL;
|
2017-06-28 21:05:43 +02:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-07-30 13:55:13 +02:00
|
|
|
DynStr *ds = BLI_dynstr_new();
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-07-30 13:55:13 +02:00
|
|
|
/* Attributes, Shader interface; */
|
|
|
|
if (interface_str) {
|
|
|
|
BLI_dynstr_appendf(ds, "in codegenInterface {%s} dataAttrIn[];\n\n", interface_str);
|
|
|
|
BLI_dynstr_appendf(ds, "out codegenInterface {%s} dataAttrOut;\n\n", interface_str);
|
2018-09-20 17:41:07 +02:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-07-30 13:55:13 +02:00
|
|
|
BLI_dynstr_append(ds, datatoc_gpu_shader_codegen_lib_glsl);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-09-20 17:41:07 +02:00
|
|
|
if (builtins & GPU_BARYCENTRIC_DIST) {
|
2020-07-30 13:55:13 +02:00
|
|
|
/* geom_code should do something with this, but may not. */
|
|
|
|
BLI_dynstr_append(ds, "#define DO_BARYCENTRIC_DISTANCES\n");
|
2018-08-21 16:07:13 +02:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2017-06-28 21:05:43 +02:00
|
|
|
/* Generate varying assignments. */
|
2020-07-30 13:55:13 +02:00
|
|
|
BLI_dynstr_append(ds, "#define USE_ATTR\n");
|
2020-09-01 00:52:57 +02:00
|
|
|
/* This needs to be a define. Some drivers don't like variable vert index inside dataAttrIn. */
|
|
|
|
BLI_dynstr_append(ds, "#define pass_attr(vert) {\\\n");
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-08-21 16:07:13 +02:00
|
|
|
if (builtins & GPU_BARYCENTRIC_TEXCO) {
|
2020-09-01 00:52:57 +02:00
|
|
|
BLI_dynstr_append(ds, "dataAttrOut.barycentricTexCo = calc_barycentric_co(vert);\\\n");
|
2018-08-21 16:07:13 +02:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-04-03 19:15:01 +02:00
|
|
|
LISTBASE_FOREACH (GPUMaterialAttribute *, attr, &graph->attributes) {
|
2020-02-27 13:55:29 +01:00
|
|
|
/* TODO let shader choose what to do depending on what the attribute is. */
|
2020-09-01 00:52:57 +02:00
|
|
|
BLI_dynstr_appendf(ds, "dataAttrOut.var%d = dataAttrIn[vert].var%d;\\\n", attr->id, attr->id);
|
2017-06-28 21:05:43 +02:00
|
|
|
}
|
2020-07-30 13:55:13 +02:00
|
|
|
BLI_dynstr_append(ds, "}\n\n");
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-07-30 13:55:13 +02:00
|
|
|
BLI_dynstr_append(ds, geom_code);
|
|
|
|
|
|
|
|
char *code = BLI_dynstr_get_cstring(ds);
|
2017-06-28 21:05:43 +02:00
|
|
|
BLI_dynstr_free(ds);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2017-06-28 21:05:43 +02:00
|
|
|
return code;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
|
|
|
return pass->shader;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Pass create/free */
|
|
|
|
|
2018-06-07 11:58:15 +02:00
|
|
|
static bool gpu_pass_is_valid(GPUPass *pass)
|
|
|
|
{
|
2018-08-08 12:18:02 +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
|
|
|
}
|
|
|
|
|
2018-09-19 19:34:00 +02:00
|
|
|
GPUPass *GPU_generate_pass(GPUMaterial *material,
|
2020-02-12 12:48:44 +01:00
|
|
|
GPUNodeGraph *graph,
|
2018-06-07 11:58:15 +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
|
|
|
{
|
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);
|
2020-02-14 10:47:20 +01:00
|
|
|
|
2020-07-30 13:55:13 +02:00
|
|
|
int builtins = 0;
|
|
|
|
LISTBASE_FOREACH (GPUNode *, node, &graph->nodes) {
|
|
|
|
LISTBASE_FOREACH (GPUInput *, input, &node->inputs) {
|
|
|
|
if (input->source == GPU_SOURCE_BUILTIN) {
|
|
|
|
builtins |= input->builtin;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-03-11 23:43:09 +01:00
|
|
|
/* generate code */
|
2020-07-30 13:55:13 +02:00
|
|
|
char *interface_str = code_generate_interface(graph, builtins);
|
|
|
|
char *fragmentgen = code_generate_fragment(material, graph, interface_str);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-06-07 11:58:15 +02:00
|
|
|
/* Cache lookup: Reuse shaders already compiled */
|
2020-02-14 10:47:20 +01:00
|
|
|
uint32_t hash = gpu_pass_hash(fragmentgen, defines, &graph->attributes);
|
|
|
|
GPUPass *pass_hash = gpu_pass_cache_lookup(hash);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-06-07 11:58:15 +02:00
|
|
|
if (pass_hash && (pass_hash->next == NULL || pass_hash->next->hash != hash)) {
|
|
|
|
/* No collision, just return the pass. */
|
2020-07-30 13:55:13 +02:00
|
|
|
MEM_SAFE_FREE(interface_str);
|
2018-06-07 11:58:15 +02:00
|
|
|
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;
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-06-07 11:58:15 +02:00
|
|
|
/* 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-07-30 13:55:13 +02:00
|
|
|
char *geometrycode = code_generate_geometry(graph, interface_str, geom_code, builtins);
|
|
|
|
char *vertexcode = code_generate_vertex(graph, interface_str, vert_code, builtins);
|
2020-02-14 10:47:20 +01:00
|
|
|
char *fragmentcode = BLI_strdupcat(tmp, fragmentgen);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-07-30 13:55:13 +02:00
|
|
|
MEM_SAFE_FREE(interface_str);
|
2018-03-11 23:43:09 +01:00
|
|
|
MEM_freeN(fragmentgen);
|
2017-04-27 22:27:09 +02:00
|
|
|
MEM_freeN(tmp);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-02-14 10:47:20 +01:00
|
|
|
GPUPass *pass = NULL;
|
2018-06-07 11:58:15 +02:00
|
|
|
if (pass_hash) {
|
|
|
|
/* Cache lookup: Reuse shaders already compiled */
|
|
|
|
pass = gpu_pass_cache_resolve_collision(
|
|
|
|
pass_hash, vertexcode, geometrycode, fragmentcode, defines, hash);
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-03-11 23:43:09 +01:00
|
|
|
if (pass) {
|
2020-02-14 10:47:20 +01:00
|
|
|
MEM_SAFE_FREE(vertexcode);
|
|
|
|
MEM_SAFE_FREE(fragmentcode);
|
|
|
|
MEM_SAFE_FREE(geometrycode);
|
|
|
|
|
2018-03-11 23:43:09 +01:00
|
|
|
/* Cache hit. Reuse the same GPUPass and GPUShader. */
|
2018-06-07 11:58:15 +02:00
|
|
|
if (!gpu_pass_is_valid(pass)) {
|
|
|
|
/* Shader has already been created but failed to compile. */
|
|
|
|
return NULL;
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-06-07 11:58:15 +02:00
|
|
|
pass->refcount += 1;
|
2018-03-11 23:43:09 +01:00
|
|
|
}
|
|
|
|
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");
|
2018-06-07 11:58:15 +02:00
|
|
|
pass->shader = NULL;
|
2018-03-11 23:43:09 +01:00
|
|
|
pass->refcount = 1;
|
|
|
|
pass->hash = hash;
|
|
|
|
pass->vertexcode = vertexcode;
|
|
|
|
pass->fragmentcode = fragmentcode;
|
|
|
|
pass->geometrycode = geometrycode;
|
|
|
|
pass->defines = (defines) ? BLI_strdup(defines) : NULL;
|
2018-06-07 11:58:15 +02:00
|
|
|
pass->compiled = false;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-06-07 11:58:15 +02:00
|
|
|
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);
|
2018-03-11 23:43:09 +01:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-06-07 11:58:15 +02:00
|
|
|
return pass;
|
|
|
|
}
|
|
|
|
|
2018-09-18 14:22:42 +02:00
|
|
|
static int count_active_texture_sampler(GPUShader *shader, char *source)
|
|
|
|
{
|
|
|
|
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
|
|
|
|
2018-09-19 10:29:57 +10:00
|
|
|
while ((code = strstr(code, "uniform "))) {
|
2018-09-18 14:22:42 +02:00
|
|
|
/* 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")) {
|
2018-09-18 14:22:42 +02:00
|
|
|
/* Move past "uniform". */
|
|
|
|
code += 7;
|
|
|
|
/* Skip sampler type suffix. */
|
|
|
|
while (*code != ' ' && *code != '\0') {
|
|
|
|
code++;
|
|
|
|
}
|
|
|
|
/* Skip following spaces. */
|
|
|
|
while (*code == ' ') {
|
|
|
|
code++;
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-09-18 14:22:42 +02:00
|
|
|
if (*code != '\0') {
|
|
|
|
char sampler_name[64];
|
|
|
|
code = gpu_str_skip_token(code, sampler_name, sizeof(sampler_name));
|
2020-06-02 12:29:20 +02:00
|
|
|
int id = GPU_shader_get_uniform(shader, sampler_name);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-09-18 14:22:42 +02:00
|
|
|
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++;
|
2018-09-18 14:22:42 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
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) {
|
2018-09-18 14:22:42 +02:00
|
|
|
return false;
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-09-18 14:22:42 +02:00
|
|
|
/* 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
|
|
|
|
2018-09-18 14:22:42 +02:00
|
|
|
int total_samplers_len = vert_samplers_len + frag_samplers_len;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-09-18 14:22:42 +02:00
|
|
|
/* Validate against opengl limit. */
|
|
|
|
if ((frag_samplers_len > GPU_max_textures_frag()) ||
|
2019-04-05 20:46:13 +02:00
|
|
|
(vert_samplers_len > GPU_max_textures_vert())) {
|
2018-09-18 14:22:42 +02:00
|
|
|
return false;
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-09-18 14:22:42 +02:00
|
|
|
if (pass->geometrycode) {
|
2019-06-05 13:06:11 -03:00
|
|
|
int geom_samplers_len = count_active_texture_sampler(shader, pass->geometrycode);
|
2018-09-18 14:22:42 +02:00
|
|
|
total_samplers_len += geom_samplers_len;
|
|
|
|
if (geom_samplers_len > GPU_max_textures_geom()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-09-18 14:22:42 +02:00
|
|
|
return (total_samplers_len <= GPU_max_textures());
|
|
|
|
}
|
|
|
|
|
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;
|
2018-06-07 11:58:15 +02:00
|
|
|
if (!pass->compiled) {
|
2019-06-05 13:06:11 -03:00
|
|
|
GPUShader *shader = GPU_shader_create(
|
2018-07-18 23:09:31 +10:00
|
|
|
pass->vertexcode, pass->fragmentcode, pass->geometrycode, NULL, pass->defines, shname);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-09-18 14:22:42 +02:00
|
|
|
/* NOTE: Some drivers / gpu allows more active samplers than the opengl limit.
|
2018-12-24 12:31:39 +01:00
|
|
|
* 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) {
|
2018-09-18 14:22:42 +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;
|
2018-09-18 14:22:42 +02:00
|
|
|
}
|
|
|
|
}
|
2019-06-05 13:06:11 -03:00
|
|
|
pass->shader = shader;
|
2019-03-11 20:32:00 -03:00
|
|
|
pass->compiled = true;
|
2018-03-11 23:43:09 +01:00
|
|
|
}
|
2019-06-05 13:06:11 -03:00
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
BLI_assert(pass->refcount > 0);
|
|
|
|
pass->refcount--;
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
{
|
2018-03-11 23:43:09 +01:00
|
|
|
BLI_assert(pass->refcount == 0);
|
2018-04-09 12:09:51 +02:00
|
|
|
if (pass->shader) {
|
|
|
|
GPU_shader_free(pass->shader);
|
|
|
|
}
|
2018-03-11 23:43:09 +01:00
|
|
|
MEM_SAFE_FREE(pass->fragmentcode);
|
|
|
|
MEM_SAFE_FREE(pass->geometrycode);
|
|
|
|
MEM_SAFE_FREE(pass->vertexcode);
|
|
|
|
MEM_SAFE_FREE(pass->defines);
|
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
|
|
|
MEM_freeN(pass);
|
|
|
|
}
|
2016-07-27 10:59:09 +02:00
|
|
|
|
2018-03-11 23:43:09 +01:00
|
|
|
void GPU_pass_cache_garbage_collect(void)
|
|
|
|
{
|
|
|
|
static int lasttime = 0;
|
|
|
|
const int shadercollectrate = 60; /* hardcoded for now. */
|
|
|
|
int ctime = (int)PIL_check_seconds_timer();
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-04-22 09:32:37 +10:00
|
|
|
if (ctime < shadercollectrate + lasttime) {
|
2018-03-11 23:43:09 +01:00
|
|
|
return;
|
2019-04-22 09:32:37 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-03-11 23:43:09 +01:00
|
|
|
lasttime = ctime;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-06-07 11:58:15 +02:00
|
|
|
BLI_spin_lock(&pass_cache_spin);
|
|
|
|
GPUPass *next, **prev_pass = &pass_cache;
|
|
|
|
for (GPUPass *pass = pass_cache; pass; pass = next) {
|
|
|
|
next = pass->next;
|
2018-03-11 23:43:09 +01:00
|
|
|
if (pass->refcount == 0) {
|
|
|
|
/* Remove from list */
|
2018-06-07 11:58:15 +02:00
|
|
|
*prev_pass = next;
|
|
|
|
gpu_pass_free(pass);
|
2018-03-11 23:43:09 +01:00
|
|
|
}
|
|
|
|
else {
|
2018-06-07 11:58:15 +02:00
|
|
|
prev_pass = &pass->next;
|
2018-03-11 23:43:09 +01:00
|
|
|
}
|
|
|
|
}
|
2018-06-07 11:58:15 +02:00
|
|
|
BLI_spin_unlock(&pass_cache_spin);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GPU_pass_cache_init(void)
|
|
|
|
{
|
|
|
|
BLI_spin_init(&pass_cache_spin);
|
2018-03-11 23:43:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void GPU_pass_cache_free(void)
|
|
|
|
{
|
2018-06-07 11:58:15 +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);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-06-07 11:58:15 +02:00
|
|
|
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();
|
|
|
|
}
|