materials_overview.html 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. <!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><!--[if IE]><meta http-equiv="X-UA-Compatible" content="IE=edge"><![endif]--><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta name="generator" content="Asciidoctor 1.5.4"><meta name="keywords" content="material, texture, MatDefs, light, culling, RenderStates, documentation"><title>Material Definition Properties</title><link rel="stylesheet" href="./asciidoctor.css">
  2. <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.5.0/css/font-awesome.min.css">
  3. <link rel="stylesheet" href="./coderay-asciidoctor.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/docsearch.js/2/docsearch.min.css"><link rel="stylesheet" href="/home/travis/build/jMonkeyEngine/wiki/build/asciidoc/html5/jme3/advanced/twemoji-awesome.css"></head><body class="article toc2 toc-left"><div id="header"><div id="toolbar"><a href="https://github.com/jMonkeyEngine/wiki/edit/master/src/docs/asciidoc/jme3/advanced/materials_overview.adoc"><i class="fa fa-pencil-square" aria-hidden="true"></i></a><a href="https://github.com/jMonkeyEngine/wiki/new/master/src/docs/asciidoc/jme3/advanced/"><i class="fa fa-plus-square" aria-hidden="true"></i></a><input dir="auto" style="position: relative; vertical-align: top;" spellcheck="false" autocomplete="off" class="searchbox__input aa-input" id="doc-search" name="search" placeholder="Search in the doc" required="required" type="search"></div><h1>Material Definition Properties</h1><div class="details"><span class="author" id="author"></span><br><span id="revnumber">version ,</span> <span id="revdate">2016/03/17 20:48</span></div><div id="toc" class="toc2"><div id="toctitle">Table of Contents</div><ul class="sectlevel1"><li><a href="#all-materials-definition-properties">All Materials Definition Properties</a><ul class="sectlevel2"><li><a href="#unshaded-coloring-and-textures">Unshaded Coloring and Textures</a></li><li><a href="#phong-illuminated">Phong Illuminated</a></li><li><a href="#other-test-and-debug">Other: Test and Debug</a></li></ul></li><li><a href="#renderstates">RenderStates</a></li></ul></div></div><div id="content"><div id="preamble"><div class="sectionbody"><div class="paragraph"><p>In jMonkeyEngine 3, colors and textures are represented as Material objects.</p></div>
  4. <div class="ulist"><ul><li><p>All Geometries must have Materials. To improve performance, reuse Materials for similar models, don&#8217;t create a new Material object for every Geometry. (E.g. use one bark Material for several tree models.)</p></li><li><p>Each Material is based on one of jme3&#8217;s default Material Definitions (.j3md files) that are included in the engine. Advanced users can create additional custom Material Definitions (see how it&#8217;s done in the <a href="../../jme3/build_from_sources.html">jme3 sources</a>).</p></li></ul></div>
  5. <div class="admonitionblock tip"><table><tr><td class="icon"><i class="fa icon-tip" title="Tip"></i></td><td class="content"><div class="paragraph"><p>Find out quickly <a href="../../jme3/intermediate/how_to_use_materials.html">How to Use Materials</a>, including the most commonly used code samples and RenderStates.<br>
  6. Or find more background info on <a href="../../jme3/advanced/material_definitions.html">How to use Material Definitions</a>.</p></div></td></tr></table></div></div></div>
  7. <div class="sect2"><h3 id="all-materials-definition-properties">All Materials Definition Properties</h3><div class="paragraph"><p>The following Materials table shows the Material Definitions that jMonkeyEngine 3 supports.</p></div>
  8. <div class="admonitionblock tip"><table><tr><td class="icon"><i class="fa icon-tip" title="Tip"></i></td><td class="content"><div class="paragraph"><p>Looks confusing?<br>
  9. 1) Start learning about <code>Unshaded.j3md</code> and <code>Lighting.j3md</code>, they cover 90% of the cases.<br>
  10. 2) Use <a href="../../sdk/material_editing.html">the SDK&#8217;s visual material editor</a> to try out and save material settings easily.<br>
  11. 3) The <a href="../../sdk/code_editor.html">SDK&#8217;s Palette</a> contains drag&amp;drop code snippets for loading materials.</p></div></td></tr></table></div>
  12. <div class="paragraph"><p>Most Material parameters are optional. For example, it is okay to specify solely the <code>DiffuseMap</code> and <code>NormalMap</code> when using <code>Lighting.j3md</code>, and leave the other texture maps empty. In this case, you are only using a subset of the possible features, but that&#8217;s fine if it already makes in the material look the way that you want. You can always add more texture maps later.</p></div>
  13. <div class="sect2"><h3 id="unshaded-coloring-and-textures">Unshaded Coloring and Textures</h3><div class="paragraph"><p>jMonkeyEngine supports illuminated and unshaded Material Definitions.</p></div>
  14. <div class="ulist"><ul><li><p>Phong Illuminated materials look more naturalistic.</p></li><li><p>Unshaded materials look more abstract.</p></li></ul></div>
  15. <div class="paragraph"><p>&#8220;Unshaded&#8221; materials look somewhat abstract because they ignore lighting and shading. Unshaded Materials work even if the scene does not include a light source. These Materials can be single-colored or textured. For example, they are used for cards and tiles, for the sky, billboards and UI elements, for toon-style games, or for testing.</p></div>
  16. <table class="tableblock frame-all grid-all spread"><caption class="title">Table 1. Standard Unshaded</caption><colgroup><col style="width: 20%;"><col style="width: 30%;"><col style="width: 50%;"></colgroup><thead><tr><th class="tableblock halign-left valign-top">Material Definition</th><th class="tableblock halign-left valign-top">Usage</th><th class="tableblock halign-left valign-top">Material Parameters</th></tr></thead><tbody><tr><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p>Common/MatDefs/Misc/<br>
  17. Unshaded.j3md</p></div></div></td><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p>Standard, non-illuminated Materials.</p></div>
  18. <div class="paragraph"><p>Use this for simple coloring, texturing, glow, and transparency.</p></div>
  19. <div class="paragraph"><p>See also: <a href="../../jme3/beginner/hello_material.html">Hello Material</a></p></div></div></td><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p><strong>Texture Maps</strong><br>
  20. setTexture(&#8220;ColorMap&#8221;, assetManager.loadTexture(&#8220;name&#8221;));<br>
  21. setBoolean(&#8220;SeparateTexCoord&#8221;,true);<br>
  22. setTexture(&#8220;LightMap&#8221;, assetManager.loadTexture(&#8220;name&#8221;));<br>
  23. <strong>Colors</strong><br>
  24. setColor(&#8220;Color&#8221;, ColorRGBA.White);<br>
  25. setBoolean(&#8220;VertexColor&#8221;,true);<br>
  26. <strong>Glow</strong><br>
  27. setTexture(&#8220;GlowMap&#8221;, assetManager.loadTexture(&#8220;name&#8221;));<br>
  28. setColor(&#8220;GlowColor&#8221;, ColorRGBA.White);</p></div></div></td></tr></tbody></table>
  29. <div class="paragraph"><p>Other useful, but less commonly used material definitions:</p></div>
  30. <table class="tableblock frame-all grid-all spread"><caption class="title">Table 2. Special Unshaded</caption><colgroup><col style="width: 20%;"><col style="width: 25%;"><col style="width: 55%;"></colgroup><thead><tr><th class="tableblock halign-left valign-top">Material Definition</th><th class="tableblock halign-left valign-top">Usage</th><th class="tableblock halign-left valign-top">Material Parameters</th></tr></thead><tbody><tr><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p>Common/MatDefs/Misc/<br>
  31. Sky.j3md</p></div></div></td><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p>A solid sky blue, or use with a custom SkyDome texture.</p></div>
  32. <div class="paragraph"><p>See also: <a href="../../jme3/advanced/sky.html">Sky</a></p></div></div></td><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p>setTexture(&#8220;Texture&#8221;, assetManager.loadTexture(&#8220;name&#8221;));<br>
  33. setBoolean(&#8220;SphereMap&#8221;,true);<br>
  34. setVector3(&#8220;NormalScale&#8221;, new Vector3f(0,0,0));</p></div></div></td></tr><tr><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p>Common/MatDefs/Terrain/<br>
  35. Terrain.j3md</p></div></div></td><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p>Splat textures for, e.g. terrains.</p></div>
  36. <div class="paragraph"><p>See also: <a href="../../jme3/beginner/hello_terrain.html">Hello Terrain</a></p></div></div></td><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p>setTexture(&#8220;Tex1&#8221;, assetManager.loadTexture(&#8220;name&#8221;));<br>
  37. (red)<br>
  38. setFloat(&#8220;Tex1Scale&#8221;,1f);<br>
  39. setTexture(&#8220;Tex2&#8221;, assetManager.loadTexture(&#8220;name&#8221;));<br>
  40. (green)<br>
  41. setFloat(&#8220;Tex2Scale&#8221;,1f);<br>
  42. setTexture(&#8220;Tex3&#8221;, assetManager.loadTexture(&#8220;name&#8221;));<br>
  43. (blue)<br>
  44. setFloat(&#8220;Tex3Scale&#8221;,1f);<br>
  45. setTexture(&#8220;Alpha&#8221;, assetManager.loadTexture(&#8220;name&#8221;));</p></div></div></td></tr><tr><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p>Common/MatDefs/Terrain/<br>
  46. HeightBasedTerrain.j3md</p></div></div></td><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p>A multi-layered texture for terrains.</p></div>
  47. <div class="paragraph"><p>Specify four textures and a Vector3f describing the region in which each texture should appear:</p></div>
  48. <div class="paragraph"><p>X = start height,<br>
  49. Y = end height,<br>
  50. Z = texture scale.</p></div>
  51. <div class="paragraph"><p>Texture regions can overlap.</p></div>
  52. <div class="paragraph"><p>For example:</p></div>
  53. <div class="paragraph"><p>Specify a seafloor texture for the lowest areas.</p></div>
  54. <div class="paragraph"><p>A sandy texture for the beaches.</p></div>
  55. <div class="paragraph"><p>A grassy texture for inland areas.</p></div>
  56. <div class="paragraph"><p>A rocky texture for mountain tops.</p></div></div></td><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p>setFloat(&#8220;terrainSize&#8221;,512f);<br>
  57. setTexture(&#8220;region1ColorMap&#8221;, assetManager.loadTexture(&#8220;name&#8221;));<br>
  58. setTexture(&#8220;region2ColorMap&#8221;, assetManager.loadTexture(&#8220;name&#8221;));<br>
  59. setTexture(&#8220;region3ColorMap&#8221;, assetManager.loadTexture(&#8220;name&#8221;));<br>
  60. setTexture(&#8220;region4ColorMap&#8221;, assetManager.loadTexture(&#8220;name&#8221;));<br>
  61. setVector3(&#8220;region1&#8221;, new Vector3f(0,0,0));<br>
  62. setVector3(&#8220;region2&#8221;, new Vector3f(0,0,0));<br>
  63. setVector3(&#8220;region3&#8221;, new Vector3f(0,0,0));<br>
  64. setVector3(&#8220;region4&#8221;, new Vector3f(0,0,0));<br>
  65. <strong>Settings for steep areas:</strong><br>
  66. setTexture(&#8220;slopeColorMap&#8221;, assetManager.loadTexture(&#8220;name&#8221;));<br>
  67. setFloat(&#8220;slopeTileFactor&#8221;,1f);</p></div></div></td></tr><tr><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p>Common/MatDefs/Misc/<br>
  68. Particle.j3md</p></div></div></td><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p>Used with texture masks for particle effects, or for point sprites.</p></div>
  69. <div class="paragraph"><p>The Quadratic value scales the particle for perspective view. (<a href="https://github.com/jMonkeyEngine/jmonkeyengine/blob/master/jme3-core/src/main/java/com/jme3/effect/ParticleEmitter.java">formula</a>)</p></div>
  70. <div class="paragraph"><p>Does support an optional colored glow effect.</p></div>
  71. <div class="paragraph"><p>See also: <a href="../../jme3/beginner/hello_effects.html">Hello Effects</a></p></div></div></td><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p>setTexture(&#8220;Texture&#8221;, assetManager.loadTexture(&#8220;name&#8221;));<br>
  72. setTexture(&#8220;GlowMap&#8221;, assetManager.loadTexture(&#8220;name&#8221;));<br>
  73. setColor(&#8220;GlowColor&#8221;, ColorRGBA.White);<br>
  74. setFloat(&#8220;Quadratic&#8221;,1f);<br>
  75. setBoolean(&#8220;PointSprite&#8221;,true);</p></div></div></td></tr></tbody></table></div>
  76. <div class="sect2"><h3 id="phong-illuminated">Phong Illuminated</h3><div class="paragraph"><p>jMonkeyEngine supports illuminated and unshaded Material Definitions.</p></div>
  77. <div class="ulist"><ul><li><p>Phong Illuminated materials look more naturalistic.</p></li><li><p>Unshaded materials look more abstract.</p></li></ul></div>
  78. <div class="paragraph"><p>Illuminated materials require a <a href="../../jme3/advanced/light_and_shadow.html">light source</a> added to at least one of their parent nodes! (e.g. rootNode.) Illuminated materials are darker on the sides facing away from light sources. They use Phong illumination model (default), or the Ward isotropic gaussian specular shader (WardIso) which looks more like plastic. They do not cast <a href="../../jme3/advanced/light_and_shadow.html">drop shadows</a> unless you use a FilterPostProcessor.</p></div>
  79. <table class="tableblock frame-all grid-all spread"><caption class="title">Table 3. Standard Illuminated</caption><colgroup><col style="width: 20%;"><col style="width: 30%;"><col style="width: 50%;"></colgroup><thead><tr><th class="tableblock halign-left valign-top">Material Definition</th><th class="tableblock halign-left valign-top">Usage</th><th class="tableblock halign-left valign-top">Material Parameters</th></tr></thead><tbody><tr><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p>Common/MatDefs/Light/<br>
  80. Lighting.j3md</p></div></div></td><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p>Commonly used Material with Phong illumination.</p></div>
  81. <div class="paragraph"><p>Use this material together with DiffuseMap, SpecularMap, BumpMap (NormalMaps, ParalaxMap) textures.</p></div>
  82. <div class="paragraph"><p>Supports shininess, transparency, and plain material colors (Diffuse, Ambient, Specular).</p></div>
  83. <div class="paragraph"><p>See also: <a href="../../jme3/beginner/hello_material.html">Hello Material</a></p></div></div></td><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p><strong>Texture Maps</strong><br>
  84. setTexture(&#8220;DiffuseMap&#8221;, assetManager.loadTexture(&#8220;name&#8221;));<br>
  85. setBoolean(&#8220;UseAlpha&#8221;,true); <span class="footnote">[<a class="footnote" id="_footnoteref_1" href="#_footnote_1" title="View footnote.">1</a>]</span> <br>
  86. setTexture(&#8220;NormalMap&#8221;, assetManager.loadTexture(&#8220;name&#8221;));<br>
  87. setBoolean(&#8220;LATC&#8221;,true); <span class="footnote">[<a class="footnote" id="_footnoteref_2" href="#_footnote_2" title="View footnote.">2</a>]</span> <br>
  88. setTexture(&#8220;SpecularMap&#8221;, assetManager.loadTexture(&#8220;name&#8221;));<br>
  89. setFloat(&#8220;Shininess&#8221;,64f);<br>
  90. setTexture(&#8220;ParallaxMap&#8221;, assetManager.loadTexture(&#8220;name&#8221;));<br>
  91. setTexture(&#8220;AlphaMap&#8221;, assetManager.loadTexture(&#8220;name&#8221;));<br>
  92. setFloat(&#8220;AlphaDiscardThreshold&#8221;,1f);<br>
  93. setTexture(&#8220;ColorRamp&#8221;, assetManager.loadTexture(&#8220;name&#8221;));<br>
  94. <strong>Glow</strong><br>
  95. setTexture(&#8220;GlowMap&#8221;, assetManager.loadTexture(&#8220;name&#8221;));<br>
  96. setColor(&#8220;GlowColor&#8221;, ColorRGBA.White);<br>
  97. <strong>Performance and quality</strong><br>
  98. setBoolean(&#8220;VertexLighting&#8221;,true);<br>
  99. setBoolean(&#8220;UseVertexColor&#8221;,true);<br>
  100. setBoolean(&#8220;LowQuality&#8221;,true);<br>
  101. setBoolean(&#8220;HighQuality&#8221;,true);<br>
  102. <strong>Material Colors</strong><br>
  103. setBoolean(&#8220;UseMaterialColors&#8221;,true);<br>
  104. setColor(&#8220;Diffuse&#8221;, ColorRGBA.White);<br>
  105. setColor(&#8220;Ambient&#8221;, ColorRGBA.White);<br>
  106. setColor(&#8220;Specular&#8221;, ColorRGBA.White);<br>
  107. <strong>Tangent shading:</strong><br>
  108. setBoolean(&#8220;VTangent&#8221;,true);<br>
  109. setBoolean(&#8220;Minnaert&#8221;,true); <span class="footnote">[<a class="footnote" id="_footnoteref_3" href="#_footnote_3" title="View footnote.">3</a>]</span><br>
  110. setBoolean(&#8220;WardIso&#8221;,true); <span class="footnote">[<a class="footnote" id="_footnoteref_4" href="#_footnote_4" title="View footnote.">4</a>]</span></p></div><div id="footnotes"><hr><div class="footnote" id="_footnote_1"><a href="#_footnoteref_1">1</a>. UseAlpha specifies whether DiffuseMap uses the alpha channel</div><div class="footnote" id="_footnote_2"><a href="#_footnoteref_2">2</a>. LATC Specifies whether NormalMap is BC5/ATI2n/LATC/3Dc-compressed</div><div class="footnote" id="_footnote_3"><a href="#_footnoteref_3">3</a>. Minnaert is a shader type.</div><div class="footnote" id="_footnote_4"><a href="#_footnoteref_4">4</a>. WardIso is a shader type.</div></div></div></td></tr></tbody></table>
  111. <table class="tableblock frame-all grid-all spread"><caption class="title">Table 4. Special Illuminated</caption><colgroup><col style="width: 20%;"><col style="width: 30%;"><col style="width: 50%;"></colgroup><thead><tr><th class="tableblock halign-left valign-top">Material Definitions</th><th class="tableblock halign-left valign-top">Usage</th><th class="tableblock halign-left valign-top">Material Parameters</th></tr></thead><tbody><tr><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p>Common/MatDefs/Terrain/<br>
  112. TerrainLighting.j3md</p></div></div></td><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p>Same kind of multi-layered splat texture as Terrain.j3md, but with illumination and shading.</p></div>
  113. <div class="paragraph"><p>Typically used for terrains, but works on any mesh.</p></div>
  114. <div class="paragraph"><p>For every three splat textures, you need one alpha map.</p></div>
  115. <div class="paragraph"><p>You can use a total of 11 texture maps in the terrain&#8217;s splat texture:</p></div>
  116. <div class="paragraph"><p>Note that diffuse and normal maps all count against that.</p></div>
  117. <div class="paragraph"><p>For example:</p></div>
  118. <div class="paragraph"><p>You can use a maximum of nine diffuse textures, two of which can have normal maps; or, five textures with both diffuse and normal maps.</p></div></div></td><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p><strong>Texture Splat Maps</strong><br>
  119. setTexture(&#8220;DiffuseMap&#8221;, assetManager.loadTexture(&#8220;name&#8221;));<br>
  120. setFloat(&#8220;DiffuseMap_0_scale&#8221;,1f);<br>
  121. setTexture(&#8220;NormalMap&#8221;, assetManager.loadTexture(&#8220;name&#8221;));<br>
  122. setTexture(&#8220;DiffuseMap_1&#8221;, assetManager.loadTexture(&#8220;name&#8221;));<br>
  123. setFloat(&#8220;DiffuseMap_1_scale&#8221;,1f);<br>
  124. setTexture(&#8220;NormalMap_1&#8221;, assetManager.loadTexture(&#8220;name&#8221;));<br>
  125. setTexture(&#8220;DiffuseMap_2&#8221;, assetManager.loadTexture(&#8220;name&#8221;));<br>
  126. setFloat(&#8220;DiffuseMap_2_scale&#8221;,1f);<br>
  127. setTexture(&#8220;NormalMap_2&#8221;, assetManager.loadTexture(&#8220;name&#8221;));<br>
  128. setTexture(&#8220;DiffuseMap_3&#8221;, assetManager.loadTexture(&#8220;name&#8221;));<br>
  129. setFloat(&#8220;DiffuseMap_3_scale&#8221;,1f);<br>
  130. setTexture(&#8220;NormalMap_3&#8221;, assetManager.loadTexture(&#8220;name&#8221;));<br>
  131. etc, up to 11.<br>
  132. <strong>Alpha Maps</strong><br>
  133. setTexture(&#8220;AlphaMap&#8221;, assetManager.loadTexture("name"));<br>
  134. setTexture(&#8220;AlphaMap_1&#8221;, assetManager.loadTexture(&#8220;name&#8221;));<br>
  135. setTexture(&#8220;AlphaMap_2&#8221;, assetManager.loadTexture(&#8220;name&#8221;));<br>
  136. <strong>Glowing</strong><br>
  137. setTexture(&#8220;GlowMap&#8221;, assetManager.loadTexture(&#8220;name&#8221;));<br>
  138. setColor(&#8220;GlowColor&#8221;, ColorRGBA.White);<br>
  139. <strong>Miscellaneous</strong><br>
  140. setColor(&#8220;Diffuse&#8221;, ColorRGBA.White);<br>
  141. setColor(&#8220;Ambient&#8221;, ColorRGBA.White);<br>
  142. setFloat(&#8220;Shininess&#8221;,64f);<br>
  143. setColor(&#8220;Specular&#8221;, ColorRGBA.White);<br>
  144. setTexture(&#8220;SpecularMap&#8221;, assetManager.loadTexture(&#8220;name&#8221;));<br>
  145. setBoolean(&#8220;WardIso&#8221;,true);<br>
  146. setBoolean(&#8220;useTriPlanarMapping&#8221;,true);<br>
  147. setBoolean(&#8220;isTerrainGrid&#8221;,true);</p></div></div></td></tr><tr><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p>Common/MatDefs/Light/<br>
  148. reflect.j3md</p></div></div></td><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p>Reflective glass material with environment map (CubeMap/SphereMap).</p></div></div></td><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p>setTexture(&#8220;Texture&#8221;, assetManager.loadTexture(&#8220;name&#8221;));<br>
  149. setBoolean(&#8220;SphereMap&#8221;,true);</p></div></div></td></tr></tbody></table></div>
  150. <div class="sect2"><h3 id="other-test-and-debug">Other: Test and Debug</h3><table class="tableblock frame-all grid-all spread"><caption class="title">Table 5. Testing</caption><colgroup><col style="width: 20%;"><col style="width: 80%;"></colgroup><thead><tr><th class="tableblock halign-left valign-top">Material Definition</th><th class="tableblock halign-left valign-top">Usage</th></tr></thead><tbody><tr><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p>Common/MatDefs/Misc/<br>
  151. ShowNormals.j3md</p></div></div></td><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p>A color gradient calculated from the model&#8217;s surface normal&#8217;s. You can use this built-in material to debug the generation of normal&#8217;s in meshes, to preview models that have no material and no lights, or as fall-back default material. This built-in material has no parameters.</p></div></div></td></tr></tbody></table></div></div>
  152. <div class="sect1"><h2 id="renderstates">RenderStates</h2><div class="sectionbody"><table class="tableblock frame-all grid-all spread"><caption class="title">Table 6. Transparancy</caption><colgroup><col style="width: 33.3333%;"><col style="width: 33.3333%;"><col style="width: 33.3334%;"></colgroup><thead><tr><th class="tableblock halign-left valign-top">Material Option</th><th class="tableblock halign-left valign-top">Description</th><th class="tableblock halign-left valign-top">Example</th></tr></thead><tbody><tr><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p>getAdditionalRenderState().<br>
  153. setBlendMode(BlendMode.Off);</p></div></div></td><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p>This is the default, no transparency.</p></div></div></td><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p>Use for all opaque objects like walls, floors, people…</p></div></div></td></tr><tr><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p>getAdditionalRenderState()<br>
  154. .setBlendMode(BlendMode.Alpha);</p></div></div></td><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p>Interpolates the background pixel with the current pixel by using the current pixel&#8217;s alpha.</p></div></div></td><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p>Use this for normal every-day translucency: Frosted window panes, ice, glass, alpha-blended vegetation textures…</p></div></div></td></tr><tr><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p>getAdditionalRenderState()<br>
  155. .setDepthWrite(false);</p></div></div></td><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p>Disables writing of the pixel&#8217;s depth value to the depth buffer.</p></div></div></td><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p>Use this on Materials if you have several transparent/translucent objects obscuring one another, but you want to see through both.</p></div></div></td></tr><tr><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p>getAdditionalRenderState()<br>
  156. .setAlphaFallOff(0.5f);</p></div>
  157. <div class="paragraph"><p>getAdditionalRenderState()<br>
  158. .setAlphaTest(true)</p></div></div></td><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p>Enables Alpha Testing with a &#8220;AlphaDiscardThreshold&#8221; in the AlphaMap.</p></div></div></td><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p>Activate Alpha Testing for (partially) <strong>transparent</strong> objects such as foliage, hair, etc.</p></div>
  159. <div class="paragraph"><p>Deactivate Alpha Testing for gradually <strong>translucent</strong> objects, such as colored glass, smoked glass, ghosts.</p></div></div></td></tr><tr><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p>getAdditionalRenderState()<br>
  160. .setBlendMode(BlendMode.Additive);</p></div></div></td><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p>Additive alpha blending adds colors in a commutative way, i.e. the result does not depend on the order of transparent layers since it adds the scene&#8217;s background pixel color to the current pixel color. This is useful if you have many transparent textures overlapping and don&#8217;t care about the order.</p></div>
  161. <div class="paragraph"><p><strong>Note:</strong> Viewed in front of a white background, Additive textures become fully transparent!</p></div></div></td><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p>This is the default for Particle.j3md-based textures that have a black color background.</p></div></div></td></tr><tr><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p>getAdditionalRenderState()<br>
  162. .setBlendMode(BlendMode.AlphaAdditive);</p></div></div></td><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p>Same as &#8220;Additive&#8221;, except first it multiplies the current pixel color by the pixel alpha.</p></div></div></td><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p>This can be used for particle effects that have alpha as background.</p></div></div></td></tr><tr><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p>getAdditionalRenderState()<br>
  163. .setBlendMode(BlendMode.Color);</p></div></div></td><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p>Blends by color.</p></div></div></td><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p>Generally useless.</p></div></div></td></tr><tr><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p>getAdditionalRenderState()<br>
  164. .setBlendMode(BlendMode.Modulate);</p></div></div></td><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p>Multiplies the background pixel by the current pixel.</p></div></div></td><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p>?</p></div></div></td></tr><tr><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p>getAdditionalRenderState()<br>
  165. .setBlendMode(BlendMode.ModulateX2);</p></div></div></td><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p>Same as &#8220;Modulate&#8221;, except the result is doubled.</p></div></div></td><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p>?</p></div></div></td></tr><tr><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p>getAdditionalRenderState()<br>
  166. .setBlendMode(BlendMode.PremultAlpha);</p></div></div></td><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p>Pre-multiplied alpha blending. E.g. if the color of the object has already been multiplied by its alpha, this is used instead of &#8220;Alpha&#8221; blend mode.</p></div></div></td><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p>For use with Premult Alpha textures.</p></div></div></td></tr></tbody></table>
  167. <div class="paragraph"><p>If the DiffuseMap has an alpha channel, use:</p></div>
  168. <div class="listingblock"><div class="content"><pre class="CodeRay highlight"><code data-lang="java">mat.setBoolean(<span class="string"><span class="delimiter">&quot;</span><span class="content">UseAlpha</span><span class="delimiter">&quot;</span></span>,<span class="predefined-constant">true</span>);</code></pre></div></div>
  169. <div class="paragraph"><p>Later, put the Geometry (not the Material!) in the appropriate render queue.</p></div>
  170. <div class="listingblock"><div class="content"><pre class="CodeRay highlight"><code data-lang="java">geo.setQueueBucket(Bucket.Translucent);</code></pre></div></div>
  171. <div class="paragraph"><p>or</p></div>
  172. <div class="listingblock"><div class="content"><pre class="CodeRay highlight"><code data-lang="java">geo.setQueueBucket(Bucket.Transparent);</code></pre></div></div>
  173. <table class="tableblock frame-all grid-all spread"><caption class="title">Table 7. Culling</caption><colgroup><col style="width: 33.3333%;"><col style="width: 33.3333%;"><col style="width: 33.3334%;"></colgroup><thead><tr><th class="tableblock halign-left valign-top">Material Option</th><th class="tableblock halign-left valign-top">Usage</th><th class="tableblock halign-left valign-top">Example</th></tr></thead><tbody><tr><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p>getAdditionalRenderState()<br>
  174. .setFaceCullMode(FaceCullMode.Back);</p></div></div></td><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p>Activates back-face culling. Mesh faces that are facing away from the camera are not rendered, which saves time.</p></div>
  175. <div class="paragraph"><p><strong>Backface culling is activated by default as a major optimization.</strong></p></div></div></td><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p>The invisible backsides and insides of models are not calculated.</p></div></div></td></tr><tr><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p>getAdditionalRenderState()<br>
  176. .setFaceCullMode(FaceCullMode.Off);</p></div></div></td><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p>No meshes are culled. Both mesh faces are rendered, even if they face away from the camera. Slow.</p></div></div></td><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p>Sometimes used to debug custom meshes if you messed up some of the polygon sides, or for special shadow effects.</p></div></div></td></tr><tr><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p>getAdditionalRenderState()<br>
  177. .setFaceCullMode(FaceCullMode.Front);</p></div></div></td><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p>Activates front-face culling. Mesh faces facing the camera are not rendered.</p></div></div></td><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p>No example – Typically not used because you wouldn&#8217;t see anything meaningful.</p></div></div></td></tr><tr><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p>getAdditionalRenderState()<br>
  178. .setFaceCullMode(FaceCullMode.FrontAndBack)</p></div></div></td><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p>Culls both backfaces and frontfaces.</p></div></div></td><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p>Use this as an efficient way to make an object temporarily invisible, while keeping all its other in-game properties (such as node attachment, collision shapes, interactions, etc.) active.</p></div></div></td></tr></tbody></table>
  179. <table class="tableblock frame-all grid-all spread"><caption class="title">Table 8. Miscellaneous</caption><colgroup><col style="width: 33.3333%;"><col style="width: 33.3333%;"><col style="width: 33.3334%;"></colgroup><thead><tr><th class="tableblock halign-left valign-top">Material Option</th><th class="tableblock halign-left valign-top">Useage</th><th class="tableblock halign-left valign-top">Example</th></tr></thead><tbody><tr><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p>getAdditionalRenderState()<br>
  180. .setColorWrite(false);</p></div></div></td><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p>Disable writing the color of pixels.</p></div></div></td><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p>Use this together with setDepthWrite(true) to write pixels only to the depth buffer, for example.</p></div></div></td></tr><tr><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p>getAdditionalRenderState()<br>
  181. .setPointSprite(true);</p></div></div></td><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p>Enables point-sprite mode, e.g. meshes with &#8220;Mode&#8221;.Points will be rendered as textured sprites.</p></div>
  182. <div class="paragraph"><p>Note that gl_PointCoord must be set in the shader.</p></div></div></td><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p>Point sprites are used internally for hardware accelerated particle effects.</p></div></div></td></tr><tr><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p>getAdditionalRenderState()<br>
  183. .setPolyOffset();</p></div></div></td><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p>Enable polygon offset.</p></div></div></td><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p>Use this when you have meshes that have triangles really close to each over (e.g. <a href="http://en.wikipedia.org/wiki/Coplanarity">Coplanar</a>), it will shift the depth values to prevent <a href="http://en.wikipedia.org/wiki/Z-fighting">Z-fighting</a>.</p></div></div></td></tr></tbody></table>
  184. <div class="paragraph"><p><strong>Related Links</strong></p></div>
  185. <div class="ulist"><ul><li><p><a href="../../jme3/advanced/material_specification.html">Developer specification of the jME3 material system (.j3md,.j3m)</a></p></li></ul></div></div></div></div><div id="footer"><div id="footer-text">Version <br>Last updated 2019-12-20 23:30:51 +00:00</div></div><script type="text/javascript" src="https://cdn.jsdelivr.net/docsearch.js/2/docsearch.min.js"></script><script>docsearch({
  186. apiKey: 'a736b6d93de805e26ec2f49b55013fbd',
  187. indexName: 'jmonkeyengine',
  188. inputSelector: '#doc-search',
  189. debug: false // Set debug to true if you want to inspect the dropdown
  190. });</script></body></html>