diff options
author | Clément Foucault <foucault.clem@gmail.com> | 2018-05-29 13:14:14 +0300 |
---|---|---|
committer | Clément Foucault <foucault.clem@gmail.com> | 2018-05-30 13:25:20 +0300 |
commit | 501c0b1df8c2db9806481d4e4c4c59008389b426 (patch) | |
tree | f608add20e44f92e4ddbb54272bdd8a82f59dc2c /source/blender/gpu/intern/gpu_codegen.c | |
parent | 328f8dc21c0e8a7e3da14f6578fb84a811f80b89 (diff) |
GPUMaterial: Add support for hair vertex color, uvs and orco.
Diffstat (limited to 'source/blender/gpu/intern/gpu_codegen.c')
-rw-r--r-- | source/blender/gpu/intern/gpu_codegen.c | 48 |
1 files changed, 46 insertions, 2 deletions
diff --git a/source/blender/gpu/intern/gpu_codegen.c b/source/blender/gpu/intern/gpu_codegen.c index 7a4af0521bb..f182f08f4a9 100644 --- a/source/blender/gpu/intern/gpu_codegen.c +++ b/source/blender/gpu/intern/gpu_codegen.c @@ -895,6 +895,15 @@ static char *code_generate_vertex(ListBase *nodes, const char *vert_code, bool u GPUInput *input; char *code; + /* Hairs uv and col attribs are passed by bufferTextures. */ + BLI_dynstr_append(ds, + "#ifdef HAIR_SHADER\n" + "#define DEFINE_ATTRIB(type, attr) uniform samplerBuffer attr\n" + "#else\n" + "#define DEFINE_ATTRIB(type, attr) in type attr\n" + "#endif\n" + ); + for (node = nodes->first; node; node = node->next) { for (input = node->inputs.first; input; input = input->next) { if (input->source == GPU_SOURCE_ATTRIB && input->attribfirst) { @@ -905,12 +914,12 @@ static char *code_generate_vertex(ListBase *nodes, const char *vert_code, bool u BLI_dynstr_appendf(ds, "uniform vec3 OrcoTexCoFactors[2];\n"); } else if (input->attribname[0] == '\0') { - BLI_dynstr_appendf(ds, "in %s %s;\n", GPU_DATATYPE_STR[input->type], attrib_prefix_get(input->attribtype)); + BLI_dynstr_appendf(ds, "DEFINE_ATTRIB(%s, %s);\n", GPU_DATATYPE_STR[input->type], attrib_prefix_get(input->attribtype)); BLI_dynstr_appendf(ds, "#define att%d %s\n", input->attribid, attrib_prefix_get(input->attribtype)); } else { unsigned int hash = BLI_ghashutil_strhash_p(input->attribname); - BLI_dynstr_appendf(ds, "in %s %s%u;\n", + BLI_dynstr_appendf(ds, "DEFINE_ATTRIB(%s, %s%u);\n", GPU_DATATYPE_STR[input->type], attrib_prefix_get(input->attribtype), hash); BLI_dynstr_appendf(ds, "#define att%d %s%u\n", input->attribid, attrib_prefix_get(input->attribtype), hash); @@ -932,6 +941,7 @@ static char *code_generate_vertex(ListBase *nodes, const char *vert_code, bool u BLI_dynstr_append(ds, "#define ATTRIB\n" "uniform mat3 NormalMatrix;\n" + "uniform mat4 ModelMatrixInverse;\n" "vec3 srgb_to_linear_attrib(vec3 c) {\n" "\tc = max(c, vec3(0.0));\n" "\tvec3 c1 = c * (1.0 / 12.92);\n" @@ -940,8 +950,41 @@ static char *code_generate_vertex(ListBase *nodes, const char *vert_code, bool u "}\n\n" ); + /* Prototype because defined later. */ + BLI_dynstr_append(ds, + "vec2 hair_get_customdata_vec2(const samplerBuffer);\n" + "vec3 hair_get_customdata_vec3(const samplerBuffer);\n" + "vec4 hair_get_customdata_vec4(const samplerBuffer);\n" + "vec3 hair_get_strand_pos(void);\n" + "\n" + ); + BLI_dynstr_append(ds, "void pass_attrib(in vec3 position) {\n"); + BLI_dynstr_append(ds, "#ifdef HAIR_SHADER\n"); + + for (node = nodes->first; node; node = node->next) { + for (input = node->inputs.first; input; input = input->next) { + if (input->source == GPU_SOURCE_ATTRIB && input->attribfirst) { + if (input->attribtype == CD_TANGENT) { + /* Not supported by hairs */ + BLI_dynstr_appendf(ds, "\tvar%d%s = vec4(0.0);\n", + input->attribid, use_geom ? "g" : ""); + } + else if (input->attribtype == CD_ORCO) { + BLI_dynstr_appendf(ds, "\tvar%d%s = OrcoTexCoFactors[0] + (ModelMatrixInverse * vec4(hair_get_strand_pos(), 1.0)).xyz * OrcoTexCoFactors[1];\n", + input->attribid, use_geom ? "g" : ""); + } + else { + BLI_dynstr_appendf(ds, "\tvar%d%s = hair_get_customdata_%s(att%d);\n", + input->attribid, use_geom ? "g" : "", GPU_DATATYPE_STR[input->type], input->attribid); + } + } + } + } + + BLI_dynstr_append(ds, "#else /* MESH_SHADER */\n"); + for (node = nodes->first; node; node = node->next) { for (input = node->inputs.first; input; input = input->next) { if (input->source == GPU_SOURCE_ATTRIB && input->attribfirst) { @@ -973,6 +1016,7 @@ static char *code_generate_vertex(ListBase *nodes, const char *vert_code, bool u } } } + BLI_dynstr_append(ds, "#endif /* HAIR_SHADER */\n"); BLI_dynstr_append(ds, "}\n"); |