Apply one shader in "viewport"

How can i do to apply one shader on the view?



i see the SketchRenderPass but i can do it :S



i have one Quad with cam (render to texture) but i need this Quad “ortho” on my screen (not like a plane in 3d)



i have this result:







any idea?

quad.setRenderQueueMode(Renderer.QUEUE_ORTHO);

quad.updateGeometricState(0.0f, true);

dhdd said:

quad.setRenderQueueMode(Renderer.QUEUE_ORTHO);
quad.updateGeometricState(0.0f, true);


I have that:

fullScreenQuad = new Quad("FullScreenQuad", display.getWidth(), display.getHeight());
fullScreenQuad.getLocalRotation().set(0, 0, 0, 1);
fullScreenQuad.getLocalTranslation().set(display.getWidth() / 2, display.getHeight() / 2, 0);
fullScreenQuad.getLocalScale().set(1, 1, 1);
fullScreenQuad.setRenderQueueMode(Renderer.QUEUE_ORTHO);

fullScreenQuad.setCullHint(Spatial.CullHint.Never);
fullScreenQuad.setTextureCombineMode(TextureCombineMode.Replace);
fullScreenQuad.setLightCombineMode(Spatial.LightCombineMode.Off);

fullScreenQuad.updateRenderState();
fullScreenQuad.updateGeometricState(0.0f, true);

but don't work, any idea?

Maybe post a test case of what you are trying to do…

basixs said:

Maybe post a test case of what you are trying to do...


Ok, i'm trying to use SSAO shader in one view (main view), the shader:

Vert:
varying vec2 texCoord;

void main(void) {
gl_Position = ftransform();
texCoord=gl_MultiTexCoord0.xy;
gl_FrontColor = gl_Color;
}


Frag:
uniform sampler2D texture0; // depth texture
uniform sampler2D texture1; // rendered scene color texture

uniform vec2 camerarange;
uniform vec2 screensize;

varying vec2 texCoord;


float readDepth( in vec2 coord ) {
return (2.0 * camerarange.x) / (camerarange.y + camerarange.x - texture2D( texture0, coord ).x * (camerarange.y - camerarange.x));
}


void main(void)
{
float depth = readDepth( texCoord );
float d;

float pw = 1.0 / screensize.x;
float ph = 1.0 / screensize.y;

float aoCap = 1.0;

float ao = 0.0;

float aoMultiplier=1000.0;

float depthTolerance = 0.0001;

d=readDepth( vec2(texCoord.x+pw,texCoord.y+ph));
ao+=min(aoCap,max(0.0,depth-d-depthTolerance) * aoMultiplier);

d=readDepth( vec2(texCoord.x-pw,texCoord.y+ph));
ao+=min(aoCap,max(0.0,depth-d-depthTolerance) * aoMultiplier);

d=readDepth( vec2(texCoord.x+pw,texCoord.y-ph));
ao+=min(aoCap,max(0.0,depth-d-depthTolerance) * aoMultiplier);

d=readDepth( vec2(texCoord.x-pw,texCoord.y-ph));
ao+=min(aoCap,max(0.0,depth-d-depthTolerance) * aoMultiplier);

pw*=2.0;
ph*=2.0;
aoMultiplier/=2.0;

d=readDepth( vec2(texCoord.x+pw,texCoord.y+ph));
ao+=min(aoCap,max(0.0,depth-d-depthTolerance) * aoMultiplier);

d=readDepth( vec2(texCoord.x-pw,texCoord.y+ph));
ao+=min(aoCap,max(0.0,depth-d-depthTolerance) * aoMultiplier);

d=readDepth( vec2(texCoord.x+pw,texCoord.y-ph));
ao+=min(aoCap,max(0.0,depth-d-depthTolerance) * aoMultiplier);

d=readDepth( vec2(texCoord.x-pw,texCoord.y-ph));
ao+=min(aoCap,max(0.0,depth-d-depthTolerance) * aoMultiplier);

pw*=2.0;
ph*=2.0;
aoMultiplier/=2.0;

d=readDepth( vec2(texCoord.x+pw,texCoord.y+ph));
ao+=min(aoCap,max(0.0,depth-d-depthTolerance) * aoMultiplier);

d=readDepth( vec2(texCoord.x-pw,texCoord.y+ph));
ao+=min(aoCap,max(0.0,depth-d-depthTolerance) * aoMultiplier);

d=readDepth( vec2(texCoord.x+pw,texCoord.y-ph));
ao+=min(aoCap,max(0.0,depth-d-depthTolerance) * aoMultiplier);

d=readDepth( vec2(texCoord.x-pw,texCoord.y-ph));
ao+=min(aoCap,max(0.0,depth-d-depthTolerance) * aoMultiplier);

pw*=2.0;
ph*=2.0;
aoMultiplier/=2.0;

d=readDepth( vec2(texCoord.x+pw,texCoord.y+ph));
ao+=min(aoCap,max(0.0,depth-d-depthTolerance) * aoMultiplier);

d=readDepth( vec2(texCoord.x-pw,texCoord.y+ph));
ao+=min(aoCap,max(0.0,depth-d-depthTolerance) * aoMultiplier);

d=readDepth( vec2(texCoord.x+pw,texCoord.y-ph));
ao+=min(aoCap,max(0.0,depth-d-depthTolerance) * aoMultiplier);

d=readDepth( vec2(texCoord.x-pw,texCoord.y-ph));
ao+=min(aoCap,max(0.0,depth-d-depthTolerance) * aoMultiplier);

ao/=16.0;

gl_FragColor = vec4(1.0-ao) * texture2D(texture1,texCoord);
}


Java Class (Pass representation):
public class SSAORenderPass extends Pass
{
    private static final long serialVersionUID = 1L;
   
    private TextureRenderer tRendererDepth;
    private Texture2D textureDepth;

    private Quad fullScreenQuad;
   
    protected RenderState[] preStates = new RenderState[RenderState.RS_MAX_STATE];

    private GLSLShaderObjectsState ssaoShader;
// private GLSLShaderObjectsState normShader;
   
    protected static TextureState noTexture;
protected static LightState noLights;
protected static MaterialState noMaterials;
   
    Vector2f screenSize = new Vector2f ( 1024, 768 );
    Vector2f cameraRange = new Vector2f ( 2, 3 );
   
    private boolean supported = true;
   
    public void resetParameters() {
screenSize = new Vector2f ( 1024, 768 );
cameraRange = new Vector2f ( 2, 3 );
}
   
    public void cleanup() {
tRendererDepth.cleanup();
}
   
    public boolean isSupported() {
return supported;
}
   
    public SSAORenderPass(Camera cam, int renderScale )
    {
        if(!GLSLShaderObjectsState.isSupported()) {
            supported = false;
            return;
        }
       
        DisplaySystem display = DisplaySystem.getDisplaySystem();

resetParameters();
               
        tRendererDepth = display.createTextureRenderer(
                            display.getWidth() / renderScale,
                            display.getHeight() / renderScale,
                            TextureRenderer.Target.Texture2D);
tRendererDepth.setBackgroundColor(new ColorRGBA(0.0f, 0.0f, 0.0f, 1.0f));
tRendererDepth.setCamera(cam);

textureDepth = new Texture2D();
        textureDepth.setWrap(Texture.WrapMode.Clamp);
textureDepth.setMagnificationFilter(Texture.MagnificationFilter.Bilinear);
tRendererDepth.setupTexture(textureDepth);
               
        ssaoShader = display.getRenderer().createGLSLShaderObjectsState();
ssaoShader.load(SSAORenderPass.class.getClassLoader().getResource("Media/Shaders/ssao.vert"),
SSAORenderPass.class.getClassLoader().getResource("Media/Shaders/ssao.frag"));
ssaoShader.setEnabled(true);
ssaoShader.setUniform("camerarange", new Vector2f ( cam.getFrustumNear(), cam.getFrustumFar() ) );
ssaoShader.setUniform("screensize", screenSize );
               
        fullScreenQuad = new Quad("FullScreenQuad", display.getWidth(), display.getHeight());
fullScreenQuad.getLocalRotation().set(0, 0, 0, 1);
fullScreenQuad.getLocalTranslation().set(display.getWidth() / 2, display.getHeight() / 2, 0);
fullScreenQuad.getLocalScale().set(1, 1, 1);
fullScreenQuad.setRenderQueueMode(Renderer.QUEUE_ORTHO);

fullScreenQuad.setCullHint(Spatial.CullHint.Never);
fullScreenQuad.setTextureCombineMode(TextureCombineMode.Replace);
fullScreenQuad.setLightCombineMode(Spatial.LightCombineMode.Off);

TextureState ts = display.getRenderer().createTextureState();
ts.setEnabled(true);
fullScreenQuad.setRenderState(ts);

fullScreenQuad.updateRenderState();
fullScreenQuad.updateGeometricState(0.0f, true);
               
                noTexture = display.getRenderer().createTextureState();
noTexture.setEnabled(false);
noLights = display.getRenderer().createLightState();
noLights.setEnabled(false);
noMaterials = display.getRenderer().createMaterialState();
noMaterials.setEnabled(false);
    }
   
    public void doRender(Renderer r) {
if(!isSupported() ||spatials.size() != 1) return;
               
                saveEnforcedStates();
tRendererDepth.render(spatials.get(0), textureDepth);

TextureState ts = (TextureState) fullScreenQuad.getRenderState(RenderState.RS_TEXTURE);
               
                ssaoShader.clearUniforms();
                ssaoShader.setUniform("camerarange", new Vector2f ( 1, 10f ) );
ssaoShader.setUniform("screensize", screenSize );
                ts.setTexture(textureDepth, 0);
fullScreenQuad.setRenderState(ssaoShader);
fullScreenQuad.updateRenderState();
                replaceEnforcedStates();
r.draw(fullScreenQuad);
    }
   
    protected void saveEnforcedStates() {
for(int x = RenderState.RS_MAX_STATE; --x >= 0;) {
preStates[x] = context.enforcedStateList[x];
}
}

/**
* replaces any states enforced by the user at the end of the pass.
*/
protected void replaceEnforcedStates() {
for(int x = RenderState.RS_MAX_STATE; --x >= 0;) {
            context.enforcedStateList[x] = preStates[x];
}
}
}

and the main.java
SSAORenderPass bloomRenderPass = new SSAORenderPass(cam, 1);

        if(!bloomRenderPass.isSupported()) {
            Text t = Text.createDefaultTextLabel("Text", "GLSL Not supported on this computer.");
            t.setRenderQueueMode(Renderer.QUEUE_ORTHO);
            t.setLightCombineMode(LightCombineMode.Off);
            t.setLocalTranslation(new Vector3f(0,20,0));
            statNode.attachChild(t);
        } else {
            bloomRenderPass.add(rootNode);
            pManager.add(bloomRenderPass);
        }
             
       
        RenderPass statPass = new RenderPass();
statPass.add(statNode);
pManager.add(statPass);

alright, that it's all.  I'm trying to apply SSAO shader on the view, all work fine but i have one "Render to texture" and i want render on main view (camera plane).

Where it's the problem? help me please

note: sorry for my english, i'm colombian :D (speak spanish)

help me please, how can i do that?

i can't help with shader questions, but pleas wrap your code with [ code ] [ /code ] tags.

That way others can much easier read your code.

Hmm, how hard would it be to wipe up a mockup (picture) of what you are trying to do?

alright, i want that:







or that:







ok,



i have one shader (from opengl site) of SSAO, it’s work but i need apply it in my camera (view) and i don’t know how do it, so … how can i do to apply my shader (SSAO) in may view?



i see bloomShader and Skeptcha but when i try, i have this result:







any idea? please help me :smiley:

If I'm correct ( new to  shaders …),



you need to update correctly your planes (near,far) from camera

your rendering quad size must be the size of your screen, it's already ortho



And about your shader, I'm not sure but:


uniform sampler2D texture0; // depth texture
uniform sampler2D texture1; // rendered scene color texture


means you use two texture in this shader no ?
If so you have to use one shader to create a depht texture with a texture renderer.
Render the object normally into another texture.
use the two textures in a same textureState, apply to the quad, and render the quad with the shader you proposed.

Hope this helps a bit anyway :)

why reinvent the weel?  :wink:



http://www.jmonkeyengine.com/jmeforum/index.php?topic=8446.0

http://www.jmonkeyengine.com/jmeforum/index.php?topic=9073.0

LOL, good memory dhdd; I forgot ALL about those posts