use of com.jme3.shader.Shader in project jmonkeyengine by jMonkeyEngine.
the class TechniqueDef method setShaderFile.
/**
* Sets the shaders that this technique definition will use.
*
* @param shaderNames EnumMap containing all shader names for this stage
* @param shaderLanguages EnumMap containing all shader languages for this stage
*/
public void setShaderFile(EnumMap<Shader.ShaderType, String> shaderNames, EnumMap<Shader.ShaderType, String> shaderLanguages) {
requiredCaps.clear();
weight = 0;
for (Shader.ShaderType shaderType : shaderNames.keySet()) {
String language = shaderLanguages.get(shaderType);
String shaderFile = shaderNames.get(shaderType);
this.shaderLanguages.put(shaderType, language);
this.shaderNames.put(shaderType, shaderFile);
Caps cap = Caps.valueOf(language);
requiredCaps.add(cap);
weight = Math.max(weight, cap.ordinal());
if (shaderType.equals(Shader.ShaderType.Geometry)) {
requiredCaps.add(Caps.GeometryShader);
} else if (shaderType.equals(Shader.ShaderType.TessellationControl)) {
requiredCaps.add(Caps.TesselationShader);
}
}
}
use of com.jme3.shader.Shader in project jmonkeyengine by jMonkeyEngine.
the class TechniqueDef method setShaderFile.
/**
* Sets the shaders that this technique definition will use.
*
* @param vertexShader The name of the vertex shader
* @param fragmentShader The name of the fragment shader
* @param vertLanguage The vertex shader language
* @param fragLanguage The fragment shader language
*/
public void setShaderFile(String vertexShader, String fragmentShader, String vertLanguage, String fragLanguage) {
this.shaderLanguages.put(Shader.ShaderType.Vertex, vertLanguage);
this.shaderNames.put(Shader.ShaderType.Vertex, vertexShader);
this.shaderLanguages.put(Shader.ShaderType.Fragment, fragLanguage);
this.shaderNames.put(Shader.ShaderType.Fragment, fragmentShader);
requiredCaps.clear();
Caps vertCap = Caps.valueOf(vertLanguage);
requiredCaps.add(vertCap);
Caps fragCap = Caps.valueOf(fragLanguage);
requiredCaps.add(fragCap);
weight = Math.max(vertCap.ordinal(), fragCap.ordinal());
}
use of com.jme3.shader.Shader in project jmonkeyengine by jMonkeyEngine.
the class HDRRenderer method initialize.
public void initialize(RenderManager rm, ViewPort vp) {
if (!enabled)
return;
renderer = rm.getRenderer();
renderManager = rm;
viewPort = vp;
// loadInitial()
fsQuad = new Picture("HDR Fullscreen Quad");
Format lumFmt = Format.RGB8;
scene64FB = new FrameBuffer(64, 64, 1);
scene64 = new Texture2D(64, 64, lumFmt);
scene64FB.setColorTexture(scene64);
scene64.setMagFilter(fbMagFilter);
scene64.setMinFilter(fbMinFilter);
scene8FB = new FrameBuffer(8, 8, 1);
scene8 = new Texture2D(8, 8, lumFmt);
scene8FB.setColorTexture(scene8);
scene8.setMagFilter(fbMagFilter);
scene8.setMinFilter(fbMinFilter);
scene1FB[0] = new FrameBuffer(1, 1, 1);
scene1[0] = new Texture2D(1, 1, lumFmt);
scene1FB[0].setColorTexture(scene1[0]);
scene1FB[1] = new FrameBuffer(1, 1, 1);
scene1[1] = new Texture2D(1, 1, lumFmt);
scene1FB[1].setColorTexture(scene1[1]);
// prepare tonemap shader
tone = new Material(manager, "Common/MatDefs/Hdr/ToneMap.j3md");
tone.setFloat("A", 0.18f);
tone.setFloat("White", 100);
// load();
int w = vp.getCamera().getWidth();
int h = vp.getCamera().getHeight();
reshape(vp, w, h);
}
use of com.jme3.shader.Shader in project jmonkeyengine by jMonkeyEngine.
the class GLRenderer method setVertexAttrib.
public void setVertexAttrib(VertexBuffer vb, VertexBuffer idb) {
if (vb.getBufferType() == VertexBuffer.Type.Index) {
throw new IllegalArgumentException("Index buffers not allowed to be set to vertex attrib");
}
if (context.boundShaderProgram <= 0) {
throw new IllegalStateException("Cannot render mesh without shader bound");
}
Attribute attrib = context.boundShader.getAttribute(vb.getBufferType());
int loc = attrib.getLocation();
if (loc == -1) {
// not defined
return;
}
if (loc == -2) {
loc = gl.glGetAttribLocation(context.boundShaderProgram, "in" + vb.getBufferType().name());
// the internal name of the enum (Position).
if (loc < 0) {
attrib.setLocation(-1);
// not available in shader.
return;
} else {
attrib.setLocation(loc);
}
}
if (vb.isInstanced()) {
if (!caps.contains(Caps.MeshInstancing)) {
throw new RendererException("Instancing is required, " + "but not supported by the " + "graphics hardware");
}
}
int slotsRequired = 1;
if (vb.getNumComponents() > 4) {
if (vb.getNumComponents() % 4 != 0) {
throw new RendererException("Number of components in multi-slot " + "buffers must be divisible by 4");
}
slotsRequired = vb.getNumComponents() / 4;
}
if (vb.isUpdateNeeded() && idb == null) {
updateBufferData(vb);
}
VertexBuffer[] attribs = context.boundAttribs;
for (int i = 0; i < slotsRequired; i++) {
if (!context.attribIndexList.moveToNew(loc + i)) {
gl.glEnableVertexAttribArray(loc + i);
}
}
if (attribs[loc] != vb) {
// NOTE: Use id from interleaved buffer if specified
int bufId = idb != null ? idb.getId() : vb.getId();
assert bufId != -1;
if (context.boundArrayVBO != bufId) {
gl.glBindBuffer(GL.GL_ARRAY_BUFFER, bufId);
context.boundArrayVBO = bufId;
//statistics.onVertexBufferUse(vb, true);
} else {
//statistics.onVertexBufferUse(vb, false);
}
if (slotsRequired == 1) {
gl.glVertexAttribPointer(loc, vb.getNumComponents(), convertFormat(vb.getFormat()), vb.isNormalized(), vb.getStride(), vb.getOffset());
} else {
for (int i = 0; i < slotsRequired; i++) {
// The pointer maps the next 4 floats in the slot.
// E.g.
// P1: XXXX____________XXXX____________
// P2: ____XXXX____________XXXX________
// P3: ________XXXX____________XXXX____
// P4: ____________XXXX____________XXXX
// stride = 4 bytes in float * 4 floats in slot * num slots
// offset = 4 bytes in float * 4 floats in slot * slot index
gl.glVertexAttribPointer(loc + i, 4, convertFormat(vb.getFormat()), vb.isNormalized(), 4 * 4 * slotsRequired, 4 * 4 * i);
}
}
for (int i = 0; i < slotsRequired; i++) {
int slot = loc + i;
if (vb.isInstanced() && (attribs[slot] == null || !attribs[slot].isInstanced())) {
// non-instanced -> instanced
glext.glVertexAttribDivisorARB(slot, vb.getInstanceSpan());
} else if (!vb.isInstanced() && attribs[slot] != null && attribs[slot].isInstanced()) {
// instanced -> non-instanced
glext.glVertexAttribDivisorARB(slot, 0);
}
attribs[slot] = vb;
}
}
}
use of com.jme3.shader.Shader in project jmonkeyengine by jMonkeyEngine.
the class OpaqueComparator method compare.
@Override
public int compare(Geometry o1, Geometry o2) {
Material m1 = o1.getMaterial();
Material m2 = o2.getMaterial();
int compareResult = Integer.compare(m1.getSortId(), m2.getSortId());
if (compareResult == 0) {
// use the same shader.
// sort front-to-back then.
float d1 = distanceToCam(o1);
float d2 = distanceToCam(o2);
if (d1 == d2)
return 0;
else if (d1 < d2)
return -1;
else
return 1;
} else {
return compareResult;
}
}
Aggregations