if( useRefraction ) { textureRefract = new Texture(); textureRefract.setWrap( Texture.WM_ECLAMP_S_ECLAMP_T ); textureRefract.setFilter( Texture.FM_LINEAR ); tRenderer.setupTexture( textureRefract );
textureReflect = new Texture(); textureReflect.setWrap( Texture.WM_ECLAMP_S_ECLAMP_T ); textureReflect.setFilter( Texture.FM_LINEAR ); textureReflect.setScale( new Vector3f( -1.0f, 1.0f, 1.0f ) ); textureReflect.setTranslation( new Vector3f( 1.0f, 0.0f, 0.0f ) ); tRenderer.setupTexture( textureReflect );
	public WaterRenderPass( Camera cam, int renderScale, boolean useProjectedShader, boolean useRefraction ) {		this.cam = cam;		this.useProjectedShader = useProjectedShader;		this.useRefraction = useRefraction;		if( useRefraction && useProjectedShader && TextureState.getNumberOfFragmentUnits() < 6 ||			useRefraction && TextureState.getNumberOfFragmentUnits() < 5 ) {			useRefraction = false;			LoggingSystem.getLogger().log( Level.INFO, "Not enough textureunits, falling back to non refraction water" );		}		resetParameters();		DisplaySystem display = DisplaySystem.getDisplaySystem();		waterShader = display.getRenderer().createGLSLShaderObjectsState();		if( !waterShader.isSupported() ) {			supported = false;		}		else {			if( useProjectedShader ) {				if( useRefraction ) {					currentShaderStr = projectedShaderRefractionStr;				}				else {					currentShaderStr = projectedShaderStr;				}			}			else {				if( useRefraction ) {					currentShaderStr = simpleShaderRefractionStr;				}				else {					currentShaderStr = simpleShaderStr;				}			}			waterShader.load( WaterRenderPass.class.getClassLoader().getResource( currentShaderStr + ".vert" ),							  WaterRenderPass.class.getClassLoader().getResource( currentShaderStr + ".frag" ) );			waterShader.setEnabled( true );		}		cullBackFace = display.getRenderer().createCullState();		cullBackFace.setEnabled( true );		cullBackFace.setCullMode( CullState.CS_NONE );		clipState = display.getRenderer().createClipState();		if( isSupported() ) {			tRenderer = display.createTextureRenderer(					display.getWidth() / renderScale, display.getHeight() / renderScale, false, true, false, false,					TextureRenderer.RENDER_TEXTURE_2D, 0 );			tRenderer.setBackgroundColor( new ColorRGBA( 0.0f, 0.0f, 0.0f, 1.0f ) );			tRenderer.getCamera().setFrustum( cam.getFrustumNear(), cam.getFrustumFar(), cam.getFrustumLeft(), cam.getFrustumRight(), cam.getFrustumTop(), cam.getFrustumBottom() );			tRenderer.forceCopy( true );			textureReflect = new Texture();			textureReflect.setWrap( Texture.WM_ECLAMP_S_ECLAMP_T );			textureReflect.setFilter( Texture.FM_LINEAR );			textureReflect.setScale( new Vector3f( -1.0f, 1.0f, 1.0f ) );			textureReflect.setTranslation( new Vector3f( 1.0f, 0.0f, 0.0f ) );			tRenderer.setupTexture( textureReflect );			if( useRefraction ) {				textureRefract = new Texture();				textureRefract.setWrap( Texture.WM_ECLAMP_S_ECLAMP_T );				textureRefract.setFilter( Texture.FM_LINEAR );				tRenderer.setupTexture( textureRefract );				textureDepth = new Texture();				textureDepth.setWrap( Texture.WM_ECLAMP_S_ECLAMP_T );				textureDepth.setFilter( Texture.FM_NEAREST );				textureDepth.setRTTSource( Texture.RTT_SOURCE_DEPTH );				tRenderer.setupTexture( textureDepth );			}			ts = display.getRenderer().createTextureState();			ts.setEnabled( true );			Texture t1 = TextureManager.loadTexture(					WaterRenderPass.class.getClassLoader().getResource( "com/jmex/effects/water/data/normalmap3.dds" ),					Texture.MM_LINEAR_LINEAR,					Texture.FM_LINEAR			);			ts.setTexture( t1, 0 );			t1.setWrap( Texture.WM_WRAP_S_WRAP_T );			ts.setTexture( textureReflect, 1 );			t1 = TextureManager.loadTexture(					WaterRenderPass.class.getClassLoader().getResource( "com/jmex/effects/water/data/dudvmap.png" ),					Texture.MM_LINEAR_LINEAR,					Texture.FM_LINEAR, com.jme.image.Image.GUESS_FORMAT_NO_S3TC, 1.0f, false			);			ts.setTexture( t1, 2 );			t1.setWrap( Texture.WM_WRAP_S_WRAP_T );			if( useRefraction ) {				ts.setTexture( textureRefract, 3 );				ts.setTexture( textureDepth, 4 );			}			if( useProjectedShader ) {				t1 = TextureManager.loadTexture(						WaterRenderPass.class.getClassLoader().getResource( "com/jmex/effects/water/data/oceanfoam.png" ),						Texture.MM_LINEAR_LINEAR,						Texture.FM_LINEAR );				if( useRefraction ) {					ts.setTexture( t1, 5 );				}				else {					ts.setTexture( t1, 3 );				}				t1.setWrap( Texture.WM_WRAP_S_WRAP_T );			}			clipState.setEnabled( true );			clipState.setEnableClipPlane( ClipState.CLIP_PLANE0, true );		}		else {			ts = display.getRenderer().createTextureState();			ts.setEnabled( true );			Texture t1 = TextureManager.loadTexture(					WaterRenderPass.class.getClassLoader().getResource( "com/jmex/effects/water/data/water2.png" ),					Texture.MM_LINEAR_LINEAR,					Texture.FM_LINEAR );			ts.setTexture( t1, 0 );			t1.setWrap( Texture.WM_WRAP_S_WRAP_T );			as1 = display.getRenderer().createAlphaState();			as1.setBlendEnabled( true );			as1.setSrcFunction( AlphaState.SB_SRC_ALPHA );			as1.setDstFunction( AlphaState.DB_ONE_MINUS_SRC_ALPHA );			as1.setEnabled( true );		}	}