Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'source/blender/gpu')
-rw-r--r--source/blender/gpu/GPU_material.h3
-rw-r--r--source/blender/gpu/intern/gpu_codegen.c4
-rw-r--r--source/blender/gpu/intern/gpu_node_graph.c17
-rw-r--r--source/blender/gpu/intern/gpu_node_graph.h3
-rw-r--r--source/blender/gpu/shaders/material/gpu_shader_material_volume_info.glsl22
5 files changed, 40 insertions, 9 deletions
diff --git a/source/blender/gpu/GPU_material.h b/source/blender/gpu/GPU_material.h
index da00306bf9f..337c0b03308 100644
--- a/source/blender/gpu/GPU_material.h
+++ b/source/blender/gpu/GPU_material.h
@@ -233,7 +233,8 @@ typedef struct GPUMaterialTexture {
typedef struct GPUMaterialVolumeGrid {
struct GPUMaterialVolumeGrid *next, *prev;
char *name;
- char sampler_name[32]; /* Name of sampler in GLSL. */
+ char sampler_name[32]; /* Name of sampler in GLSL. */
+ char transform_name[32]; /* Name of 4x4 matrix in GLSL. */
int users;
} GPUMaterialVolumeGrid;
diff --git a/source/blender/gpu/intern/gpu_codegen.c b/source/blender/gpu/intern/gpu_codegen.c
index bcaa95c2f59..066b8d633d2 100644
--- a/source/blender/gpu/intern/gpu_codegen.c
+++ b/source/blender/gpu/intern/gpu_codegen.c
@@ -335,6 +335,7 @@ static int codegen_process_uniforms_functions(GPUMaterial *material,
/* Volume Grids */
for (GPUMaterialVolumeGrid *grid = graph->volume_grids.first; grid; grid = grid->next) {
BLI_dynstr_appendf(ds, "uniform sampler3D %s;\n", grid->sampler_name);
+ BLI_dynstr_appendf(ds, "uniform mat4 %s = mat4(0.0);\n", grid->transform_name);
}
/* Print other uniforms */
@@ -432,6 +433,9 @@ static void codegen_call_functions(DynStr *ds, GPUNodeGraph *graph, GPUOutput *f
else if (input->source == GPU_SOURCE_VOLUME_GRID) {
BLI_dynstr_append(ds, input->volume_grid->sampler_name);
}
+ else if (input->source == GPU_SOURCE_VOLUME_GRID_TRANSFORM) {
+ BLI_dynstr_append(ds, input->volume_grid->transform_name);
+ }
else if (input->source == GPU_SOURCE_OUTPUT) {
codegen_convert_datatype(
ds, input->link->output->type, input->type, "tmp", input->link->output->id);
diff --git a/source/blender/gpu/intern/gpu_node_graph.c b/source/blender/gpu/intern/gpu_node_graph.c
index 0d5cc46c0b9..0eb62bf5b2f 100644
--- a/source/blender/gpu/intern/gpu_node_graph.c
+++ b/source/blender/gpu/intern/gpu_node_graph.c
@@ -123,6 +123,10 @@ static void gpu_node_input_link(GPUNode *node, GPUNodeLink *link, const eGPUType
input->source = GPU_SOURCE_VOLUME_GRID;
input->volume_grid = link->volume_grid;
break;
+ case GPU_NODE_LINK_VOLUME_GRID_TRANSFORM:
+ input->source = GPU_SOURCE_VOLUME_GRID_TRANSFORM;
+ input->volume_grid = link->volume_grid;
+ break;
case GPU_NODE_LINK_ATTR:
input->source = GPU_SOURCE_ATTR;
input->attr = link->attr;
@@ -342,6 +346,7 @@ static GPUMaterialVolumeGrid *gpu_node_graph_add_volume_grid(GPUNodeGraph *graph
grid = MEM_callocN(sizeof(*grid), __func__);
grid->name = BLI_strdup(name);
BLI_snprintf(grid->sampler_name, sizeof(grid->sampler_name), "vsamp%d", num_grids);
+ BLI_snprintf(grid->transform_name, sizeof(grid->transform_name), "vtfm%d", num_grids);
BLI_addtail(&graph->volume_grids, grid);
}
@@ -432,16 +437,20 @@ GPUNodeLink *GPU_volume_grid(GPUMaterial *mat, const char *name)
link->link_type = GPU_NODE_LINK_VOLUME_GRID;
link->volume_grid = gpu_node_graph_add_volume_grid(graph, name);
+ GPUNodeLink *transform_link = gpu_node_link_create();
+ transform_link->link_type = GPU_NODE_LINK_VOLUME_GRID_TRANSFORM;
+ transform_link->volume_grid = link->volume_grid;
+
/* Two special cases, where we adjust the output values of smoke grids to
* bring the into standard range without having to modify the grid values. */
if (strcmp(name, "color") == 0) {
- GPU_link(mat, "node_attribute_volume_color", link, &link);
+ GPU_link(mat, "node_attribute_volume_color", link, transform_link, &link);
}
else if (strcmp(name, "temperature") == 0) {
- GPU_link(mat, "node_attribute_volume_temperature", link, &link);
+ GPU_link(mat, "node_attribute_volume_temperature", link, transform_link, &link);
}
else {
- GPU_link(mat, "node_attribute_volume", link, &link);
+ GPU_link(mat, "node_attribute_volume", link, transform_link, &link);
}
return link;
@@ -590,7 +599,7 @@ static void gpu_inputs_free(ListBase *inputs)
else if (ELEM(input->source, GPU_SOURCE_TEX, GPU_SOURCE_TEX_TILED_MAPPING)) {
input->texture->users--;
}
- else if (ELEM(input->source, GPU_SOURCE_VOLUME_GRID)) {
+ else if (ELEM(input->source, GPU_SOURCE_VOLUME_GRID, GPU_SOURCE_VOLUME_GRID_TRANSFORM)) {
input->volume_grid->users--;
}
diff --git a/source/blender/gpu/intern/gpu_node_graph.h b/source/blender/gpu/intern/gpu_node_graph.h
index ceaeea2bfa8..8506c6a87e2 100644
--- a/source/blender/gpu/intern/gpu_node_graph.h
+++ b/source/blender/gpu/intern/gpu_node_graph.h
@@ -62,6 +62,7 @@ typedef enum {
GPU_NODE_LINK_IMAGE_TILED,
GPU_NODE_LINK_IMAGE_TILED_MAPPING,
GPU_NODE_LINK_VOLUME_GRID,
+ GPU_NODE_LINK_VOLUME_GRID_TRANSFORM,
GPU_NODE_LINK_OUTPUT,
GPU_NODE_LINK_UNIFORM,
} GPUNodeLinkType;
@@ -131,7 +132,7 @@ typedef struct GPUInput {
struct GPUMaterialTexture *texture;
/* GPU_SOURCE_ATTR */
struct GPUMaterialAttribute *attr;
- /* GPU_SOURCE_VOLUME_GRID */
+ /* GPU_SOURCE_VOLUME_GRID | GPU_SOURCE_VOLUME_GRID_TRANSFORM */
struct GPUMaterialVolumeGrid *volume_grid;
};
} GPUInput;
diff --git a/source/blender/gpu/shaders/material/gpu_shader_material_volume_info.glsl b/source/blender/gpu/shaders/material/gpu_shader_material_volume_info.glsl
index a80cd3cb329..e6d7b9d3721 100644
--- a/source/blender/gpu/shaders/material/gpu_shader_material_volume_info.glsl
+++ b/source/blender/gpu/shaders/material/gpu_shader_material_volume_info.glsl
@@ -4,18 +4,24 @@ uniform vec3 volumeColor = vec3(1.0);
uniform vec2 volumeTemperature = vec2(0.0);
/* Generic volume attribute. */
-void node_attribute_volume(sampler3D tex, out vec3 outvec)
+void node_attribute_volume(sampler3D tex, mat4 transform, out vec3 outvec)
{
#if defined(MESH_SHADER) && defined(VOLUMETRICS)
vec3 cos = volumeObjectLocalCoord;
#else
vec3 cos = vec3(0.0);
#endif
+
+ /* Optional per-grid transform. */
+ if (transform[3][3] != 0.0) {
+ cos = (transform * vec4(cos, 1.0)).xyz;
+ }
+
outvec = texture(tex, cos).rgb;
}
/* Special color attribute for smoke. */
-void node_attribute_volume_color(sampler3D tex, out vec3 outvec)
+void node_attribute_volume_color(sampler3D tex, mat4 transform, out vec3 outvec)
{
#if defined(MESH_SHADER) && defined(VOLUMETRICS)
vec3 cos = volumeObjectLocalCoord;
@@ -23,6 +29,11 @@ void node_attribute_volume_color(sampler3D tex, out vec3 outvec)
vec3 cos = vec3(0.0);
#endif
+ /* Optional per-grid transform. */
+ if (transform[3][3] != 0.0) {
+ cos = (transform * vec4(cos, 1.0)).xyz;
+ }
+
/* Density is premultiplied for interpolation, divide it out here. */
vec4 value = texture(tex, cos).rgba;
if (value.a > 1e-8) {
@@ -33,7 +44,7 @@ void node_attribute_volume_color(sampler3D tex, out vec3 outvec)
}
/* Special temperature attribute for smoke. */
-void node_attribute_volume_temperature(sampler3D tex, out float outf)
+void node_attribute_volume_temperature(sampler3D tex, mat4 transform, out float outf)
{
#if defined(MESH_SHADER) && defined(VOLUMETRICS)
vec3 cos = volumeObjectLocalCoord;
@@ -41,6 +52,11 @@ void node_attribute_volume_temperature(sampler3D tex, out float outf)
vec3 cos = vec3(0.0);
#endif
+ /* Optional per-grid transform. */
+ if (transform[3][3] != 0.0) {
+ cos = (transform * vec4(cos, 1.0)).xyz;
+ }
+
float value = texture(tex, cos).r;
if (volumeTemperature.x < volumeTemperature.y) {
outf = (value > 0.01) ?