﻿<?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%2FOpenGL%2FShaders</id>
	<title>Dev:2.8/Source/OpenGL/Shaders - 版の履歴</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%2FOpenGL%2FShaders"/>
	<link rel="alternate" type="text/html" href="https://wiki.blender.jp/index.php?title=Dev:2.8/Source/OpenGL/Shaders&amp;action=history"/>
	<updated>2026-07-23T12:25:26Z</updated>
	<subtitle>このウィキのこのページに関する変更履歴</subtitle>
	<generator>MediaWiki 1.31.0</generator>
	<entry>
		<id>https://wiki.blender.jp/index.php?title=Dev:2.8/Source/OpenGL/Shaders&amp;diff=150359&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/OpenGL/Shaders&amp;diff=150359&amp;oldid=prev"/>
		<updated>2018-06-28T21:15:12Z</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:15時点における版&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/OpenGL/Shaders&amp;diff=150358&amp;oldid=prev</id>
		<title>wiki&gt;Ideasman42: /* Tasks */</title>
		<link rel="alternate" type="text/html" href="https://wiki.blender.jp/index.php?title=Dev:2.8/Source/OpenGL/Shaders&amp;diff=150358&amp;oldid=prev"/>
		<updated>2016-06-09T13:21:03Z</updated>

		<summary type="html">&lt;p&gt;‎&lt;span dir=&quot;auto&quot;&gt;&lt;span class=&quot;autocomment&quot;&gt;Tasks&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;新規ページ&lt;/b&gt;&lt;/p&gt;&lt;div&gt;= OpenGL Refactoring: Shaders =&lt;br /&gt;
&lt;br /&gt;
== Overview ==&lt;br /&gt;
&lt;br /&gt;
Shaders must be used for all drawing in the core profile, so we must write our own GLSL shaders with support for drawing textured polgyons, solid lighting, stippling, and so on.&lt;br /&gt;
&lt;br /&gt;
For some drawing code it makes sense to write a custom GLSL shader, but a lot of code only needs basic constant color or textured drawing, and for those cases we should have some shared shaders available that can easily be bound for drawing.&lt;br /&gt;
&lt;br /&gt;
We have APIs for dynamically generating shader code, binding vertex attributes, etc. However this is too much tied to the GLSL material draw mode, and should be made more generic so that it is possible to write custom shaders for various purposes.&lt;br /&gt;
&lt;br /&gt;
== Tasks ==&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;strike&amp;gt;[https://developer.blender.org/D1688 Add polygon stipple support to basic GLSL shader]&amp;lt;/strike&amp;gt;&lt;br /&gt;
* &amp;lt;strike&amp;gt;[https://developer.blender.org/D1694 Port smoke shader to GLSL]&amp;lt;/strike&amp;gt;&lt;br /&gt;
* Add LOD bias in GLSL basic shader for icon drawing&lt;br /&gt;
* Add glShadeModel(GL_FLAT) support in GLSL shaders (using dFdx / dFdy?)&lt;br /&gt;
* Implement texture paint multitexture masking shader in GLSL&lt;br /&gt;
* Optimize basic GLSL shader&lt;br /&gt;
* &amp;lt;strike&amp;gt;Fix remaining draw errors when switching basic shader to use GLSL&amp;lt;/strike&amp;gt;&amp;lt;br&amp;gt; ({{GitCommit|d01499a45c}} {{GitCommit|b9de44f458}} {{GitCommit|5e063ce6c9}} {{GitCommit|eaa19177e7}} {{GitCommit|5bd9e83289}})&lt;br /&gt;
* Add test .blend covering most GLSL material features&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Implement proposal for low level shader API&lt;br /&gt;
** Move GPUVertexAttribs into GPUShader&lt;br /&gt;
** Implement GPUShaderParams&lt;br /&gt;
** Update existing users of GPUShader for API changes&lt;br /&gt;
*** Smoke shaders&lt;br /&gt;
*** Basic shader&lt;br /&gt;
*** GLSL materials&lt;br /&gt;
*** Viewport FX shaders&lt;br /&gt;
*** ...&lt;br /&gt;
* Figure out where to put blend modes, culling, depth tests, .. maybe in GPUShader?&lt;br /&gt;
&lt;br /&gt;
* Convert UI code to use basic shader instead of fixed function&lt;br /&gt;
* &amp;lt;strike&amp;gt;[https://developer.blender.org/D1880 Line width and stipple (not just a shader, requires right geometry too) ]&amp;lt;/strike&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Design Proposal ==&lt;br /&gt;
&lt;br /&gt;
The shader API would have 4 main types.&lt;br /&gt;
&lt;br /&gt;
* GPUShader: a set of compiled GLSL shaders and information about the uniforms, textures, vertex attributes they use. It can represent many types of shaders, for GLSL node materials, matcaps, UI buttons, selected faces, wireframes, etc.&lt;br /&gt;
&lt;br /&gt;
* GPUShaderParams: set of parameters like uniforms and textures for a particular GPUShader. Parameters are stored separately from the GPUShader, so that for example a wireframe shader can be used multiple times but with different colors.&lt;br /&gt;
&lt;br /&gt;
* GPUShaderInstance: GPUShader + list of GPUShaderParams, ready to use for drawing.&lt;br /&gt;
&lt;br /&gt;
* GPUShaderVertexAttribs: a set of vertex attributes required for drawing with a particular GPUShader.&lt;br /&gt;
&lt;br /&gt;
A basic shader could be used like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
GPUShaderInstance shader = GPU_basic_color_shader(rgb_value);&lt;br /&gt;
draw(&amp;amp;shader, vertex_buffers, transformation);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Or in a more advanced case:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
// init material related parameters&lt;br /&gt;
FunkyMaterialParams funky;&lt;br /&gt;
funky.diffuse_color = ...;&lt;br /&gt;
funky.specular_roughness = ...;&lt;br /&gt;
funky.alpha_texture = ...;&lt;br /&gt;
&lt;br /&gt;
// retrieve shared light related parameters&lt;br /&gt;
GPUShaderParams *light_params = view3d_light_parameters(...);&lt;br /&gt;
&lt;br /&gt;
// create shader instance&lt;br /&gt;
GPUShaderInstance shader = funky_shader_new(&amp;amp;funky, light_params);&lt;br /&gt;
&lt;br /&gt;
// create vertex buffers&lt;br /&gt;
GPUVertexBuffers vertex_buffers = vertex_buffers_new();&lt;br /&gt;
for attrib in GPU_shader_vertex_attribs(shader):&lt;br /&gt;
    vertex_buffers.add(...)&lt;br /&gt;
&lt;br /&gt;
// ready to draw&lt;br /&gt;
draw(&amp;amp;shader, vertex_buffers, transformation);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that the above code does not rely on any global state. We do not bind shaders or set a current color, all the information needed is passed explicitly to the draw function.&lt;br /&gt;
&lt;br /&gt;
In GLSL shader code the current transformation is a uniform like any other, but for convenience the draw function can automatically add it to the shader instance.&lt;br /&gt;
&lt;br /&gt;
==== Notes ====&lt;br /&gt;
&lt;br /&gt;
* In most cases the shaders, shader parameters and vertex buffers would be created once and cached for subsequent redraws. Some of those caches would be global (UI drawing shaders) and others tied to specific datablocks and freed along with them (GLSL node materials).&lt;br /&gt;
&lt;br /&gt;
* In Vulkan terminology, a GPUShader is a Pipeline, and GPUShaderParames corresponds to a Descriptor Set.&lt;br /&gt;
&lt;br /&gt;
* With Vulkan draw calls would all go into a command buffer, and multiple such command buffers might be created by multiple threads at the same time. This is something we should aim for in API design, but it will take a while before we get there.&lt;br /&gt;
&lt;br /&gt;
==== Basic Shader Example ====&lt;br /&gt;
&lt;br /&gt;
The implementation of a basic shader would looking something like this. The GPUShader would be cached, not actually compiled every time.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
GPUShaderInstance GPU_basic_color_shader(float color[3])&lt;br /&gt;
{&lt;br /&gt;
    GPUShader *shader = GPU_shader_new(vertex_code, fragment_code, ...);&lt;br /&gt;
&lt;br /&gt;
    GPUShaderParams *params = GPU_shader_params_new(...);&lt;br /&gt;
    GPU_shader_params_set_uniform_vec3(params, &amp;quot;color&amp;quot;, color);&lt;br /&gt;
    GPU_shader_params_finalize(params);&lt;br /&gt;
&lt;br /&gt;
    return GPUShaderInstance(shader, params);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Advanced Shader Example ====&lt;br /&gt;
&lt;br /&gt;
A more complicated shader might look like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
struct FunkyLight&lt;br /&gt;
{&lt;br /&gt;
    float intensity;&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
GPUShaderParams *funky_light_params_new(FunkyLight lights[], int num_lights);&lt;br /&gt;
{&lt;br /&gt;
    GPUShaderParams *params = GPU_shader_params_new(...);&lt;br /&gt;
    for (int i = 0; i &amp;lt; num_lights; i++)&lt;br /&gt;
        GPU_shader_params_set_float(params, &amp;quot;intensity_&amp;quot; + i, lights[i].intensity);&lt;br /&gt;
&lt;br /&gt;
    return params;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
struct FunkMaterialParams&lt;br /&gt;
{&lt;br /&gt;
    float diffuse_color[3];&lt;br /&gt;
    float specular_roughness;&lt;br /&gt;
    GPUTexture *alpha_texture;&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
GPUShaderInstance funky_shader_new(FunkyMaterialParams *funky, GPUShaderParams *light_params)&lt;br /&gt;
{&lt;br /&gt;
    GPUShader *shader = GPU_shader_new(vertex_code, fragment_code, ...);&lt;br /&gt;
&lt;br /&gt;
    GPUShaderParams *material_params = GPU_shader_params_new(...);&lt;br /&gt;
    GPU_shader_params_set_uniform_vec3(material_params, &amp;quot;diffuse_color&amp;quot;, funk-&amp;gt;diffuse_color);&lt;br /&gt;
    ....&lt;br /&gt;
    GPU_shader_params_finalize(params);&lt;br /&gt;
&lt;br /&gt;
    return GPU_shader_instance(shader, material_params, light_params);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;/div&gt;</summary>
		<author><name>wiki&gt;Ideasman42</name></author>
		
	</entry>
</feed>