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:
Diffstat (limited to 'doc/python_api/rst/bge_types/bge.types.KX_BlenderMaterial.rst')
-rw-r--r--doc/python_api/rst/bge_types/bge.types.KX_BlenderMaterial.rst119
1 files changed, 88 insertions, 31 deletions
diff --git a/doc/python_api/rst/bge_types/bge.types.KX_BlenderMaterial.rst b/doc/python_api/rst/bge_types/bge.types.KX_BlenderMaterial.rst
index 0dfc7a10d13..80450526c9a 100644
--- a/doc/python_api/rst/bge_types/bge.types.KX_BlenderMaterial.rst
+++ b/doc/python_api/rst/bge_types/bge.types.KX_BlenderMaterial.rst
@@ -7,11 +7,66 @@ base class --- :class:`PyObjectPlus`
.. class:: KX_BlenderMaterial(PyObjectPlus)
- KX_BlenderMaterial
+ This is the interface to materials in the game engine.
+
+ Materials define the render state to be applied to mesh objects.
+
+ The example below shows a simple GLSL shader setup allowing to dynamically mix two texture channels
+ in a material. All materials of the object executing this script should have two textures using
+ separate UV maps in the two first texture channels.
+
+ The code works for both Multitexture and GLSL rendering modes.
+
+ .. code-block:: python
+
+ from bge import logic
+
+ vertex_shader = """
+
+ void main(void)
+ {
+ // simple projection of the vertex position to view space
+ gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
+ // coordinate of the 1st texture channel
+ gl_TexCoord[0] = gl_MultiTexCoord0;
+ // coordinate of the 2nd texture channel
+ gl_TexCoord[1] = gl_MultiTexCoord1;
+ }
+ """
+
+ fragment_shader ="""
+
+ uniform sampler2D texture_0;
+ uniform sampler2D texture_1;
+ uniform float factor;
+
+ void main(void)
+ {
+ vec4 color_0 = texture2D(texture_0, gl_TexCoord[0].st);
+ vec4 color_1 = texture2D(texture_1, gl_TexCoord[1].st);
+ gl_FragColor = mix(color_0, color_1, factor);
+ }
+ """
+
+ object = logic.getCurrentController().owner
+
+ for mesh in object.meshes:
+ for material in mesh.materials:
+ shader = material.getShader()
+ if shader is not None:
+ if not shader.isValid():
+ shader.setSource(vertex_shader, fragment_shader, True)
+
+ # get the first texture channel of the material
+ shader.setSampler('texture_0', 0)
+ # get the second texture channel of the material
+ shader.setSampler('texture_1', 1)
+ # pass another uniform to the shader
+ shader.setUniform1f('factor', 0.3)
.. attribute:: shader
- The materials shader.
+ The material's shader.
:type: :class:`BL_Shader`
@@ -38,35 +93,37 @@ base class --- :class:`PyObjectPlus`
Set the pixel color arithmetic functions.
- :arg src: Specifies how the red, green, blue, and alpha source blending factors are computed.
- :type src: Value in...
-
- * GL_ZERO,
- * GL_ONE,
- * GL_SRC_COLOR,
- * GL_ONE_MINUS_SRC_COLOR,
- * GL_DST_COLOR,
- * GL_ONE_MINUS_DST_COLOR,
- * GL_SRC_ALPHA,
- * GL_ONE_MINUS_SRC_ALPHA,
- * GL_DST_ALPHA,
- * GL_ONE_MINUS_DST_ALPHA,
- * GL_SRC_ALPHA_SATURATE
-
- :arg dest: Specifies how the red, green, blue, and alpha destination blending factors are computed.
- :type dest: Value in...
-
- * GL_ZERO
- * GL_ONE
- * GL_SRC_COLOR
- * GL_ONE_MINUS_SRC_COLOR
- * GL_DST_COLOR
- * GL_ONE_MINUS_DST_COLOR
- * GL_SRC_ALPHA
- * GL_ONE_MINUS_SRC_ALPHA
- * GL_DST_ALPHA
- * GL_ONE_MINUS_DST_ALPHA
- * GL_SRC_ALPHA_SATURATE
+ :arg src: Specifies how the red, green, blue, and alpha source blending factors are computed, one of...
+
+ * :data:`~bgl.GL_ZERO`
+ * :data:`~bgl.GL_ONE`
+ * :data:`~bgl.GL_SRC_COLOR`
+ * :data:`~bgl.GL_ONE_MINUS_SRC_COLOR`
+ * :data:`~bgl.GL_DST_COLOR`
+ * :data:`~bgl.GL_ONE_MINUS_DST_COLOR`
+ * :data:`~bgl.GL_SRC_ALPHA`
+ * :data:`~bgl.GL_ONE_MINUS_SRC_ALPHA`
+ * :data:`~bgl.GL_DST_ALPHA`
+ * :data:`~bgl.GL_ONE_MINUS_DST_ALPHA`
+ * :data:`~bgl.GL_SRC_ALPHA_SATURATE`
+
+ :type src: int
+
+ :arg dest: Specifies how the red, green, blue, and alpha destination blending factors are computed, one of...
+
+ * :data:`~bgl.GL_ZERO`
+ * :data:`~bgl.GL_ONE`
+ * :data:`~bgl.GL_SRC_COLOR`
+ * :data:`~bgl.GL_ONE_MINUS_SRC_COLOR`
+ * :data:`~bgl.GL_DST_COLOR`
+ * :data:`~bgl.GL_ONE_MINUS_DST_COLOR`
+ * :data:`~bgl.GL_SRC_ALPHA`
+ * :data:`~bgl.GL_ONE_MINUS_SRC_ALPHA`
+ * :data:`~bgl.GL_DST_ALPHA`
+ * :data:`~bgl.GL_ONE_MINUS_DST_ALPHA`
+ * :data:`~bgl.GL_SRC_ALPHA_SATURATE`
+
+ :type dest: int
.. method:: getMaterialIndex()