Changeset View
Changeset View
Standalone View
Standalone View
source/blender/nodes/NOD_texture_evaluate.hh
- This file was added.
| /* SPDX-License-Identifier: GPL-2.0-or-later */ | |||||
| #pragma once | |||||
| #include "BLI_array.hh" | |||||
| #include "BLI_math_vec_types.hh" | |||||
| #include "BLI_span.hh" | |||||
| #include "BKE_attribute.h" | |||||
| struct ID; | |||||
| struct Mesh; | |||||
| struct Tex; | |||||
| namespace blender::nodes { | |||||
| /* Batch of samples to evaluate a texture for. | |||||
| * | |||||
| * TextureBatch is the most simple case, where only positions of the samples | |||||
| * are known and there is no associated geometry that we can read additional | |||||
| * attributes from. | |||||
| * | |||||
| * Evaluating textures in large batches is required for good performance, to | |||||
| * amortize the overhead of node evaluation. */ | |||||
| struct TextureBatch { | |||||
| const Tex *tex; | |||||
| int size; | |||||
| Array<float3> positions; | |||||
| TextureBatch(const Tex *tex, const int size); | |||||
| void evaluate(const MutableSpan<float> &output, IndexMask mask) const; | |||||
| void evaluate(const MutableSpan<float4> &output, IndexMask mask) const; | |||||
| }; | |||||
| /* Batch of samples in a geometry domain. | |||||
| * | |||||
| * Evaluate a texture for every index in a point, edge, face, corner or curve | |||||
| * domain of a geometry. For example for baking a texture into vertex colors. | |||||
| * Attributes from the geometry will be used by texture nodes. | |||||
| * | |||||
| * TODO: support a mask to evaluate only a subset. */ | |||||
| struct GeometryDomainTextureBatch : public TextureBatch { | |||||
| const ID *geometry; | |||||
| eAttrDomain domain; | |||||
| GeometryDomainTextureBatch(const Tex *tex, const ID *geometry, eAttrDomain domain); | |||||
| void evaluate(const MutableSpan<float> &output) const; | |||||
| void evaluate(const MutableSpan<float4> &output) const; | |||||
| }; | |||||
| /* Batch of samples on a mesh surface. | |||||
| * | |||||
| * Evaluate a texture on a mesh surface, at barycentric coordinates in mesh | |||||
| * loop triangles. Attributes from the geometry will be interpolated as | |||||
| * required. */ | |||||
| struct GeometrySurfaceTextureBatch : public TextureBatch { | |||||
| struct Sample { | |||||
| int triangle; | |||||
| float u, v; | |||||
| }; | |||||
| const Mesh *mesh; | |||||
| Array<Sample> samples; | |||||
| GeometrySurfaceTextureBatch(const Tex *tex, const Mesh *mesh, const int size); | |||||
| void evaluate(const MutableSpan<float> &output) const; | |||||
| void evaluate(const MutableSpan<float4> &output) const; | |||||
| }; | |||||
| /* Single position texture evaluation. | |||||
| * | |||||
| * This has poor performance and exists for legacy code only. */ | |||||
| bool texture_evaluate_single(Tex *tex, const float3 position, const int thread, float *output); | |||||
| bool texture_evaluate_single(Tex *tex, const float3 position, const int thread, float4 *output); | |||||
| } // namespace blender::nodes | |||||