Changeset View
Changeset View
Standalone View
Standalone View
doc/python_api/rst/bge_types/bge.types.KX_BlenderMaterial.rst
| KX_BlenderMaterial(PyObjectPlus) | KX_BlenderMaterial(PyObjectPlus) | ||||
| ================================ | ================================ | ||||
| .. module:: bge.types | .. module:: bge.types | ||||
| base class --- :class:`PyObjectPlus` | base class --- :class:`PyObjectPlus` | ||||
| .. class:: KX_BlenderMaterial(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. | |||||
| .. code-block:: python | |||||
| from bge import logic | |||||
| vertex_shader = """ | |||||
| void main(void) | |||||
| { | |||||
| // original vertex position, no changes | |||||
| gl_Position = ftransform(); | |||||
panzergame: iirc ftransform is a deprecated function in GLSL. it should be :
gl_ProjectionMatrix *… | |||||
| // 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 color_0; | |||||
| uniform sampler2D color_1; | |||||
| uniform float factor; | |||||
| void main(void) | |||||
| { | |||||
| vec4 color_0 = texture2D(color_0, gl_TexCoord[0].st); | |||||
| vec4 color_1 = texture2D(color_1, gl_TexCoord[1].st); | |||||
| gl_FragColor = mix(color_0, color_1, factor); | |||||
| } | |||||
| """ | |||||
| object = logic.getCurrentController().owner | |||||
| object = cont.owner | |||||
Not Done Inline Actionsehh, it's redundant. panzergame: ehh, it's redundant. | |||||
| for mesh in object.meshes: | |||||
| for material in mesh.materials: | |||||
| shader = material.getShader() | |||||
| if shader != None: | |||||
| if not shader.isValid(): | |||||
| shader.setSource(vertex_shader, fragment_shader, True) | |||||
| # get the first texture channel of the material | |||||
| shader.setSampler('color_0', 0) | |||||
| # get the second texture channel of the material | |||||
| shader.setSampler('color_1', 1) | |||||
| # pass another uniform to the shader | |||||
| shader.setUniform1f('factor', 0.3) | |||||
| .. attribute:: shader | .. attribute:: shader | ||||
Not Done Inline Actionsit should be texture_0 panzergame: it should be texture_0 | |||||
| The materials shader. | The materials shader. | ||||
| :type: :class:`BL_Shader` | :type: :class:`BL_Shader` | ||||
| .. attribute:: blending | .. attribute:: blending | ||||
| Ints used for pixel blending, (src, dst), matching the setBlending method. | Ints used for pixel blending, (src, dst), matching the setBlending method. | ||||
| Show All 13 Lines | .. method:: getShader() | ||||
| :return: the material's shader | :return: the material's shader | ||||
| :rtype: :class:`BL_Shader` | :rtype: :class:`BL_Shader` | ||||
| .. method:: setBlending(src, dest) | .. method:: setBlending(src, dest) | ||||
| Set the pixel color arithmetic functions. | Set the pixel color arithmetic functions. | ||||
| :arg src: Specifies how the red, green, blue, and alpha source blending factors are computed. | :arg src: Specifies how the red, green, blue, and alpha source blending factors are computed. | ||||
| :type src: Value in... | :type src: :class:`~bgl.GL_ZERO`, | ||||
| :class:`~bgl.GL_ONE`, | |||||
| * GL_ZERO, | :class:`~bgl.GL_SRC_COLOR`, | ||||
| * GL_ONE, | :class:`~bgl.GL_ONE_MINUS_SRC_COLOR`, | ||||
| * GL_SRC_COLOR, | :class:`~bgl.GL_DST_COLOR`, | ||||
| * GL_ONE_MINUS_SRC_COLOR, | :class:`~bgl.GL_ONE_MINUS_DST_COLOR`, | ||||
| * GL_DST_COLOR, | :class:`~bgl.GL_SRC_ALPHA`, | ||||
| * GL_ONE_MINUS_DST_COLOR, | :class:`~bgl.GL_ONE_MINUS_SRC_ALPHA`, | ||||
| * GL_SRC_ALPHA, | :class:`~bgl.GL_DST_ALPHA`, | ||||
| * GL_ONE_MINUS_SRC_ALPHA, | :class:`~bgl.GL_ONE_MINUS_DST_ALPHA`, | ||||
| * GL_DST_ALPHA, | :class:`~bgl.GL_SRC_ALPHA_SATURATE` | ||||
| * GL_ONE_MINUS_DST_ALPHA, | |||||
| * GL_SRC_ALPHA_SATURATE | |||||
| :arg dest: Specifies how the red, green, blue, and alpha destination blending factors are computed. | :arg dest: Specifies how the red, green, blue, and alpha destination blending factors are computed. | ||||
| :type dest: Value in... | :type dest: :class:`~bgl.GL_ZERO`, | ||||
| :class:`~bgl.GL_ONE`, | |||||
| * GL_ZERO | :class:`~bgl.GL_SRC_COLOR`, | ||||
| * GL_ONE | :class:`~bgl.GL_ONE_MINUS_SRC_COLOR`, | ||||
| * GL_SRC_COLOR | :class:`~bgl.GL_DST_COLOR`, | ||||
| * GL_ONE_MINUS_SRC_COLOR | :class:`~bgl.GL_ONE_MINUS_DST_COLOR`, | ||||
| * GL_DST_COLOR | :class:`~bgl.GL_SRC_ALPHA`, | ||||
| * GL_ONE_MINUS_DST_COLOR | :class:`~bgl.GL_ONE_MINUS_SRC_ALPHA`, | ||||
| * GL_SRC_ALPHA | :class:`~bgl.GL_DST_ALPHA`, | ||||
| * GL_ONE_MINUS_SRC_ALPHA | :class:`~bgl.GL_ONE_MINUS_DST_ALPHA`, | ||||
| * GL_DST_ALPHA | :class:`~bgl.GL_SRC_ALPHA_SATURATE` | ||||
Not Done Inline Actionsit's not better "one of :" instead of "one of…" ? panzergame: it's not better "one of :" instead of "one of…" ? | |||||
| * GL_ONE_MINUS_DST_ALPHA | |||||
| * GL_SRC_ALPHA_SATURATE | |||||
| .. method:: getMaterialIndex() | .. method:: getMaterialIndex() | ||||
| Returns the material's index. | Returns the material's index. | ||||
| :return: the material's index | :return: the material's index | ||||
| :rtype: integer | :rtype: integer | ||||
iirc ftransform is a deprecated function in GLSL. it should be :
gl_ProjectionMatrix * gl_ModelViewMatrix * gl_Vertex