diff --git a/jme3-core/src/main/java/com/jme3/material/Material.java b/jme3-core/src/main/java/com/jme3/material/Material.java index 5f0ab8f91..44bfb73f5 100644 --- a/jme3-core/src/main/java/com/jme3/material/Material.java +++ b/jme3-core/src/main/java/com/jme3/material/Material.java @@ -69,7 +69,7 @@ import java.util.logging.Logger; * Setting the parameters can modify the behavior of a * shader. *
- * + * * @author Kirill Vainer */ public class Material implements CloneableSmartAsset, Cloneable, Savable { @@ -146,7 +146,7 @@ public class Material implements CloneableSmartAsset, Cloneable, Savable { public String getName() { return name; } - + /** * This method sets the name of the material. * The name is not the same as the asset name. @@ -222,11 +222,11 @@ public class Material implements CloneableSmartAsset, Cloneable, Savable { } /** - * Compares two materials and returns true if they are equal. + * Compares two materials and returns true if they are equal. * This methods compare definition, parameters, additional render states. - * Since materials are mutable objects, implementing equals() properly is not possible, + * Since materials are mutable objects, implementing equals() properly is not possible, * hence the name contentEquals(). - * + * * @param otherObj the material to compare to this material * @return true if the materials are equal. */ @@ -234,15 +234,15 @@ public class Material implements CloneableSmartAsset, Cloneable, Savable { if (!(otherObj instanceof Material)) { return false; } - + Material other = (Material) otherObj; - + // Early exit if the material are the same object if (this == other) { return true; } - // Check material definition + // Check material definition if (this.getMaterialDef() != other.getMaterialDef()) { return false; } @@ -251,12 +251,12 @@ public class Material implements CloneableSmartAsset, Cloneable, Savable { if (this.paramValues.size() != other.paramValues.size()) { return false; } - + // Checking technique if (this.technique != null || other.technique != null) { // Techniques are considered equal if their names are the same - // E.g. if user chose custom technique for one material but - // uses default technique for other material, the materials + // E.g. if user chose custom technique for one material but + // uses default technique for other material, the materials // are not equal. String thisDefName = this.technique != null ? this.technique.getDef().getName() : "Default"; String otherDefName = other.technique != null ? other.technique.getDef().getName() : "Default"; @@ -290,7 +290,7 @@ public class Material implements CloneableSmartAsset, Cloneable, Savable { return false; } } - + return true; } @@ -305,7 +305,7 @@ public class Material implements CloneableSmartAsset, Cloneable, Savable { hash = 29 * hash + (this.additionalState != null ? this.additionalState.contentHashCode() : 0); return hash; } - + /** * Returns the currently active technique. *
@@ -436,7 +436,7 @@ public class Material implements CloneableSmartAsset, Cloneable, Savable {
public Collection
@@ -747,30 +747,30 @@ public class Material implements CloneableSmartAsset, Cloneable, Savable {
return 0;
}
- Uniform lightData = shader.getUniform("g_LightData");
- lightData.setVector4Length(numLights * 3);//8 lights * max 3
+ Uniform lightData = shader.getUniform("g_LightData");
+ lightData.setVector4Length(numLights * 3);//8 lights * max 3
Uniform ambientColor = shader.getUniform("g_AmbientLightColor");
-
- if (startIndex != 0) {
+
+ if (startIndex != 0) {
// apply additive blending for 2nd and future passes
rm.getRenderer().applyRenderState(additiveLight);
- ambientColor.setValue(VarType.Vector4, ColorRGBA.Black);
+ ambientColor.setValue(VarType.Vector4, ColorRGBA.Black);
}else{
ambientColor.setValue(VarType.Vector4, getAmbientColor(lightList,true));
}
-
+
int lightDataIndex = 0;
TempVars vars = TempVars.get();
Vector4f tmpVec = vars.vect4f1;
int curIndex;
int endIndex = numLights + startIndex;
for (curIndex = startIndex; curIndex < endIndex && curIndex < lightList.size(); curIndex++) {
-
-
- Light l = lightList.get(curIndex);
+
+
+ Light l = lightList.get(curIndex);
if(l.getType() == Light.Type.Ambient){
- endIndex++;
+ endIndex++;
continue;
}
ColorRGBA color = l.getColor();
@@ -781,14 +781,14 @@ public class Material implements CloneableSmartAsset, Cloneable, Savable {
l.getType().getId(),
lightDataIndex);
lightDataIndex++;
-
+
switch (l.getType()) {
case Directional:
DirectionalLight dl = (DirectionalLight) l;
- Vector3f dir = dl.getDirection();
+ Vector3f dir = dl.getDirection();
//Data directly sent in view space to avoid a matrix mult for each pixel
tmpVec.set(dir.getX(), dir.getY(), dir.getZ(), 0.0f);
- rm.getCurrentCamera().getViewMatrix().mult(tmpVec, tmpVec);
+ rm.getCurrentCamera().getViewMatrix().mult(tmpVec, tmpVec);
// tmpVec.divideLocal(tmpVec.w);
// tmpVec.normalizeLocal();
lightData.setVector4InArray(tmpVec.getX(), tmpVec.getY(), tmpVec.getZ(), -1, lightDataIndex);
@@ -802,7 +802,7 @@ public class Material implements CloneableSmartAsset, Cloneable, Savable {
Vector3f pos = pl.getPosition();
float invRadius = pl.getInvRadius();
tmpVec.set(pos.getX(), pos.getY(), pos.getZ(), 1.0f);
- rm.getCurrentCamera().getViewMatrix().mult(tmpVec, tmpVec);
+ rm.getCurrentCamera().getViewMatrix().mult(tmpVec, tmpVec);
//tmpVec.divideLocal(tmpVec.w);
lightData.setVector4InArray(tmpVec.getX(), tmpVec.getY(), tmpVec.getZ(), invRadius, lightDataIndex);
lightDataIndex++;
@@ -810,37 +810,37 @@ public class Material implements CloneableSmartAsset, Cloneable, Savable {
lightData.setVector4InArray(0,0,0,0, lightDataIndex);
lightDataIndex++;
break;
- case Spot:
+ case Spot:
SpotLight sl = (SpotLight) l;
Vector3f pos2 = sl.getPosition();
Vector3f dir2 = sl.getDirection();
float invRange = sl.getInvSpotRange();
float spotAngleCos = sl.getPackedAngleCos();
tmpVec.set(pos2.getX(), pos2.getY(), pos2.getZ(), 1.0f);
- rm.getCurrentCamera().getViewMatrix().mult(tmpVec, tmpVec);
+ rm.getCurrentCamera().getViewMatrix().mult(tmpVec, tmpVec);
// tmpVec.divideLocal(tmpVec.w);
lightData.setVector4InArray(tmpVec.getX(), tmpVec.getY(), tmpVec.getZ(), invRange, lightDataIndex);
lightDataIndex++;
-
+
//We transform the spot direction in view space here to save 5 varying later in the lighting shader
//one vec4 less and a vec4 that becomes a vec3
//the downside is that spotAngleCos decoding happens now in the frag shader.
tmpVec.set(dir2.getX(), dir2.getY(), dir2.getZ(), 0.0f);
- rm.getCurrentCamera().getViewMatrix().mult(tmpVec, tmpVec);
+ rm.getCurrentCamera().getViewMatrix().mult(tmpVec, tmpVec);
tmpVec.normalizeLocal();
lightData.setVector4InArray(tmpVec.getX(), tmpVec.getY(), tmpVec.getZ(), spotAngleCos, lightDataIndex);
lightDataIndex++;
- break;
+ break;
default:
throw new UnsupportedOperationException("Unknown type of light: " + l.getType());
}
}
- vars.release();
+ vars.release();
//Padding of unsued buffer space
while(lightDataIndex < numLights * 3) {
lightData.setVector4InArray(0f, 0f, 0f, 0f, lightDataIndex);
- lightDataIndex++;
- }
+ lightDataIndex++;
+ }
return curIndex;
}
@@ -887,10 +887,10 @@ public class Material implements CloneableSmartAsset, Cloneable, Savable {
case Directional:
DirectionalLight dl = (DirectionalLight) l;
Vector3f dir = dl.getDirection();
- //FIXME : there is an inconstency here due to backward
+ //FIXME : there is an inconstency here due to backward
//compatibility of the lighting shader.
- //The directional light direction is passed in the
- //LightPosition uniform. The lighting shader needs to be
+ //The directional light direction is passed in the
+ //LightPosition uniform. The lighting shader needs to be
//reworked though in order to fix this.
tmpLightPosition.set(dir.getX(), dir.getY(), dir.getZ(), -1);
lightPos.setValue(VarType.Vector4, tmpLightPosition);
@@ -987,11 +987,11 @@ public class Material implements CloneableSmartAsset, Cloneable, Savable {
for (TechniqueDef techDef : techDefs) {
if (rendererCaps.containsAll(techDef.getRequiredCaps())) {
// use the first one that supports all the caps
- tech = new Technique(this, techDef);
+ tech = new Technique(this, techDef);
techniques.put(name, tech);
if(tech.getDef().getLightMode() == renderManager.getPreferredLightMode() ||
tech.getDef().getLightMode() == LightMode.Disable){
- break;
+ break;
}
}
lastTech = techDef;
@@ -1078,7 +1078,7 @@ public class Material implements CloneableSmartAsset, Cloneable, Savable {
Uniform u = uniforms.getValue(i);
if (!u.isSetByCurrentMaterial()) {
if (u.getName().charAt(0) != 'g') {
- // Don't reset world globals!
+ // Don't reset world globals!
// The benefits gained from this are very minimal
// and cause lots of matrix -> FloatBuffer conversions.
u.clearValue();
@@ -1093,21 +1093,21 @@ public class Material implements CloneableSmartAsset, Cloneable, Savable {
*
* The material is rendered as follows:
*
* An array of light positions and light colors is passed to the shader
* containing the world light list for the geometry being rendered.
*/
SinglePass,
-
+
/**
* Enable light rendering by using multi-pass rendering.
*
@@ -77,7 +77,7 @@ public class TechniqueDef implements Savable {
* passes have it set to black.
*/
MultiPass,
-
+
/**
* @deprecated OpenGL1 is not supported anymore
*/
@@ -96,15 +96,16 @@ public class TechniqueDef implements Savable {
private EnumMap
* Used internally by the J3M/J3MD loader.
- *
+ *
* @param name The name of the technique, should be set to
* Any time the material parameter on the parent material is altered,
- * the appropriate define on the technique will be modified as well.
- * See the method
+ * the appropriate define on the technique will be modified as well.
+ * See the method
* {@link DefineList#set(java.lang.String, com.jme3.shader.VarType, java.lang.Object) }
* on the exact details of how the material parameter changes the define.
- *
+ *
* @param paramName The name of the material parameter to link to.
* @param defineName The name of the define parameter, e.g. USE_LIGHTING
*/
@@ -314,26 +337,26 @@ public class TechniqueDef implements Savable {
/**
* Returns the {@link DefineList} for the preset defines.
- *
+ *
* @return the {@link DefineList} for the preset defines.
- *
- * @see #addShaderPresetDefine(java.lang.String, com.jme3.shader.VarType, java.lang.Object)
+ *
+ * @see #addShaderPresetDefine(java.lang.String, com.jme3.shader.VarType, java.lang.Object)
*/
public DefineList getShaderPresetDefines() {
return presetDefines;
}
-
+
/**
- * Adds a preset define.
+ * Adds a preset define.
*
* Preset defines do not depend upon any parameters to be activated,
* they are always passed to the shader as long as this technique is used.
- *
+ *
* @param defineName The name of the define parameter, e.g. USE_LIGHTING
- * @param type The type of the define. See
+ * @param type The type of the define. See
* {@link DefineList#set(java.lang.String, com.jme3.shader.VarType, java.lang.Object) }
* to see why it matters.
- *
+ *
* @param value The value of the define
*/
public void addShaderPresetDefine(String defineName, VarType type, Object value){
@@ -346,18 +369,18 @@ public class TechniqueDef implements Savable {
/**
* Returns the name of the fragment shader used by the technique, or null
* if no fragment shader is specified.
- *
+ *
* @return the name of the fragment shader to be used.
*/
public String getFragmentShaderName() {
return shaderNames.get(Shader.ShaderType.Fragment);
}
-
+
/**
* Returns the name of the vertex shader used by the technique, or null
* if no vertex shader is specified.
- *
+ *
* @return the name of the vertex shader to be used.
*/
public String getVertexShaderName() {
@@ -370,7 +393,7 @@ public class TechniqueDef implements Savable {
public String getFragmentShaderLanguage() {
return shaderLanguages.get(Shader.ShaderType.Fragment);
}
-
+
/**
* Returns the language of the vertex shader used in this technique.
*/
@@ -390,10 +413,10 @@ public class TechniqueDef implements Savable {
public String getShaderProgramName(Shader.ShaderType shaderType){
return shaderNames.get(shaderType);
}
-
+
/**
* Adds a new world parameter by the given name.
- *
+ *
* @param name The world parameter to add.
* @return True if the world parameter name was found and added
* to the list of world parameters, false otherwise.
@@ -402,7 +425,7 @@ public class TechniqueDef implements Savable {
if (worldBinds == null){
worldBinds = new ArrayList
*
*
- *
- *
- *
- *
*
- *
- *
*
@@ -1147,10 +1147,11 @@ public class Material implements CloneableSmartAsset, Cloneable, Savable {
*/
public void render(Geometry geom, LightList lights, RenderManager rm) {
autoSelectTechnique(rm);
+ TechniqueDef techDef = technique.getDef();
- Renderer r = rm.getRenderer();
+ if (techDef.isNoRender()) return;
- TechniqueDef techDef = technique.getDef();
+ Renderer r = rm.getRenderer();
if (rm.getForcedRenderState() != null) {
r.applyRenderState(rm.getForcedRenderState());
@@ -1169,7 +1170,7 @@ public class Material implements CloneableSmartAsset, Cloneable, Savable {
// reset unchanged uniform flag
clearUniformsSetByCurrent(technique.getShader());
rm.updateUniformBindings(technique.getWorldBindUniforms());
-
+
// setup textures and uniforms
for (int i = 0; i < paramValues.size(); i++) {
@@ -1212,24 +1213,24 @@ public class Material implements CloneableSmartAsset, Cloneable, Savable {
// any unset uniforms will be set to 0
resetUniformsNotSetByCurrent(shader);
r.setShader(shader);
-
+
renderMeshFromGeometry(r, geom);
}
/**
* Called by {@link RenderManager} to render the geometry by
* using this material.
- *
+ *
* Note that this version of the render method
* does not perform light filtering.
- *
+ *
* @param geom The geometry to render
* @param rm The render manager requesting the rendering
*/
public void render(Geometry geom, RenderManager rm) {
render(geom, geom.getWorldLightList(), rm);
}
-
+
public void write(JmeExporter ex) throws IOException {
OutputCapsule oc = ex.getCapsule(this);
oc.write(def.getAssetName(), "material_def", null);
@@ -1304,14 +1305,14 @@ public class Material implements CloneableSmartAsset, Cloneable, Savable {
continue;
}
}
-
+
if (im.getFormatVersion() == 0 && param.getName().startsWith("m_")) {
// Ancient version of jME3 ...
param.setName(param.getName().substring(2));
}
-
+
if (def.getMaterialParam(param.getName()) == null) {
- logger.log(Level.WARNING, "The material parameter is not defined: {0}. Ignoring..",
+ logger.log(Level.WARNING, "The material parameter is not defined: {0}. Ignoring..",
param.getName());
} else {
checkSetParam(param.getVarType(), param.getName());
diff --git a/jme3-core/src/main/java/com/jme3/material/TechniqueDef.java b/jme3-core/src/main/java/com/jme3/material/TechniqueDef.java
index f8152e563..d7523956c 100644
--- a/jme3-core/src/main/java/com/jme3/material/TechniqueDef.java
+++ b/jme3-core/src/main/java/com/jme3/material/TechniqueDef.java
@@ -40,7 +40,7 @@ import java.util.*;
/**
* Describes a technique definition.
- *
+ *
* @author Kirill Vainer
*/
public class TechniqueDef implements Savable {
@@ -49,7 +49,7 @@ public class TechniqueDef implements Savable {
* Version #1: Separate shader language for each shader source.
*/
public static final int SAVABLE_VERSION = 1;
-
+
/**
* Describes light rendering mode.
*/
@@ -58,15 +58,15 @@ public class TechniqueDef implements Savable {
* Disable light-based rendering
*/
Disable,
-
+
/**
- * Enable light rendering by using a single pass.
+ * Enable light rendering by using a single pass.
* null
* for default techniques.
*/
@@ -135,7 +136,7 @@ public class TechniqueDef implements Savable {
/**
* Returns the name of this technique as specified in the J3MD file.
* Default techniques have the name "Default".
- *
+ *
* @return the name of this technique
*/
public String getName(){
@@ -153,9 +154,9 @@ public class TechniqueDef implements Savable {
/**
* Set the light mode
- *
+ *
* @param lightMode the light mode
- *
+ *
* @see LightMode
*/
public void setLightMode(LightMode lightMode) {
@@ -172,9 +173,9 @@ public class TechniqueDef implements Savable {
/**
* Set the shadow mode.
- *
+ *
* @param shadowMode the shadow mode.
- *
+ *
* @see ShadowMode
*/
public void setShadowMode(ShadowMode shadowMode) {
@@ -184,7 +185,7 @@ public class TechniqueDef implements Savable {
/**
* Returns the render state that this technique is using
* @return the render state that this technique is using
- * @see #setRenderState(com.jme3.material.RenderState)
+ * @see #setRenderState(com.jme3.material.RenderState)
*/
public RenderState getRenderState() {
return renderState;
@@ -192,15 +193,37 @@ public class TechniqueDef implements Savable {
/**
* Sets the render state that this technique is using.
- *
+ *
* @param renderState the render state that this technique is using.
- *
+ *
* @see RenderState
*/
public void setRenderState(RenderState renderState) {
this.renderState = renderState;
}
+ /**
+ * Sets if this technique should not be used to render.
+ *
+ * @param noRender not render or render ?
+ *
+ * @see NoRender
+ */
+ public void setNoRender(boolean noRender) {
+ this.noRender = noRender;
+ }
+
+ /**
+ * Returns true if this technique should not be used to render.
+ * (eg. to not render a material with default technique)
+ *
+ * @return true if this technique should not be rendered, false otherwise.
+ *
+ */
+ public boolean isNoRender(){
+ return noRender;
+ }
+
/**
* @deprecated jME3 always requires shaders now
*/
@@ -208,12 +231,12 @@ public class TechniqueDef implements Savable {
public boolean isUsingShaders(){
return true;
}
-
+
/**
* Returns true if this technique uses Shader Nodes, false otherwise.
- *
+ *
* @return true if this technique uses Shader Nodes, false otherwise.
- *
+ *
*/
public boolean isUsingShaderNodes(){
return usesNodes;
@@ -222,7 +245,7 @@ public class TechniqueDef implements Savable {
/**
* Gets the {@link Caps renderer capabilities} that are required
* by this technique.
- *
+ *
* @return the required renderer capabilities
*/
public EnumSet