com.jme3.texture.Texture2D Java Examples

The following examples show how to use com.jme3.texture.Texture2D. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CombinedTexture.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/**
 * This method adds a texture data to the resulting texture.
 * 
 * @param texture
 *            the source texture
 * @param textureBlender
 *            the texture blender (to mix the texture with its material
 *            color)
 * @param uvCoordinatesType
 *            the type of UV coordinates
 * @param projectionType
 *            the type of UV coordinates projection (for flat textures)
 * @param textureStructure
 *            the texture sructure
 * @param blenderContext
 *            the blender context
 */
public void add(Texture texture, TextureBlender textureBlender, int uvCoordinatesType, int projectionType, Structure textureStructure, BlenderContext blenderContext) {
    if (!(texture instanceof GeneratedTexture) && !(texture instanceof Texture2D)) {
        throw new IllegalArgumentException("Unsupported texture type: " + (texture == null ? "null" : texture.getClass()));
    }
    if (!(texture instanceof GeneratedTexture) || blenderContext.getBlenderKey().isLoadGeneratedTextures()) {
        if (UVCoordinatesGenerator.isTextureCoordinateTypeSupported(UVCoordinatesType.valueOf(uvCoordinatesType))) {
            TextureData textureData = new TextureData();
            textureData.texture = texture;
            textureData.textureBlender = textureBlender;
            textureData.uvCoordinatesType = UVCoordinatesType.valueOf(uvCoordinatesType);
            textureData.projectionType = UVProjectionType.valueOf(projectionType);
            textureData.textureStructure = textureStructure;

            if (textureDatas.size() > 0 && this.isWithoutAlpha(textureData, blenderContext)) {
                textureDatas.clear();// clear previous textures, they will be covered anyway
            }
            textureDatas.add(textureData);
        } else {
            LOGGER.warning("The texture coordinates type is not supported: " + UVCoordinatesType.valueOf(uvCoordinatesType) + ". The texture '" + textureStructure.getName() + "'.");
        }
    }
}
 
Example #2
Source File: CombinedTexture.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/**
 * This method scales the given texture to the given size.
 * 
 * @param texture
 *            the texture to be scaled
 * @param width
 *            new width of the texture
 * @param height
 *            new height of the texture
 */
private void scale(Texture2D texture, int width, int height) {
    // first determine if scaling is required
    boolean scaleRequired = texture.getImage().getWidth() != width || texture.getImage().getHeight() != height;

    if (scaleRequired) {
        Image image = texture.getImage();
        BufferedImage sourceImage = ImageToAwt.convert(image, false, true, 0);

        int sourceWidth = sourceImage.getWidth();
        int sourceHeight = sourceImage.getHeight();

        BufferedImage targetImage = new BufferedImage(width, height, sourceImage.getType());

        Graphics2D g = targetImage.createGraphics();
        g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
        g.drawImage(sourceImage, 0, 0, width, height, 0, 0, sourceWidth, sourceHeight, null);
        g.dispose();

        Image output = new ImageLoader().load(targetImage, false);
        image.setWidth(width);
        image.setHeight(height);
        image.setData(output.getData(0));
        image.setFormat(output.getFormat());
    }
}
 
Example #3
Source File: MaterialMatParamTest.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Test
public void testRemoveTextureOverride() {
    material("Common/MatDefs/Light/Lighting.j3md");
    Texture2D tex1 = new Texture2D(128, 128, Format.RGBA8);
    Texture2D tex2 = new Texture2D(128, 128, Format.RGBA8);

    reset();
    inputMp(mpoTexture2D("DiffuseMap", tex1));
    outDefines(def("DIFFUSEMAP", VarType.Texture2D, tex1));
    outUniforms(uniform("DiffuseMap", VarType.Int, 0));
    outTextures(tex1);

    reset();
    inputMpo(mpoTexture2D("DiffuseMap", tex2));
    outDefines(def("DIFFUSEMAP", VarType.Texture2D, tex2));
    outUniforms(uniform("DiffuseMap", VarType.Int, 0));
    outTextures(tex2);

    reset();
    geometry.clearMatParamOverrides();
    root.updateGeometricState();
    outDefines(def("DIFFUSEMAP", VarType.Texture2D, tex1));
    outUniforms(uniform("DiffuseMap", VarType.Int, 0));
    outTextures(tex1);
}
 
Example #4
Source File: MaterialMatParamTest.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Test
public void testRemoveTexture() {
    material("Common/MatDefs/Light/Lighting.j3md");
    Texture2D tex = new Texture2D(128, 128, Format.RGBA8);

    reset();
    inputMpo(mpoTexture2D("DiffuseMap", tex));
    outDefines(def("DIFFUSEMAP", VarType.Texture2D, tex));
    outUniforms(uniform("DiffuseMap", VarType.Int, 0));
    outTextures(tex);

    reset();
    geometry.clearMatParamOverrides();
    root.updateGeometricState();
    outDefines();
    outUniforms();
    outTextures();
}
 
Example #5
Source File: GltfLoader.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public Texture2D readTexture(JsonObject texture, boolean flip) throws IOException {
    if (texture == null) {
        return null;
    }
    Integer textureIndex = getAsInteger(texture, "index");
    assertNotNull(textureIndex, "Texture has no index");
    assertNotNull(textures, "There are no textures, yet one is referenced by a material");

    JsonObject textureData = textures.get(textureIndex).getAsJsonObject();
    Integer sourceIndex = getAsInteger(textureData, "source");
    Integer samplerIndex = getAsInteger(textureData, "sampler");

    Texture2D texture2d = readImage(sourceIndex, flip);

    if (samplerIndex != null) {
        texture2d = readSampler(samplerIndex, texture2d);
    } else {
        texture2d.setWrap(Texture.WrapMode.Repeat);
    }

    texture2d = customContentManager.readExtensionAndExtras("texture", texture, texture2d);

    return texture2d;
}
 
Example #6
Source File: PssmShadowRenderer.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/**
 * Sets the filtering mode for shadow edges see {@link FilterMode} for more info
 * @param filterMode 
 */
public void setFilterMode(FilterMode filterMode) {
    if (filterMode == null) {
        throw new NullPointerException();
    }

    if (this.filterMode == filterMode) {
        return;
    }

    this.filterMode = filterMode;
    postshadowMat.setInt("FilterMode", filterMode.ordinal());
    postshadowMat.setFloat("PCFEdge", edgesThickness);
    if (compareMode == CompareMode.Hardware) {
        for (Texture2D shadowMap : shadowMaps) {
            if (filterMode == FilterMode.Bilinear) {
                shadowMap.setMagFilter(MagFilter.Bilinear);
                shadowMap.setMinFilter(MinFilter.BilinearNoMipMaps);
            } else {
                shadowMap.setMagFilter(MagFilter.Nearest);
                shadowMap.setMinFilter(MinFilter.NearestNoMipMaps);
            }
        }
    }
}
 
Example #7
Source File: FbxTexture.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public FbxTexture(SceneLoader scene, FbxElement element) {
	super(scene, element);
	for(FbxElement e : element.children) {
		switch(e.id) {
		case "Type":
			bindType = (String) e.properties.get(0);
			break;
		case "FileName":
			filename = (String) e.properties.get(0);
			break;
		}
	}
	texture = new Texture2D();
	texture.setName(name);
	texture.setWrap(WrapMode.Repeat); // Default FBX wrapping. TODO: Investigate where this is stored (probably, in material)
}
 
Example #8
Source File: AbstractShadowRenderer.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Sets the shadow compare mode. See {@link CompareMode} for more info.
 *
 * @param compareMode the desired compare mode (not null)
 */
final public void setShadowCompareMode(CompareMode compareMode) {
    if (compareMode == null) {
        throw new IllegalArgumentException("Shadow compare mode cannot be null");
    }

    this.shadowCompareMode = compareMode;
    for (Texture2D shadowMap : shadowMaps) {
        if (compareMode == CompareMode.Hardware) {
            shadowMap.setShadowCompareMode(ShadowCompareMode.LessOrEqual);
            if (edgeFilteringMode == EdgeFilteringMode.Bilinear) {
                shadowMap.setMagFilter(MagFilter.Bilinear);
                shadowMap.setMinFilter(MinFilter.BilinearNoMipMaps);
            } else {
                shadowMap.setMagFilter(MagFilter.Nearest);
                shadowMap.setMinFilter(MinFilter.NearestNoMipMaps);
            }
        } else {
            shadowMap.setShadowCompareMode(ShadowCompareMode.Off);
            shadowMap.setMagFilter(MagFilter.Nearest);
            shadowMap.setMinFilter(MinFilter.NearestNoMipMaps);
        }
    }
    postshadowMat.setBoolean("HardwareShadows", compareMode == CompareMode.Hardware);
}
 
Example #9
Source File: MaterialLoader.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private void readTextureUnit(Statement statement){
    String[] split = statement.getLine().split(" ", 2); 
    // name is optional
    if (split.length == 2){
        texName = split[1];
    }else{
        texName = null;
    }

    textures[texUnit] = new Texture2D();
    for (Statement texUnitStat : statement.getContents()){
        readTextureUnitStatement(texUnitStat);
    }
    if (textures[texUnit].getImage() != null){
        texUnit++;
    }else{
        // no image was loaded, ignore
        textures[texUnit] = null;
    }
}
 
Example #10
Source File: BasicShadowRenderer.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Creates a BasicShadowRenderer
 * @param manager the asset manager
 * @param size the size of the shadow map (the map is square)
 */
public BasicShadowRenderer(AssetManager manager, int size) {
    shadowFB = new FrameBuffer(size, size, 1);
    shadowMap = new Texture2D(size, size, Format.Depth);
    shadowFB.setDepthTexture(shadowMap);
    shadowCam = new Camera(size, size);
    
     //DO NOT COMMENT THIS (it prevent the OSX incomplete read buffer crash)
    dummyTex = new Texture2D(size, size, Format.RGBA8);        
    shadowFB.setColorTexture(dummyTex);
    shadowMapSize = size;
    preshadowMat = new Material(manager, "Common/MatDefs/Shadow/PreShadow.j3md");
    postshadowMat = new Material(manager, "Common/MatDefs/Shadow/BasicPostShadow.j3md");
    postshadowMat.setTexture("ShadowMap", shadowMap);

    dispPic.setTexture(manager, shadowMap, false);

    for (int i = 0; i < points.length; i++) {
        points[i] = new Vector3f();
    }
}
 
Example #11
Source File: AbstractShadowRenderer.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Sets the filtering mode for shadow edges. See {@link EdgeFilteringMode}
 * for more info.
 *
 * @param filterMode the desired filter mode (not null)
 */
final public void setEdgeFilteringMode(EdgeFilteringMode filterMode) {
    if (filterMode == null) {
        throw new NullPointerException();
    }

    this.edgeFilteringMode = filterMode;
    postshadowMat.setInt("FilterMode", filterMode.getMaterialParamValue());
    postshadowMat.setFloat("PCFEdge", edgesThickness);
    if (shadowCompareMode == CompareMode.Hardware) {
        for (Texture2D shadowMap : shadowMaps) {
            if (filterMode == EdgeFilteringMode.Bilinear) {
                shadowMap.setMagFilter(MagFilter.Bilinear);
                shadowMap.setMinFilter(MinFilter.BilinearNoMipMaps);
            } else {
                shadowMap.setMagFilter(MagFilter.Nearest);
                shadowMap.setMinFilter(MinFilter.NearestNoMipMaps);
            }
        }
    }
}
 
Example #12
Source File: PssmShadowRenderer.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Sets the filtering mode for shadow edges see {@link FilterMode} for more
 * info
 *
 * @param filterMode
 */
final public void setFilterMode(FilterMode filterMode) {
    if (filterMode == null) {
        throw new NullPointerException();
    }

    if (this.filterMode == filterMode) {
        return;
    }

    this.filterMode = filterMode;
    postshadowMat.setInt("FilterMode", filterMode.ordinal());
    postshadowMat.setFloat("PCFEdge", edgesThickness);
    if (compareMode == CompareMode.Hardware) {
        for (Texture2D shadowMap : shadowMaps) {
            if (filterMode == FilterMode.Bilinear) {
                shadowMap.setMagFilter(MagFilter.Bilinear);
                shadowMap.setMinFilter(MinFilter.BilinearNoMipMaps);
            } else {
                shadowMap.setMagFilter(MagFilter.Nearest);
                shadowMap.setMinFilter(MinFilter.NearestNoMipMaps);
            }
        }
    }
    applyFilterMode = true;
}
 
Example #13
Source File: Texture2dPropertyControl.java    From jmonkeybuilder with Apache License 2.0 6 votes vote down vote up
/**
 * Change a texture to the file.
 *
 * @param file the file of a new texture.
 */
@FxThread
protected void changeTexture(@Nullable Path file) {

    if (file == null) {
        changed(null, getPropertyValue());
    } else {

        var config = EditorConfig.getInstance();
        var assetFile = notNull(getAssetFile(file));
        var textureKey = new TextureKey(toAssetPath(assetFile));
        textureKey.setFlipY(config.getBoolean(PREF_FLIPPED_TEXTURES, PREF_DEFAULT_FLIPPED_TEXTURES));

        var texture = (Texture2D) EditorUtil.getAssetManager()
                .loadTexture(textureKey);
        texture.setWrap(Texture.WrapMode.Repeat);

        changed(texture, getPropertyValue());
    }
}
 
Example #14
Source File: AbstractShadowRendererVR.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Sets the shadow compare mode. See {@link CompareMode} for more info.
 *
 * @param compareMode the desired compare mode (not null)
 */
final public void setShadowCompareMode(CompareMode compareMode) {
    if (compareMode == null) {
        throw new IllegalArgumentException("Shadow compare mode cannot be null");
    }

    this.shadowCompareMode = compareMode;
    for (Texture2D shadowMap : shadowMaps) {
        if (compareMode == CompareMode.Hardware) {
            shadowMap.setShadowCompareMode(ShadowCompareMode.LessOrEqual);
            if (edgeFilteringMode == EdgeFilteringMode.Bilinear) {
                shadowMap.setMagFilter(MagFilter.Bilinear);
                shadowMap.setMinFilter(MinFilter.BilinearNoMipMaps);
            } else {
                shadowMap.setMagFilter(MagFilter.Nearest);
                shadowMap.setMinFilter(MinFilter.NearestNoMipMaps);
            }
        } else {
            shadowMap.setShadowCompareMode(ShadowCompareMode.Off);
            shadowMap.setMagFilter(MagFilter.Nearest);
            shadowMap.setMinFilter(MinFilter.NearestNoMipMaps);
        }
    }
    postshadowMat.setBoolean("HardwareShadows", compareMode == CompareMode.Hardware);
}
 
Example #15
Source File: WaterFilter.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * Sets the normal Texture
 * @param normalTexture
 */
public void setNormalTexture(Texture2D normalTexture) {
    this.normalTexture = normalTexture;
    normalTexture.setWrap(WrapMode.Repeat);
    if (material != null) {
        material.setTexture("NormalMap", normalTexture);
    }
}
 
Example #16
Source File: TerrainSplatTexture.java    From OpenRTS with MIT License 5 votes vote down vote up
public Material getMaterial() {
	if (atlas.isToUpdate()) {
		mat.setTexture("AlphaMap", new Texture2D(new Image(Image.Format.RGBA8, atlas.getWidth(), atlas.getHeight(), atlas.getBuffer(0))));
		mat.setTexture("AlphaMap_1", new Texture2D(new Image(Image.Format.RGBA8, atlas.getWidth(), atlas.getHeight(), atlas.getBuffer(1))));
		atlas.setToUpdate(false);
	}
	return mat;
}
 
Example #17
Source File: OpenVRViewManager.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void setupFinalFullTexture(Camera cam) {
	
	if (environment != null){
		if (environment.getApplication() != null){
	        // create offscreen framebuffer
	        FrameBuffer out = new FrameBuffer(cam.getWidth(), cam.getHeight(), 1);
	        //offBuffer.setSrgb(true);

	        //setup framebuffer's texture
	        dualEyeTex = new Texture2D(cam.getWidth(), cam.getHeight(), Image.Format.RGBA8);
	        dualEyeTex.setMinFilter(Texture.MinFilter.BilinearNoMipMaps);
	        dualEyeTex.setMagFilter(Texture.MagFilter.Bilinear);

	        logger.config("Dual eye texture "+dualEyeTex.getName()+" ("+dualEyeTex.getImage().getId()+")");
	        logger.config("               Type: "+dualEyeTex.getType());
	        logger.config("               Size: "+dualEyeTex.getImage().getWidth()+"x"+dualEyeTex.getImage().getHeight());
	        logger.config("        Image depth: "+dualEyeTex.getImage().getDepth());
	        logger.config("       Image format: "+dualEyeTex.getImage().getFormat());
	        logger.config("  Image color space: "+dualEyeTex.getImage().getColorSpace());
	        
	        //setup framebuffer to use texture
	        out.setDepthBuffer(Image.Format.Depth);
	        out.setColorTexture(dualEyeTex);       

	        ViewPort viewPort = environment.getApplication().getViewPort();
	        viewPort.setClearFlags(true, true, true);
	        viewPort.setBackgroundColor(ColorRGBA.Black);
	        viewPort.setOutputFrameBuffer(out);
		} else {
			throw new IllegalStateException("This VR environment is not attached to any application.");
		}
	} else {
        throw new IllegalStateException("This VR view manager is not attached to any VR environment.");
  	}  
}
 
Example #18
Source File: TestSoftwareMouse.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
    public void simpleInitApp() {
        flyCam.setEnabled(false);
//        inputManager.setCursorVisible(false);

        Texture tex = assetManager.loadTexture("Interface/Logo/Cursor.png");
        
        cursor = new Picture("cursor");
        cursor.setTexture(assetManager, (Texture2D) tex, true);
        cursor.setWidth(64);
        cursor.setHeight(64);
        guiNode.attachChild(cursor);

        inputManager.addRawInputListener(inputListener);

//        Image img = tex.getImage();
//        ByteBuffer data = img.getData(0);
//        IntBuffer image = BufferUtils.createIntBuffer(64 * 64);
//        for (int y = 0; y < 64; y++){
//            for (int x = 0; x < 64; x++){
//                int rgba = data.getInt();
//                image.put(rgba);
//            }
//        }
//        image.clear();
//
//        try {
//            Cursor cur = new Cursor(64, 64, 2, 62, 1, image, null);
//            Mouse.setNativeCursor(cur);
//        } catch (LWJGLException ex) {
//            Logger.getLogger(TestSoftwareMouse.class.getName()).log(Level.SEVERE, null, ex);
//        }
    }
 
Example #19
Source File: Picture.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * Set the texture to put on the picture.
 * 
 * @param assetManager The {@link AssetManager} to use to load the material.
 * @param tex The texture
 * @param useAlpha If true, the picture will appear transparent and allow
 * objects behind it to appear through. If false, the transparent
 * portions will be the image's color at that pixel.
 */
public void setTexture(AssetManager assetManager, Texture2D tex, boolean useAlpha){
    if (getMaterial() == null){
        Material mat = new Material(assetManager, "Common/MatDefs/Gui/Gui.j3md");
        mat.setColor("Color", ColorRGBA.White);
        setMaterial(mat);
    }
    material.getAdditionalRenderState().setBlendMode(useAlpha ? BlendMode.Alpha : BlendMode.Off);
    material.setTexture("Texture", tex);
}
 
Example #20
Source File: AbstractShadowRenderer.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void init(AssetManager assetManager, int nbShadowMaps, int shadowMapSize) {
    this.postshadowMat = new Material(assetManager, "Common/MatDefs/Shadow/PostShadow.j3md");
    shadowFB = new FrameBuffer[nbShadowMaps];
    shadowMaps = new Texture2D[nbShadowMaps];
    dispPic = new Picture[nbShadowMaps];
    lightViewProjectionsMatrices = new Matrix4f[nbShadowMaps];
    shadowMapStringCache = new String[nbShadowMaps];
    lightViewStringCache = new String[nbShadowMaps];

    //DO NOT COMMENT THIS (it prevent the OSX incomplete read buffer crash)
    dummyTex = new Texture2D(shadowMapSize, shadowMapSize, Format.RGBA8);

    preshadowMat = new Material(assetManager, "Common/MatDefs/Shadow/PreShadow.j3md");
    postshadowMat.setFloat("ShadowMapSize", shadowMapSize);

    for (int i = 0; i < nbShadowMaps; i++) {
        lightViewProjectionsMatrices[i] = new Matrix4f();
        shadowFB[i] = new FrameBuffer(shadowMapSize, shadowMapSize, 1);
        shadowMaps[i] = new Texture2D(shadowMapSize, shadowMapSize, Format.Depth);

        shadowFB[i].setDepthTexture(shadowMaps[i]);

        //DO NOT COMMENT THIS (it prevent the OSX incomplete read buffer crash)
        shadowFB[i].setColorTexture(dummyTex);
        shadowMapStringCache[i] = "ShadowMap" + i; 
        lightViewStringCache[i] = "LightViewProjectionMatrix" + i;

        postshadowMat.setTexture(shadowMapStringCache[i], shadowMaps[i]);

        //quads for debuging purpose
        dispPic[i] = new Picture("Picture" + i);
        dispPic[i].setTexture(assetManager, shadowMaps[i], false);
    }

    setShadowCompareMode(shadowCompareMode);
    setEdgeFilteringMode(edgeFilteringMode);
    setShadowIntensity(shadowIntensity);
    initForcedRenderState();
    setRenderBackFacesShadows(isRenderBackFacesShadows());
}
 
Example #21
Source File: FilterPostProcessor.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * init the given filter
 * @param filter
 * @param vp 
 */
private void initFilter(Filter filter, ViewPort vp) {
    filter.setProcessor(this);
    if (filter.isRequiresDepthTexture()) {
        if (!computeDepth && renderFrameBuffer != null) {
            depthTexture = new Texture2D(width, height, depthFormat);
            renderFrameBuffer.setDepthTexture(depthTexture);
        }
        computeDepth = true;
        filter.init(assetManager, renderManager, vp, width, height);
        filter.setDepthTexture(depthTexture);
    } else {
        filter.init(assetManager, renderManager, vp, width, height);
    }
}
 
Example #22
Source File: WaterFilter.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Sets the texture to use to render caustics on the ground underwater.
 *
 * @param causticsTexture the caustics texture.
 */
public void setCausticsTexture(Texture2D causticsTexture) {
    this.causticsTexture = causticsTexture;
    if (material != null) {
        material.setTexture("causticsMap", causticsTexture);
    }
}
 
Example #23
Source File: OSVRViewManager.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private ViewPort setupViewBuffers(Camera cam, String viewName){
	
	if (environment != null){
		if (environment.getApplication() != null){
	        // create offscreen framebuffer
	        FrameBuffer offBufferLeft = new FrameBuffer(cam.getWidth(), cam.getHeight(), 1);
	        //offBufferLeft.setSrgb(true);
	        
	        //setup framebuffer's texture
	        Texture2D offTex = new Texture2D(cam.getWidth(), cam.getHeight(), Image.Format.RGBA8);
	        offTex.setMinFilter(Texture.MinFilter.BilinearNoMipMaps);
	        offTex.setMagFilter(Texture.MagFilter.Bilinear);

	        //setup framebuffer to use texture
	        offBufferLeft.setDepthBuffer(Image.Format.Depth);
	        offBufferLeft.setColorTexture(offTex);        
	        
	        ViewPort viewPort = environment.getApplication().getRenderManager().createPreView(viewName, cam);
	        viewPort.setClearFlags(true, true, true);
	        viewPort.setBackgroundColor(ColorRGBA.Black);
	        
	        Iterator<Spatial> spatialIter = environment.getApplication().getViewPort().getScenes().iterator();
	        while(spatialIter.hasNext()){
	        	viewPort.attachScene(spatialIter.next());
	        }

	        //set viewport to render to offscreen framebuffer
	        viewPort.setOutputFrameBuffer(offBufferLeft);
	        return viewPort;
		} else {
			throw new IllegalStateException("This VR environment is not attached to any application.");
		}
	} else {
		throw new IllegalStateException("This VR view manager is not attached to any VR environment.");
	}  
}
 
Example #24
Source File: OSVRViewManager.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void setupFinalFullTexture(Camera cam) {
	
	if (environment != null){
		if (environment.getApplication() != null){
			// create offscreen framebuffer
	        FrameBuffer out = new FrameBuffer(cam.getWidth(), cam.getHeight(), 1);
	        //offBuffer.setSrgb(true);

	        //setup framebuffer's texture
	        dualEyeTex = new Texture2D(cam.getWidth(), cam.getHeight(), Image.Format.RGBA8);
	        dualEyeTex.setMinFilter(Texture.MinFilter.BilinearNoMipMaps);
	        dualEyeTex.setMagFilter(Texture.MagFilter.Bilinear);

	        logger.config("Dual eye texture "+dualEyeTex.getName()+" ("+dualEyeTex.getImage().getId()+")");
	        logger.config("               Type: "+dualEyeTex.getType());
	        logger.config("               Size: "+dualEyeTex.getImage().getWidth()+"x"+dualEyeTex.getImage().getHeight());
	        logger.config("        Image depth: "+dualEyeTex.getImage().getDepth());
	        logger.config("       Image format: "+dualEyeTex.getImage().getFormat());
	        logger.config("  Image color space: "+dualEyeTex.getImage().getColorSpace());
	        
	        //setup framebuffer to use texture
	        out.setDepthBuffer(Image.Format.Depth);
	        out.setColorTexture(dualEyeTex);       

	        ViewPort viewPort = environment.getApplication().getViewPort();
	        viewPort.setClearFlags(true, true, true);
	        viewPort.setBackgroundColor(ColorRGBA.Black);
	        viewPort.setOutputFrameBuffer(out);
		} else {
			throw new IllegalStateException("This VR environment is not attached to any application.");
		}
	} else {
		throw new IllegalStateException("This VR view manager is not attached to any VR environment.");
	}  
}
 
Example #25
Source File: OSVRViewManager.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private ViewPort setupMirrorBuffers(Camera cam, Texture tex, boolean expand) {     
	
	if (environment != null){
		if (environment.getApplication() != null){
			Camera clonecam = cam.clone();
	        ViewPort viewPort = environment.getApplication().getRenderManager().createPostView("MirrorView", clonecam);
	        clonecam.setParallelProjection(true);
	        viewPort.setClearFlags(true, true, true);
	        viewPort.setBackgroundColor(ColorRGBA.Black);
	        Picture pic = new Picture("fullscene");
	        pic.setLocalTranslation(-0.75f, -0.5f, 0f);
	        if( expand ) {
	            pic.setLocalScale(3f, 1f, 1f);
	        } else {
	            pic.setLocalScale(1.5f, 1f, 1f);            
	        }
	        pic.setQueueBucket(Bucket.Opaque);
	        pic.setTexture(environment.getApplication().getAssetManager(), (Texture2D)tex, false);
	        viewPort.attachScene(pic);
	        viewPort.setOutputFrameBuffer(null);
	        
	        pic.updateGeometricState();
	        
	        return viewPort;
		} else {
			throw new IllegalStateException("This VR environment is not attached to any application.");
		}
	} else {
		throw new IllegalStateException("This VR view manager is not attached to any VR environment.");
	}  
}
 
Example #26
Source File: OpenVRViewManager.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private ViewPort setupViewBuffers(Camera cam, String viewName){
	
	if (environment != null){
		if (environment.getApplication() != null){
			// create offscreen framebuffer
	        FrameBuffer offBufferLeft = new FrameBuffer(cam.getWidth(), cam.getHeight(), 1);
	        //offBufferLeft.setSrgb(true);
	        
	        //setup framebuffer's texture
	        Texture2D offTex = new Texture2D(cam.getWidth(), cam.getHeight(), Image.Format.RGBA8);
	        offTex.setMinFilter(Texture.MinFilter.BilinearNoMipMaps);
	        offTex.setMagFilter(Texture.MagFilter.Bilinear);

	        //setup framebuffer to use texture
	        offBufferLeft.setDepthBuffer(Image.Format.Depth);
	        offBufferLeft.setColorTexture(offTex);        
	        
	        ViewPort viewPort = environment.getApplication().getRenderManager().createPreView(viewName, cam);
	        viewPort.setClearFlags(true, true, true);
	        viewPort.setBackgroundColor(ColorRGBA.Black);
	        
	        Iterator<Spatial> spatialIter = environment.getApplication().getViewPort().getScenes().iterator();
	        while(spatialIter.hasNext()){
	        	viewPort.attachScene(spatialIter.next());
	        }

	        //set viewport to render to offscreen framebuffer
	        viewPort.setOutputFrameBuffer(offBufferLeft);
	        return viewPort;
		} else {
			throw new IllegalStateException("This VR environment is not attached to any application.");
		}
	} else {
        throw new IllegalStateException("This VR view manager is not attached to any VR environment.");
  	}  
}
 
Example #27
Source File: WaterFilter.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * Sets the height texture
 * @param heightTexture
 */
public void setHeightTexture(Texture2D heightTexture) {
    this.heightTexture = heightTexture;
    heightTexture.setWrap(WrapMode.Repeat);
    if (material != null) {
        material.setTexture("HeightMap", heightTexture);
    }
}
 
Example #28
Source File: LWJGLOpenVRViewManager.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private ViewPort setupViewBuffers(Camera cam, String viewName) {

        if (environment != null) {
            if (environment.getApplication() != null) {
                // create offscreen framebuffer
                FrameBuffer offBufferLeft = new FrameBuffer(cam.getWidth(), cam.getHeight(), 1);
                //offBufferLeft.setSrgb(true);

                //setup framebuffer's texture
                Texture2D offTex = new Texture2D(cam.getWidth(), cam.getHeight(), Image.Format.RGBA8);
                offTex.setMinFilter(Texture2D.MinFilter.BilinearNoMipMaps);
                offTex.setMagFilter(Texture2D.MagFilter.Bilinear);

                //setup framebuffer to use texture
                offBufferLeft.setDepthBuffer(Image.Format.Depth);
                offBufferLeft.setColorTexture(offTex);

                ViewPort viewPort = environment.getApplication().getRenderManager().createPreView(viewName, cam);
                viewPort.setClearFlags(true, true, true);
                viewPort.setBackgroundColor(ColorRGBA.Black);

                Iterator<Spatial> spatialIter = environment.getApplication().getViewPort().getScenes().iterator();
                while (spatialIter.hasNext()) {
                    viewPort.attachScene(spatialIter.next());
                }

                //set viewport to render to offscreen framebuffer
                viewPort.setOutputFrameBuffer(offBufferLeft);
                return viewPort;
            } else {
                throw new IllegalStateException("This VR environment is not attached to any application.");
            }
        } else {
            throw new IllegalStateException("This VR view manager is not attached to any VR environment.");
        }
    }
 
Example #29
Source File: Texture2dSingleRowPropertyControl.java    From jmonkeybuilder with Apache License 2.0 5 votes vote down vote up
public Texture2dSingleRowPropertyControl(
        @Nullable Texture2D propertyValue,
        @NotNull String propertyName,
        @NotNull C changeConsumer
) {
    super(propertyValue, propertyName, changeConsumer);
}
 
Example #30
Source File: MaterialMatParamTest.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
public void testTextureOverride() {
    material("Common/MatDefs/Light/Lighting.j3md");
    Texture2D tex1 = new Texture2D(128, 128, Format.RGBA8);
    Texture2D tex2 = new Texture2D(128, 128, Format.RGBA8);

    inputMp(mpoTexture2D("DiffuseMap", tex1));
    inputMpo(mpoTexture2D("DiffuseMap", tex2));

    outDefines(def("DIFFUSEMAP", VarType.Texture2D, tex2));
    outUniforms(uniform("DiffuseMap", VarType.Int, 0));
    outTextures(tex2);
}