2
$\begingroup$

Since Blender supports GPU rendering, sometimes the shader node trees need to be compiled into a form that can be sent to the GPU. I don't know if it's first compiled into a shader language HLSL/GLSL/MSL/WGSL etc. or directly to the intermediary representation DXIL/DXBC/SPIR-V/RDNA2 ISA/PTX, or maybe even directly assembly? Obviously obtaining HLSL would be best, but even getting assembly helps.

So for example, if I have a node tree:

How would I obtain an equivalent shader code:

vec3 RGBnode() {
  return vec3(0.5);
}

void mainImage(out vec4 fragColor, in vec2 fragCoord) {
  vec3 col = RGBnode();
  fragColor = vec4(col, 1.0);
}

$\endgroup$

1 Answer 1

2
$\begingroup$

This is not really an answer, more like me sharing notes on studying the Blender source code. Various aspects of converting the node setups to shader code are all over the place, so it seems the most reasonable approach is to fork Blender and save to a file the code that is being sent to GPU…

Python

source/blender/python/gpu/gpu_py_shader_create_info.cc

source/blender/python/gpu/gpu_py_shader.c

GPU

GPU shader interface (C --> GLSL)

source/blender/gpu/opengl/gl_shader_interface.hh

source/blender/gpu/opengl/gl_shader_interface.cc

source/blender/gpu/intern/gpu_shader_interface.hh

source/blender/gpu/intern/gpu_shader_interface.cc

Structure detailing needed vertex inputs and resources for a specific shader. A shader interface can be shared between two similar shaders.

GL shader

source/blender/gpu/opengl/gl_shader.hh

source/blender/gpu/opengl/gl_shader.cc

Implementation of shader compilation and uniforms handling using OpenGL.

GPU shader shared utils

source/blender/gpu/GPU_shader_shared_utils.h

Glue definition to make shared declaration of struct & functions work in both C / C++ and GLSL.

GPU material

source/blender/gpu/GPU_material.h

Functions to create GPU Materials nodes.

GPU platform

source/blender/gpu/intern/gpu_platform.cc

Wrap OpenGL features such as textures, shaders and GLSL with checks for drivers and GPU support.

GPU codegen

source/blender/gpu/intern/gpu_codegen.h

Generate shader code from the intermediate node graph.

source/blender/gpu/intern/gpu_codegen.cc

Convert material node-trees to GLSL.

GPU shader dependency

source/blender/gpu/intern/gpu_shader_dependency.cc

Shader source dependency builder that make possible to support #include directive inside the shader files.

GPU material library

source/blender/gpu/intern/gpu_material_library.h

Parsing of and code generation using GLSL shaders in gpu/shaders/material.

GPU capabilities

source/blender/gpu/intern/gpu_capabilities.cc

Wrap OpenGL features such as textures, shaders and GLSL with checks for drivers and GPU support.

GPU node graph

source/blender/gpu/intern/gpu_node_graph.h

source/blender/gpu/intern/gpu_node_graph.c

Intermediate node graph for generating GLSL shaders.

Color management

source/blender/imbuf/IMB_colormanagement.h

source/blender/imbuf/intern/colormanagement.c

Render internal

source/blender/editors/render/render_internal.cc

Nodes

source/blender/nodes/ - it looks like those files only describe the interface part of nodes and has nothing to do with the actual rendering part.

tbc…

$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .