Projected texture question

Hi everyone.

I posted a question about projected texture two month ago.

But I found out that I posted wrong category… sorry for my misstake and I have faced this problem yet.

My goal is ( It is jme2 sample) work on jme3.

And, screenshot is this.

But I have 2 problem about it.

First, how transform texutre to projected texture. I don’t know how to apply ( It’s jme2 ) to jme3.

Second, how map projected texture on spatials that have texture already. In other words, is it can map projected texture on spatial have SimpleTextured.

If anyone know solution, please help me.

Thank you.

Please does anyone know a solution to this?

Yes, in jME3 you do this with a shader, not with java code.

1 Like

You’ll have to make your own RenderPorcessor that will compute the projection matrix for the texture, and in the postFrame method render again the “receiver” objects with a forced material.

This material will use a shader, which will be provided with the projection matrix you computed before

You should look at the BasicShadowProcessor and the associated shader (postShadow.vert and .frag), because that’s how shadow maps are projected to the scene.

1 Like

Thanks normen and nehon for the reply !

I got some questions about

  1. In the postQueue method, compute shadow camera position, frustumpoints and view projection matrix, right?
  2. In the postFrame method, render with a forced material. But, last pass null to setForcedMaterial method. What is it mean ?
  1. Yes but, for shadow mapping we use a parallel projection cam, and we crop the matrix around the caster/receiver objects in the post queue, but you don’t need this. you just need to create a camera that will “project” your texture, set the correct position in post queue, and grab its viewProjectionMatrix.

  2. Yes render with forced material, the setForcedMaterial(nul) just removes the forced material from the RenderManager so geometries’ materials are used for render.
1 Like

Thanks nehon. I’ve tried it, but faced a problem.

Now, I wrote it is extended SimpleApplication),, ProjectionTexture.j3md, ProjectionTexture.vert and ProjectionTexture.frag. is a copy of and has ProjectionTextureProcessor. It’s code is this.


package projectionTextureTest;

import com.jme3.asset.AssetManager;

import com.jme3.material.Material;

import com.jme3.math.Vector3f;


import com.jme3.renderer.Camera;

import com.jme3.renderer.RenderManager;

import com.jme3.renderer.ViewPort;

import com.jme3.renderer.queue.RenderQueue;

import com.jme3.renderer.queue.RenderQueue.Bucket;

import com.jme3.texture.FrameBuffer;

import com.jme3.texture.Texture;

import com.jme3.texture.Texture.MagFilter;

import com.jme3.texture.Texture.MinFilter;

import com.jme3.texture.Texture.WrapMode;

public class ProjectionTextureProcessor implements SceneProcessor {

private RenderManager renderManager;

private ViewPort viewPort;

private Camera camera;

private Material material;

private Texture texture;

public ProjectionTextureProcessor(String file, AssetManager manager, int width, int height) {

camera = new Camera(width, height);

camera.setFrustumPerspective(30f, 1.5f, 1.0f, 1000.0f);

camera.lookAt(Vector3f.ZERO, Vector3f.UNIT_Y);

material = new Material(manager, “projectionTextureTest/ProjectionTexture.j3md”);

texture = manager.loadTexture(file);




material.setTexture(“m_ColorMap”, texture);


public Camera getCamera() {

return camera;


public void initialize(RenderManager rm, ViewPort vp) {

renderManager = rm;

viewPort = vp;

reshape(vp, vp.getCamera().getWidth(), vp.getCamera().getHeight());


public void reshape(ViewPort vp, int w, int h) {


public boolean isInitialized() {

return viewPort != null;


public void preFrame(float tpf) {


public void postQueue(RenderQueue rq) {

camera.setLocation(new Vector3f(10, 10, 10));





public void postFrame(FrameBuffer out) {

material.setMatrix4(“m_LightViewProjectionMatrix”, camera.getViewProjectionMatrix());


viewPort.getQueue().renderQueue(Bucket.Opaque, renderManager, viewPort.getCamera());



public void cleanup() {




Run this application, display it.

It is not changed without ProjectionTextureProcessor. Then, I comment out “renderManager.setForcedMaterial(null);” and run, output is changed.

I think projection texture is worked, but others filled black…

What mistake did I make ? Could you give me a advice ? writing my codes are here

thank you.

I think the issue is that you need to add RenderState blendMode modulate in your material file like it’s don,e in the PostShadow.j3md

ummmm… I added RenderState blendMode modulate. Then with “renderManager.setForcedMaterial(null)” code is not changed before and comment out it, display filled black only. nothing is drawn…

Now, I implemented projected texture. I copied Lighting.j3m, Lighting.frag and Lighting.vert and added some codes for projected texture into these.

But, I think this way is not pluggable. If Lighting shader file is updated, I need to update my copied shader files.

Do anyone has idea to solve this problem ?