﻿<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="ja">
	<id>https://wiki.blender.jp/index.php?action=history&amp;feed=atom&amp;title=Dev%3A2.8%2FSource%2FViewport%2FPyNodeGLSL</id>
	<title>Dev:2.8/Source/Viewport/PyNodeGLSL - 版の履歴</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.blender.jp/index.php?action=history&amp;feed=atom&amp;title=Dev%3A2.8%2FSource%2FViewport%2FPyNodeGLSL"/>
	<link rel="alternate" type="text/html" href="https://wiki.blender.jp/index.php?title=Dev:2.8/Source/Viewport/PyNodeGLSL&amp;action=history"/>
	<updated>2026-06-19T10:02:18Z</updated>
	<subtitle>このウィキのこのページに関する変更履歴</subtitle>
	<generator>MediaWiki 1.31.0</generator>
	<entry>
		<id>https://wiki.blender.jp/index.php?title=Dev:2.8/Source/Viewport/PyNodeGLSL&amp;diff=152677&amp;oldid=prev</id>
		<title>Yamyam: 1版 をインポートしました</title>
		<link rel="alternate" type="text/html" href="https://wiki.blender.jp/index.php?title=Dev:2.8/Source/Viewport/PyNodeGLSL&amp;diff=152677&amp;oldid=prev"/>
		<updated>2018-06-28T21:21:46Z</updated>

		<summary type="html">&lt;p&gt;1版 をインポートしました&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left&quot; data-mw=&quot;interface&quot;&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;ja&quot;&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: #fff; color: #222; text-align: center;&quot;&gt;← 古い版&lt;/td&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: #fff; color: #222; text-align: center;&quot;&gt;2018年6月28日 (木) 21:21時点における版&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-notice&quot; lang=&quot;ja&quot;&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;(相違点なし)&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</summary>
		<author><name>Yamyam</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.blender.jp/index.php?title=Dev:2.8/Source/Viewport/PyNodeGLSL&amp;diff=152676&amp;oldid=prev</id>
		<title>2016年12月22日 (木) 23:06にwiki&gt;Hypersomniacによる</title>
		<link rel="alternate" type="text/html" href="https://wiki.blender.jp/index.php?title=Dev:2.8/Source/Viewport/PyNodeGLSL&amp;diff=152676&amp;oldid=prev"/>
		<updated>2016-12-22T23:06:24Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;新規ページ&lt;/b&gt;&lt;/p&gt;&lt;div&gt;= Pynode GLSL =&lt;br /&gt;
&lt;br /&gt;
This is the first step towards accommodating GLSL code snippets definition in PyNodes. Which in turn is related to the proposal for the viewport plan of action.&lt;br /&gt;
&lt;br /&gt;
The overall idea is to allow for external engines to define an optional GLSL code for each node. This would automatically be picked up by the Eevee engine. Also, this would allow for external engines to benefit from Blender’s internal GLSL code parser, for their own viewport drawings.&lt;br /&gt;
&lt;br /&gt;
=== Cycles Engine ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
class CyclesRender(bpy.types.RenderEngine):&lt;br /&gt;
&lt;br /&gt;
	# Define whether or not to use OpenGL/Vulkan API&lt;br /&gt;
	bl_use_realtime_engine = False&lt;br /&gt;
&lt;br /&gt;
	# This string will be added at to all shaders&lt;br /&gt;
	# Put redundant GLSL code here&lt;br /&gt;
	bl_gpu_library = &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
		#define CYCLES_M_PI 3.14&lt;br /&gt;
		vec3 CYCLES_to_tangent(...) {...};&lt;br /&gt;
		float CYCLES_saturate(...) {...};&lt;br /&gt;
		...&lt;br /&gt;
		&amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The bl_gpu_library contains all functions shared between nodes to avoid code duplication. &lt;br /&gt;
All functions, variables and constants should have a prefix to avoid namespace conflicts later.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Cycles Nodes ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
class CyclesMixShaderNode(bpy.types.ShaderNode):&lt;br /&gt;
	# with which render engine this node will be executed&lt;br /&gt;
	bl_compatibility = {'CYCLES'}&lt;br /&gt;
&lt;br /&gt;
	# Code is defined here in case any realtime RenderEngines want to use it&lt;br /&gt;
	# Multiple functions can define in there&lt;br /&gt;
	bl_gpu_code = {'CYCLES' : &amp;quot;void node_shader_mix_shader(...) {out_col = ...}&amp;quot;}&lt;br /&gt;
&lt;br /&gt;
	# Logic to call GLSL functions for the node itself&lt;br /&gt;
	def gpu_exec(self, ins, outs):&lt;br /&gt;
		return gpu_stack_link('node_shader_mix_shader', ins, outs)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Note :''' only '''bpy.types.ShaderNode''' will inherit theses properties.&lt;br /&gt;
&lt;br /&gt;
This means we need to port all cycles nodes to this API. The '''gpu_exec''' function should be a direct port from the '''gpu_shader_***''' functions defined in '''source/blender/nodes/shader/nodes/node_shader_*'''. The '''bl_gpu_code''' will be the functions needed by this node that are in '''source/blender/gpu/shaders/gpu_shader_material.glsl'''&lt;br /&gt;
The bl_gpu_code will be only added once per shader.&lt;br /&gt;
&lt;br /&gt;
The compatibility flag is here to prune any node not compatible with the engine before parsing the tree. It is not only for realtime engines but also for offline engines. '''Any node not compatible with the current Engine will be clearly indicated to the user (gray out, ...).'''&lt;br /&gt;
&lt;br /&gt;
Any node that does not have GLSL code will be considered incompatible to realtime engines.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Other Engine ===&lt;br /&gt;
&lt;br /&gt;
Now we will take a look at how a new engine is implemented. For this exemple, we use the future Eevee Engine.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
import bpy&lt;br /&gt;
&lt;br /&gt;
class EeveeRender(RenderEngine):&lt;br /&gt;
	# Enable OpenGL/Vulkan rendering&lt;br /&gt;
	bl_use_realtime_engine = True&lt;br /&gt;
&lt;br /&gt;
	# Enable Internal Features&lt;br /&gt;
	bl_gpu_features = {'PROBES', 'SHADOWS', 'LIGHTS'...}&lt;br /&gt;
&lt;br /&gt;
	# Define it's own library&lt;br /&gt;
	bl_gpu_library = &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
		#define EEVEE_M_PI 3.14&lt;br /&gt;
		vec3 EEVEE_to_tangent(...)&lt;br /&gt;
		...&lt;br /&gt;
		&amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
	# Convertion functions&lt;br /&gt;
	bl_gpu_converts =&amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
		vec4 float_to_vec4(in float val) {return vec4(val);}&lt;br /&gt;
		...&lt;br /&gt;
		&amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
def register():&lt;br /&gt;
	# This line add 'EEVEE' to the bl_compatibility of CyclesMixShaderNode&lt;br /&gt;
	# and reuse Cycles GLSL code&lt;br /&gt;
	add_engine_compatibility('EEVEE', bpy.types.ShaderNodeMixShader)&lt;br /&gt;
&lt;br /&gt;
	# You can also specify you own glsl for the node&lt;br /&gt;
	add_engine_compatibility('EEVEE', bpy.types.ShaderNodeMixShader, &amp;quot;Custom GLSL Code here&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
	# Reconstruct the GLSL hash after all compatibility changes&lt;br /&gt;
	reconstruct_glsl_library()&lt;br /&gt;
	&lt;br /&gt;
def unregister():&lt;br /&gt;
	remove_engine_compatibility('EEVEE', bpy.types.ShaderNodeType)&lt;br /&gt;
&lt;br /&gt;
	reconstruct_glsl_library()&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The '''bl_gpu_converts''' is mandatory to convert i/o sockets in the tree. If a link use an undefined conversion, we let the shader not compile and a use default one. &lt;br /&gt;
&lt;br /&gt;
After parsing, the shader code will look like something like this.&lt;br /&gt;
&lt;br /&gt;
==== Example 1 ====&lt;br /&gt;
Running Eevee, with 2 eevee nodes.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
eevee.gpu_library&lt;br /&gt;
node1.eevee.gpu_code&lt;br /&gt;
node2.eevee.gpu_code&lt;br /&gt;
&lt;br /&gt;
eevee.gpu_converts&lt;br /&gt;
&lt;br /&gt;
void main(){&lt;br /&gt;
 	node1(a,b);&lt;br /&gt;
 	node2(b,c);&lt;br /&gt;
 	gl_FragColor = c;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Only one library and 2 gpu_code are loaded.&lt;br /&gt;
&lt;br /&gt;
==== Example 2 : ====&lt;br /&gt;
Running Eevee, with 1 eevee node and 1 compatible cycles node.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cycles.gpu_library&lt;br /&gt;
node2.gpu_code.cycles&lt;br /&gt;
&lt;br /&gt;
eevee.gpu_library&lt;br /&gt;
node1.gpu_code.eevee&lt;br /&gt;
&lt;br /&gt;
eevee.gpu_converts&lt;br /&gt;
&lt;br /&gt;
void main(){&lt;br /&gt;
 	node1(a,b);&lt;br /&gt;
 	node2(b,c);&lt;br /&gt;
 	gl_FragColor = c;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This time the 2 libraries are needed because we are using code from the 2 engines.&lt;/div&gt;</summary>
		<author><name>wiki&gt;Hypersomniac</name></author>
		
	</entry>
</feed>