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:
authorClément Fukhaut <turjuque@gmail.com>2016-05-03 20:41:41 +0300
committerClément Fukhaut <turjuque@gmail.com>2016-05-03 20:41:41 +0300
commit655cfca4524fc8295cb7ead9f2ccaf4f79d3f221 (patch)
tree3e4557940e8683cccca2d3fa4852a26bb9249ca6 /source/blender/gpu/intern/gpu_codegen.c
parent7c777fe0383304219ab47251e2fe437d0ba90a7f (diff)
Implemented SSR :
- Still pretty rough implementation does only works with sharp glossy shader - No Glossy reflection - 2 algorithm but only one acheive decent results the other needs to be debuged. Changed pbr settings location : - They are now stored in structs like the FX options
Diffstat (limited to 'source/blender/gpu/intern/gpu_codegen.c')
-rw-r--r--source/blender/gpu/intern/gpu_codegen.c133
1 files changed, 95 insertions, 38 deletions
diff --git a/source/blender/gpu/intern/gpu_codegen.c b/source/blender/gpu/intern/gpu_codegen.c
index 3236c5798cf..149029d11f3 100644
--- a/source/blender/gpu/intern/gpu_codegen.c
+++ b/source/blender/gpu/intern/gpu_codegen.c
@@ -57,6 +57,7 @@
extern char datatoc_gpu_shader_material_glsl[];
extern char datatoc_gpu_shader_material_bsdf_frag_glsl[];
+extern char datatoc_gpu_shader_material_ssr_frag_glsl[];
extern char datatoc_gpu_shader_vertex_glsl[];
extern char datatoc_gpu_shader_vertex_world_glsl[];
extern char datatoc_gpu_shader_geometry_glsl[];
@@ -409,40 +410,54 @@ const char *GPU_builtin_name(GPUBuiltin builtin)
return "unfparticlevel";
else if (builtin == GPU_PARTICLE_ANG_VELOCITY)
return "unfparticleangvel";
- else if (builtin == GPU_PBR_PROBE)
+ else
+ return "";
+}
+
+const char *GPU_pbrbuiltin_name(GPUPBRBuiltin pbrbuiltin)
+{
+ if (pbrbuiltin == GPU_PROBE)
return "unfprobe";
- else if (builtin == GPU_PBR_PLANAR_REFLECT)
+ else if (pbrbuiltin == GPU_PLANAR_REFLECT)
return "unfreflect";
- else if (builtin == GPU_PBR_PLANAR_REFRACT)
+ else if (pbrbuiltin == GPU_PLANAR_REFRACT)
return "unfrefract";
- else if (builtin == GPU_PBR_LOD_FACTOR)
+ else if (pbrbuiltin == GPU_LOD_FACTOR)
return "unflodfactor";
- else if (builtin == GPU_PBR_SH0)
+ else if (pbrbuiltin == GPU_SH0)
return "unfsh0";
- else if (builtin == GPU_PBR_SH1)
+ else if (pbrbuiltin == GPU_SH1)
return "unfsh1";
- else if (builtin == GPU_PBR_SH2)
+ else if (pbrbuiltin == GPU_SH2)
return "unfsh2";
- else if (builtin == GPU_PBR_SH3)
+ else if (pbrbuiltin == GPU_SH3)
return "unfsh3";
- else if (builtin == GPU_PBR_SH4)
+ else if (pbrbuiltin == GPU_SH4)
return "unfsh4";
- else if (builtin == GPU_PBR_SH5)
+ else if (pbrbuiltin == GPU_SH5)
return "unfsh5";
- else if (builtin == GPU_PBR_SH6)
+ else if (pbrbuiltin == GPU_SH6)
return "unfsh6";
- else if (builtin == GPU_PBR_SH7)
+ else if (pbrbuiltin == GPU_SH7)
return "unfsh7";
- else if (builtin == GPU_PBR_SH8)
+ else if (pbrbuiltin == GPU_SH8)
return "unfsh8";
- else if (builtin == GPU_PBR_CORRECTION_MATRIX)
+ else if (pbrbuiltin == GPU_CORRECTION_MATRIX)
return "unfprobecorrectionmat";
- else if (builtin == GPU_PBR_PLANAR_RFL_MATRIX)
+ else if (pbrbuiltin == GPU_PLANAR_RFL_MATRIX)
return "unfplanarreflectmat";
- else if (builtin == GPU_PBR_PROBE_POSITION)
+ else if (pbrbuiltin == GPU_PROBE_POSITION)
return "unfprobepos";
- else if (builtin == GPU_PBR_PLANAR_VECTOR)
+ else if (pbrbuiltin == GPU_PLANAR_VECTOR)
return "unfplanarvec";
+ else if (pbrbuiltin == GPU_SSR)
+ return "unfssr";
+ else if (pbrbuiltin == GPU_SSR_PARAMETERS)
+ return "unfssrparam";
+ else if (pbrbuiltin == GPU_SSR_PARAMETERS2)
+ return "unfssrparam2";
+ else if (pbrbuiltin == GPU_PIXEL_PROJ_MATRIX)
+ return "unfpixelprojmat";
else
return "";
}
@@ -469,8 +484,8 @@ static void codegen_set_unique_ids(ListBase *nodes)
GPUNode *node;
GPUInput *input;
GPUOutput *output;
- /* tex slot (texid) 0-2 is pbr textures */
- int id = 1, texid = 3;
+ /* tex slot (texid) 0-3 are pbr textures */
+ int id = 1, texid = 4;
bindhash = BLI_ghash_ptr_new("codegen_set_unique_ids1 gh");
definehash = BLI_ghash_ptr_new("codegen_set_unique_ids2 gh");
@@ -537,7 +552,7 @@ static int codegen_print_uniforms_functions(DynStr *ds, ListBase *nodes)
GPUNode *node;
GPUInput *input;
const char *name;
- int builtins = 0;
+ int builtins = 0, pbrbuiltins = 0;
/* print uniforms */
for (node = nodes->first; node; node = node->next) {
@@ -561,12 +576,6 @@ static int codegen_print_uniforms_functions(DynStr *ds, ListBase *nodes)
/* XXX always here */
continue;
}
- if (input->builtin == GPU_PBR_PROBE) {
- BLI_dynstr_appendf(ds, "uniform samplerCube %s;\n", name);
- }
- else if (input->builtin == GPU_PBR_PLANAR_REFLECT || input->builtin == GPU_PBR_PLANAR_REFRACT) {
- BLI_dynstr_appendf(ds, "uniform sampler2D %s;\n", name);
- }
else if (gpu_str_prefix(name, "unf")) {
BLI_dynstr_appendf(ds, "uniform %s %s;\n",
GPU_DATATYPE_STR[input->type], name);
@@ -578,6 +587,24 @@ static int codegen_print_uniforms_functions(DynStr *ds, ListBase *nodes)
}
}
}
+ else if (input->source == GPU_SOURCE_PBR_BUILTIN) {
+ /* only define each builtin uniform/varying once */
+ if (!(pbrbuiltins & input->pbrbuiltin)) {
+ pbrbuiltins |= input->pbrbuiltin;
+ name = GPU_pbrbuiltin_name(input->pbrbuiltin);
+
+ if (input->pbrbuiltin == GPU_PROBE) {
+ BLI_dynstr_appendf(ds, "uniform samplerCube %s;\n", name);
+ }
+ else if (input->pbrbuiltin & (GPU_PLANAR_REFLECT | GPU_PLANAR_REFRACT | GPU_SSR)) {
+ BLI_dynstr_appendf(ds, "uniform sampler2D %s;\n", name);
+ }
+ else {
+ BLI_dynstr_appendf(ds, "uniform %s %s;\n",
+ GPU_DATATYPE_STR[input->type], name);
+ }
+ }
+ }
else if (input->source == GPU_SOURCE_VEC_UNIFORM) {
if (input->dynamicvec) {
/* only create uniforms for dynamic vectors */
@@ -669,6 +696,9 @@ static void codegen_call_functions(DynStr *ds, ListBase *nodes, GPUOutput *final
else
BLI_dynstr_append(ds, GPU_builtin_name(input->builtin));
}
+ else if (input->source == GPU_SOURCE_PBR_BUILTIN) {
+ BLI_dynstr_append(ds, GPU_pbrbuiltin_name(input->pbrbuiltin));
+ }
else if (input->source == GPU_SOURCE_VEC_UNIFORM) {
if (input->dynamicvec)
BLI_dynstr_appendf(ds, "unf%d", input->id);
@@ -697,16 +727,16 @@ static void codegen_call_functions(DynStr *ds, ListBase *nodes, GPUOutput *final
BLI_dynstr_append(ds, ");\n");
}
- BLI_dynstr_appendf(ds, "#ifndef ALPHA_AS_DEPTH");
+ BLI_dynstr_appendf(ds, "\n#ifndef ALPHA_AS_DEPTH\n");
BLI_dynstr_append(ds, "\n\tgl_FragColor = ");
codegen_convert_datatype(ds, finaloutput->type, GPU_VEC4, "tmp", finaloutput->id);
BLI_dynstr_append(ds, ";\n");
- BLI_dynstr_appendf(ds, "#else");
- /* Encode Depth in Alpha if we are capturing for planar reflection */
+ BLI_dynstr_appendf(ds, "\n#else\n");
+ /* Encode Depth in Alpha if we are capturing for planar reflection / ssr */
BLI_dynstr_append(ds, "\n\tgl_FragColor = vec4(");
codegen_convert_datatype(ds, finaloutput->type, GPU_VEC3, "tmp", finaloutput->id);
- BLI_dynstr_append(ds, ", -varposition.z + 1.0);\n");
- BLI_dynstr_appendf(ds, "#endif\n");
+ BLI_dynstr_append(ds, ", varposition.z);\n");
+ BLI_dynstr_appendf(ds, "\n#endif\n");
}
static char *code_generate_fragment(ListBase *nodes, const GPUMatType type, GPUOutput *output)
@@ -733,10 +763,10 @@ static char *code_generate_fragment(ListBase *nodes, const GPUMatType type, GPUO
#endif
if (type == GPU_MATERIAL_TYPE_MESH_REAL_SH) {
+ BLI_dynstr_append(ds, datatoc_gpu_shader_material_ssr_frag_glsl);
BLI_dynstr_append(ds, datatoc_gpu_shader_material_bsdf_frag_glsl);
}
-
/* XXX */
BLI_dynstr_appendf(ds, "%s vec3 varposition;\n",
GLEW_VERSION_3_0 ? "in" : "varying");
@@ -1027,6 +1057,7 @@ static void gpu_nodes_extract_dynamic_inputs(GPUPass *pass, ListBase *nodes)
#endif
}
if (input->source == GPU_SOURCE_BUILTIN ||
+ input->source == GPU_SOURCE_PBR_BUILTIN ||
input->source == GPU_SOURCE_OPENGL_BUILTIN)
{
continue;
@@ -1213,6 +1244,14 @@ static void gpu_node_input_link(GPUNode *node, GPUNodeLink *link, const GPUType
MEM_freeN(link);
}
+ else if (link->pbrbuiltin) {
+ /* builtin uniform */
+ input->type = type;
+ input->source = GPU_SOURCE_PBR_BUILTIN;
+ input->pbrbuiltin = link->pbrbuiltin;
+
+ MEM_freeN(link);
+ }
else if (link->oglbuiltin) {
/* builtin uniform */
input->type = type;
@@ -1424,17 +1463,22 @@ static void gpu_nodes_get_vertex_attributes(ListBase *nodes, GPUVertexAttribs *a
}
}
-static void gpu_nodes_get_builtin_flag(ListBase *nodes, int *builtin)
+static void gpu_nodes_get_builtin_flag(ListBase *nodes, int *builtin, int *pbrbuiltin)
{
GPUNode *node;
GPUInput *input;
*builtin = 0;
+ *pbrbuiltin = 0;
- for (node = nodes->first; node; node = node->next)
- for (input = node->inputs.first; input; input = input->next)
+ for (node = nodes->first; node; node = node->next) {
+ for (input = node->inputs.first; input; input = input->next) {
if (input->source == GPU_SOURCE_BUILTIN)
*builtin |= input->builtin;
+ else if (input->source == GPU_SOURCE_PBR_BUILTIN)
+ *pbrbuiltin |= input->pbrbuiltin;
+ }
+ }
}
/* varargs linking */
@@ -1540,6 +1584,15 @@ GPUNodeLink *GPU_builtin(GPUBuiltin builtin)
return link;
}
+GPUNodeLink *GPU_pbr_builtin(GPUPBRBuiltin builtin)
+{
+ GPUNodeLink *link = GPU_node_link_create();
+
+ link->pbrbuiltin = builtin;
+
+ return link;
+}
+
GPUNodeLink *GPU_opengl_builtin(GPUOpenGLBuiltin builtin)
{
GPUNodeLink *link = GPU_node_link_create();
@@ -1706,7 +1759,7 @@ static void gpu_nodes_prune(ListBase *nodes, GPUNodeLink *outlink)
GPUPass *GPU_generate_pass(
ListBase *nodes, GPUNodeLink *outlink,
- GPUVertexAttribs *attribs, int *builtins,
+ GPUVertexAttribs *attribs, int *builtins, int *pbrbuiltins,
const GPUMatType type, const char *UNUSED(name),
const bool use_opensubdiv,
const bool use_new_shading,
@@ -1714,6 +1767,7 @@ GPUPass *GPU_generate_pass(
const bool use_box_correction,
const bool use_ellipsoid_correction,
const bool use_alpha_as_depth,
+ const bool use_ssr,
const int samplecount)
{
GPUShader *shader;
@@ -1731,8 +1785,7 @@ GPUPass *GPU_generate_pass(
gpu_nodes_prune(nodes, outlink);
gpu_nodes_get_vertex_attributes(nodes, attribs);
- gpu_nodes_get_builtin_flag(nodes, builtins);
-
+ gpu_nodes_get_builtin_flag(nodes, builtins, pbrbuiltins);
/* generate code and compile with opengl */
fragmentcode = code_generate_fragment(nodes, type, outlink->output);
@@ -1758,6 +1811,9 @@ GPUPass *GPU_generate_pass(
if (use_alpha_as_depth) {
flags |= GPU_SHADER_FLAGS_ALPHA_DEPTH;
}
+ if (use_ssr) {
+ flags |= GPU_SHADER_FLAGS_SSR;
+ }
shader = GPU_shader_create_ex(vertexcode,
fragmentcode,
@@ -1778,6 +1834,7 @@ GPUPass *GPU_generate_pass(
MEM_freeN(vertexcode);
memset(attribs, 0, sizeof(*attribs));
memset(builtins, 0, sizeof(*builtins));
+ memset(pbrbuiltins, 0, sizeof(*pbrbuiltins));
gpu_nodes_free(nodes);
return NULL;
}