Просмотр исходного кода

Update jme3_shaders.adoc

Fixed broken new lines.
Removed unnecessary new line breaks.
Formatted some images to align left rather than using new line breaks to do so.
Added a Note Admonition under jme3 attributes paragraph.
mitm001 8 лет назад
Родитель
Сommit
ee6cb27623
1 измененных файлов с 51 добавлено и 51 удалено
  1. 51 51
      src/docs/asciidoc/jme3/advanced/jme3_shaders.adoc

+ 51 - 51
src/docs/asciidoc/jme3/advanced/jme3_shaders.adoc

@@ -7,25 +7,24 @@
 ifdef::env-github,env-browser[:outfilesuffix: .adoc]
 
 
-+
 
 
 == Shaders Basics
 
-Shaders are sets of instructions that are executed on the GPU. They are used to take advantage of hardware acceleration available on the GPU for rendering purposes.+
-This paper only covers Vertex and Fragment shaders because they are the only ones supported by JME3 for the moment. But be aware that there are some other types of shaders (geometry, tessellation,…).+
-There are multiple frequently used languages that you may encounter to code shaders but as JME3 is based on OpenGL, shaders in JME use GLSL and any example in this paper will be written in GLSL.+
-+
+Shaders are sets of instructions that are executed on the GPU. They are used to take advantage of hardware acceleration available on the GPU for rendering purposes. +
+This paper only covers Vertex and Fragment shaders because they are the only ones supported by JME3 for the moment. But be aware that there are some other types of shaders (geometry, tessellation,…). +
+There are multiple frequently used languages that you may encounter to code shaders but as JME3 is based on OpenGL, shaders in JME use GLSL and any example in this paper will be written in GLSL.
 
 
 === How Does it work?
 
-To keep it Simple: The Vertex shader is executed once for each vertex in the view, then the Fragment shader (also called the Pixel shader) is executed once for each pixel on the screen.+
-The main purpose of the Vertex shader is to compute the screen coordinate of a vertex (where this vertex will be displayed on screen) while the main purpose of the Fragment shader is to compute the color of a pixel.+
-This is a very simplified graphic to describe the call stack: +
-image:jme3/advanced/jme3andshaders.png[jme3andshaders.png,width="",height=""]+
+To keep it Simple: The Vertex shader is executed once for each vertex in the view, then the Fragment shader (also called the Pixel shader) is executed once for each pixel on the screen. +
+The main purpose of the Vertex shader is to compute the screen coordinate of a vertex (where this vertex will be displayed on screen) while the main purpose of the Fragment shader is to compute the color of a pixel. +
+This is a very simplified graphic to describe the call stack: 
+
+image:jme3/advanced/jme3andshaders.png[jme3andshaders.png,width="",height="", align="left] 
+
 The main program sends mesh data to the vertex shader (vertex position in object space, normals, tangents, etc..). The vertex shader computes the screen position of the vertex and sends it to the Fragment shader. The fragment shader computes the color, and the result is displayed on screen or in a texture.
-+
 
 
 === Variables scope
@@ -36,22 +35,22 @@ There are different types of scope for variables in a shader :
 *  attribute : Per-vertex variables passed by the engine to the shader, like position, normal, etc (Mesh data in the graphic)
 *  varying : Variables passed from the vertex shader to the fragment shader.
 
-There is a large panel of variable types to be used, for more information about it I recommend reading the GLSL specification link:http://www.opengl.org/registry/doc/GLSLangSpec.Full.1.20.8.pdf[here].+
-+
+There is a large panel of variable types to be used, for more information about it I recommend reading the GLSL specification link:http://www.opengl.org/registry/doc/GLSLangSpec.Full.1.20.8.pdf[here]. 
 
 
 === Spaces and Matrices
 
-To understand the coming example you must know about the different spaces in 3D computer graphics, and the matrices used to translate coordinate from one space to another.+
-image:jme3/advanced/jme3andshaders-1.png[jme3andshaders-1.png,width="",height=""]+
-The engine passes the object space coordinates to the vertex shader. We need to compute its position in projection space. To do that we transform the object space position by the WorldViewProjectionMatrix which is a combination of the World, View, Projection matrices (who would have guessed?).+
-+
+To understand the coming example you must know about the different spaces in 3D computer graphics, and the matrices used to translate coordinate from one space to another. 
+
+image:jme3/advanced/jme3andshaders-1.png[jme3andshaders-1.png,width="",height="", align="left"]
+
+The engine passes the object space coordinates to the vertex shader. We need to compute its position in projection space. To do that we transform the object space position by the WorldViewProjectionMatrix which is a combination of the World, View, Projection matrices (who would have guessed?).
 
 
 === Simple example : rendering a solid color on an object
 
-Here is the simplest application to shaders, rendering a solid color.+
-Vertex Shader : +
+Here is the simplest application to shaders, rendering a solid color. +
+Vertex Shader : 
 
 [source,java]
 ----
@@ -74,7 +73,7 @@ void main(){
 
 ----
 
-Fragment Shader : +
+Fragment Shader : 
 
 [source,java]
 ----
@@ -88,16 +87,15 @@ void main(){
 
 ----
 
-For example applying this shader to a sphere would render a solid blue sphere on screen.+
-+
+For example applying this shader to a sphere would render a solid blue sphere on screen.
 
 
 == How to use shaders in JME3
 
-You probably heard that JME3 is “shader oriented”, but what does that mean?+
-Usually to use shaders you must create what is called a program. This program specify the vertex shader and the fragment shader to use.+
-JME3 encloses this in the material system. Every material in JME3 uses shaders.+
-For example let’s have a look at the SolidColor.j3md file : +
+You probably heard that JME3 is “shader oriented”, but what does that mean? +
+Usually to use shaders you must create what is called a program. This program specify the vertex shader and the fragment shader to use. +
+JME3 encloses this in the material system. Every material in JME3 uses shaders. +
+For example let’s have a look at the SolidColor.j3md file : 
 
 [source,java]
 ----
@@ -125,17 +123,15 @@ MaterialDef Solid Color {
 
 ----
 
-For more information on JME3 material system, i suggest you read this link:http://jmonkeyengine.org/groups/development-discussion-jme3/forum/topic/jmonkeyengine3-material-system-full-explanation[topic].+
-+
+For more information on JME3 material system, i suggest you read this link:http://jmonkeyengine.org/groups/development-discussion-jme3/forum/topic/jmonkeyengine3-material-system-full-explanation[topic].
 
 
 === JME3 Global uniforms
 
-JME3 can expose pre-computed global uniforms to your shaders. You must specify the one that are required for your shader in the WorldParameters section of the material definition file (.j3md).+
-Note that in the shader the uniform names will be prefixed by a “g_”.+
-In the example above, WorldViewProjectionMatrix is declared as uniform mat4 g_WorldViewProjectionMatrix in the shader.+
-The complete list of global uniforms that can be used in JME3 can be found link:http://code.google.com/p/jmonkeyengine/source/browse/trunk/engine/src/core/com/jme3/shader/UniformBinding.java[here].+
-+
+JME3 can expose pre-computed global uniforms to your shaders. You must specify the one that are required for your shader in the WorldParameters section of the material definition file (.j3md). +
+Note that in the shader the uniform names will be prefixed by a “g_”. +
+In the example above, WorldViewProjectionMatrix is declared as uniform mat4 g_WorldViewProjectionMatrix in the shader. +
+The complete list of global uniforms that can be used in JME3 can be found link:http://code.google.com/p/jmonkeyengine/source/browse/trunk/engine/src/core/com/jme3/shader/UniformBinding.java[here].
 
 
 === JME3 Lighting Global uniforms
@@ -154,22 +150,25 @@ JME3 uses some global uniforms for lighting :
 *  g_AmbientLightColor the color of the ambient light.
 
 These uniforms are passed to the shader without having to declare them in the j3md file, but you have to specify in the technique definition “ LightMode MultiPass see lighting.j3md for more information.
-+
 
 
 === JME3 attributes
 
-Those are different attributes that are always passed to your shader.+
-You can find a complete list of those attribute in the Type enum of the VertexBuffer link:http://code.google.com/p/jmonkeyengine/source/browse/trunk/engine/src/core/com/jme3/scene/VertexBuffer.java[here].+
-Note that in the shader the attributes names will be prefixed by an “in”.+
-+
+Those are different attributes that are always passed to your shader. +
+You can find a complete list of those attribute in the Type enum of the VertexBuffer link:http://code.google.com/p/jmonkeyengine/source/browse/trunk/engine/src/core/com/jme3/scene/VertexBuffer.java[here]. 
+
+[NOTE] 
+====
+In the shader the attributes names will be prefixed by an “in”.
+====
+
 When the enumeration lists some usual types for each attribute (for example texCoord specifies two floats) then that is the format expected by all standard JME3 shaders that use that attribute. When writing your own shaders though you can use alternative formats such as placing three floats in texCoord simply by declaring the attribute as vec3 in the shader and passing 3 as the component count into the mesh setBuffer call.
 
 
 === User's uniforms
 
-At some point when making your own shader you'll need to pass your own uniforms+
-Any uniform has to be declared in the material definition file (.j3md) in the “MaterialParameters section.+
+At some point when making your own shader you'll need to pass your own uniforms +
+Any uniform has to be declared in the material definition file (.j3md) in the “MaterialParameters section.
 
 [source,java]
 ----
@@ -182,7 +181,7 @@ Any uniform has to be declared in the material definition file (.j3md) in the 
 ----
 
 You can also pass some define to your vertex/fragment programs to know if an uniform as been declared. +
-You simply add it in the Defines section of your Technique in the definition file. +
+You simply add it in the Defines section of your Technique in the definition file.
 
 [source,java]
 ----
@@ -193,12 +192,12 @@ You simply add it in the Defines section of your Technique in the definition fil
 
 ----
 
-For integer and floating point parameters, the define will contain the value that was set.+
-For all other types of parameters, the value 1 is defined.+
-If no value is set for that parameter, the define is not declared in the shader.+
+For integer and floating point parameters, the define will contain the value that was set. +
+For all other types of parameters, the value 1 is defined. +
+If no value is set for that parameter, the define is not declared in the shader.
 
 Those material parameters will be sent from the engine to the shader as follows,
-there are setXXXX methods for any type of uniform you want to pass.+
+there are setXXXX methods for any type of uniform you want to pass.
 
 [source,java]
 ----
@@ -210,7 +209,7 @@ there are setXXXX methods for any type of uniform you want to pass.+
 
 To use this uniform in the shader, you need to declare it in the .frag or .vert files (depending on where you need it).
 You can make use of the defines here and later in the code:
-*Note that the “m_ prefix specifies that the uniform is a material parameter.*+
+*Note that the “m_ prefix specifies that the uniform is a material parameter.*
 
 [source,java]
 ----
@@ -232,8 +231,8 @@ player-specific color on models textures. +
 The easiest way of doing this is to use a keyMap which will contain the amount of +
 color to add in its alpha channel. +
 Here I will use this color map: link:http://wstaw.org/m/2011/10/24/plasma-desktopxB2787.jpg[http://wstaw.org/m/2011/10/24/plasma-desktopxB2787.jpg] +
-to blend color on this texture: link:http://wstaw.org/m/2011/10/24/plasma-desktopbq2787.jpg[http://wstaw.org/m/2011/10/24/plasma-desktopbq2787.jpg] +
-+
+to blend color on this texture: link:http://wstaw.org/m/2011/10/24/plasma-desktopbq2787.jpg[http://wstaw.org/m/2011/10/24/plasma-desktopbq2787.jpg] 
+
 We need to pass 2 new parameters to the Lighting.j3md definition, MaterialParameters section :
 
 [source,java]
@@ -282,8 +281,8 @@ if we need to blend it:
 ----
 
 This way, a transparent pixel in the KeyMap texture doesn't modify the color. +
-A black pixel replaces it for the m_KeyColor and values in between are blended.+
-+
+A black pixel replaces it for the m_KeyColor and values in between are blended. 
+
 A result preview can be seen here: link:http://wstaw.org/m/2011/10/24/plasma-desktopuV2787.jpg[http://wstaw.org/m/2011/10/24/plasma-desktopuV2787.jpg]
 
 
@@ -307,12 +306,13 @@ A result preview can be seen here: link:http://wstaw.org/m/2011/10/24/plasma-des
 
 ----
 
-+
 
 
 === JME3 and OpenGL 3 & 4 compatibility
 
-GLSL 1.0 to 1.2 comes with built in attributes and uniforms (ie, gl_Vertex, gl_ModelViewMatrix, etc…).+Those attributes are deprecated since GLSL 1.3 (opengl 3), hence JME3 global uniforms and attributes. Here is a list of deprecated attributes and their equivalent in JME3+
+GLSL 1.0 to 1.2 comes with built in attributes and uniforms (ie, gl_Vertex, gl_ModelViewMatrix, etc…). +
+Those attributes are deprecated since GLSL 1.3 (opengl 3), hence JME3 global uniforms and attributes. Here is a list of deprecated attributes and their equivalent in JME3
+
 [cols="2", options="header"]
 |===