There can be more than one attribute of that type, they are differenciated by name.
In blender, you can retrieve the attribute data with:
..code-block:: python
mesh.uv_textures[attribute['name']]
:value:5
..data:: CD_MCOL
Vertex attribute is color layer. Data type is vector 4 unsigned byte (RGBA).
There can be more than one attribute of that type, they are differenciated by name.
In blender you can retrieve the attribute data with:
..code-block:: python
mesh.vertex_colors[attribute['name']]
:value:6
..data:: CD_ORCO
Vertex attribute is original coordinates. Data type is vector 3 float.
There can be only 1 attribute of that type per shader.
In blender you can retrieve the attribute data with:
..code-block:: python
mesh.vertices
:value:14
..data:: CD_TANGENT
Vertex attribute is the tangent vector. Data type is vector 4 float.
There can be only 1 attribute of that type per shader.
There is currently no way to retrieve this attribute data via the RNA API but a standalone
C function to compute the tangent layer from the other layers can be obtained from
blender.org.
:value:18
*********
Functions
*********
.._export_shader:
..function:: export_shader(scene,material)
Extracts the GLSL shader producing the visual effect of material in scene for the purpose of
reusing the shader in an external engine. This function is meant to be used in material exporter
so that the GLSL shader can be exported entirely. The return value is a dictionary containing the
shader source code and all associated data.
:arg scene:the scene in which the material in rendered.
:type scene::class:`bpy.types.Scene`
:arg material:the material that you want to export the GLSL shader
:type material::class:`bpy.types.Material`
:return:the shader source code and all associated data in a dictionary
:rtype:dictionary
The dictionary contains the following elements:
* ['fragment'] : string
fragment shader source code.
* ['vertex'] : string
vertex shader source code.
* ['uniforms'] : sequence
list of uniforms used in fragment shader, can be empty list. Each element of the
sequence is a dictionary with the following elements:
* ['varname'] : string
name of the uniform in the fragment shader. Always of the form 'unf<number>'.
* ['datatype'] : integer
data type of the uniform variable. Can be one of the following:
*:data:`gpu.GPU_DATA_1I` : use glUniform1i
*:data:`gpu.GPU_DATA_1F` : use glUniform1fv
*:data:`gpu.GPU_DATA_2F` : use glUniform2fv
*:data:`gpu.GPU_DATA_3F` : use glUniform3fv
*:data:`gpu.GPU_DATA_4F` : use glUniform4fv
*:data:`gpu.GPU_DATA_9F` : use glUniformMatrix3fv
*:data:`gpu.GPU_DATA_16F` : use glUniformMatrix4fv
* ['type'] : integer
type of uniform, determines the origin and method of calculation. See uniform-type_.
Depending on the type, more elements will be be present.
* ['lamp'] : :class:`bpy.types.Object`
Reference to the lamp object from which the uniforms value are extracted. Set for the following uniforms types:
..hlist::
:columns:3
*:data:`gpu.GPU_DYNAMIC_LAMP_DYNVEC`
*:data:`gpu.GPU_DYNAMIC_LAMP_DYNCO`
*:data:`gpu.GPU_DYNAMIC_LAMP_DYNIMAT`
*:data:`gpu.GPU_DYNAMIC_LAMP_DYNPERSMAT`
*:data:`gpu.GPU_DYNAMIC_LAMP_DYNENERGY`
*:data:`gpu.GPU_DYNAMIC_LAMP_DYNCOL`
*:data:`gpu.GPU_DYNAMIC_SAMPLER_2DSHADOW`
Notes:
* The uniforms :data:`gpu.GPU_DYNAMIC_LAMP_DYNVEC`, :data:`gpu.GPU_DYNAMIC_LAMP_DYNCO`, :data:`gpu.GPU_DYNAMIC_LAMP_DYNIMAT` and :data:`gpu.GPU_DYNAMIC_LAMP_DYNPERSMAT`
refer to the lamp object position and orientation, both of can be derived from the object world matrix:
..code-block:: python
obmat = uniform['lamp'].matrix_world
where obmat is the mat4_lamp_to_world_ matrix of the lamp as a 2 dimensional array,
the lamp world location location is in obmat[3].
* The uniform types :data:`gpu.GPU_DYNAMIC_LAMP_DYNENERGY` and :data:`gpu.GPU_DYNAMIC_LAMP_DYNCOL` refer to the lamp data bloc that you get from:
..code-block:: python
la = uniform['lamp'].data
from which you get la.energy and la.color
* Lamp duplication is not supported: if you have duplicated lamps in your scene
(i.e. lamp that are instantiated by dupligroup, etc), this element will only
give you a reference to the orignal lamp and you will not know which instance
of the lamp it is refering too. You can still handle that case in the exporter
by distributing the uniforms amongst the duplicated lamps.
* ['image'] : :class:`bpy.types.Image`
Reference to the image databloc. Set for uniform type :data:`gpu.GPU_DYNAMIC_SAMPLER_2DIMAGE`. You can get the image data from:
..code-block:: python
# full path to image file
uniform['image'].filepath
# image size as a 2-dimensional array of int
uniform['image'].size
* ['texnumber'] : integer
Channel number to which the texture is bound when drawing the object.
Set for uniform types :data:`gpu.GPU_DYNAMIC_SAMPLER_2DBUFFER`, :data:`gpu.GPU_DYNAMIC_SAMPLER_2DIMAGE` and :data:`gpu.GPU_DYNAMIC_SAMPLER_2DSHADOW`.
This is provided for information only: when reusing the shader outside blencer,
you are free to assign the textures to the channel of your choice and to pass
that number channel to the GPU in the uniform.
* ['texpixels'] : byte array
texture data for uniform type :data:`gpu.GPU_DYNAMIC_SAMPLER_2DBUFFER`. Although
the corresponding uniform is a 2D sampler, the texture is always a 1D texture
of n x 1 pixel. The texture size n is provided in ['texsize'] element.
These texture are only used for computer generated texture (colorband, etc).
The texture data is provided so that you can make a real image out of it in the
exporter.
* ['texsize'] : integer
horizontal size of texture for uniform type :data:`gpu.GPU_DYNAMIC_SAMPLER_2DBUFFER`.
The texture data is in ['texpixels'].
* ['attributes'] : sequence
list of attributes used in vertex shader, can be empty. Blender doesn't use
standard attributes except for vertex position and normal. All other vertex
attributes must be passed using the generic glVertexAttrib functions.
The attribute data can be found in the derived mesh custom data using RNA.
Each element of the sequence is a dictionary containing the following elements:
* ['varname'] : string
name of the uniform in the vertex shader. Always of the form 'att<number>'.
* ['datatype'] : integer
data type of vertex attribute, can be one of the following:
*:data:`gpu.GPU_DATA_2F` : use glVertexAttrib2fv
*:data:`gpu.GPU_DATA_3F` : use glVertexAttrib3fv
*:data:`gpu.GPU_DATA_4F` : use glVertexAttrib4fv
*:data:`gpu.GPU_DATA_4UB` : use glVertexAttrib4ubv
* ['number'] : integer
generic attribute number. This is provided for information only. Blender
doesn't use glBindAttribLocation to place generic attributes at specific location,
it lets the shader compiler place the attributes automatically and query the
placement with glGetAttribLocation. The result of this placement is returned in
this element.
When using this shader in a render engine, you should either use
glBindAttribLocation to force the attribute at this location or use
glGetAttribLocation to get the placement chosen by the compiler of your GPU.
* ['type'] : integer
type of the mesh custom data from which the vertex attribute is loaded.
See attribute-type_.
* ['name'] : string or integer
custom data layer name, used for attribute type :data:`gpu.CD_MTFACE` and :data:`gpu.CD_MCOL`.
Example:
..code-block:: python
import gpu
# get GLSL shader of material Mat.001 in scene Scene.001
scene = bpy.data.scenes['Scene.001']
material = bpy.data.materials['Mat.001']
shader = gpu.export_shader(scene,material)
# scan the uniform list and find the images used in the shader
for uniform in shader['uniforms']:
if uniform['type'] == gpu.GPU_DYNAMIC_SAMPLER_2DIMAGE:
print("uniform {0} is using image {1}".format(uniform['varname'], uniform['image'].filepath))