com.badlogic.gdx.graphics.g3d.utils.ShaderProvider Java Examples

The following examples show how to use com.badlogic.gdx.graphics.g3d.utils.ShaderProvider. 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: SimpleRoom.java    From gdx-vr with Apache License 2.0 6 votes vote down vote up
@Override
public void create() {
	assets = new AssetManager();
	String model = "Bambo_House.g3db";
	assets.load(model, Model.class);
	assets.finishLoading();
	modelInstance = new ModelInstance(assets.get(model, Model.class), new Matrix4().setToScaling(0.6f, 0.6f, 0.6f));

	DefaultShader.Config config = new Config();
	config.defaultCullFace = GL20.GL_NONE;
	ShaderProvider shaderProvider = new DefaultShaderProvider(config);
	modelBatch = new ModelBatch(shaderProvider);

	ModelBuilder builder = new ModelBuilder();
	float groundSize = 1000f;
	ground = new ModelInstance(builder.createRect(-groundSize, 0, groundSize, groundSize, 0, groundSize, groundSize, 0, -groundSize, -groundSize, 0, -groundSize, 0,
			1, 0, new Material(), Usage.Position | Usage.Normal), new Matrix4().setToTranslation(0, -0.01f, 0));
	environment = new Environment();
	environment.set(new ColorAttribute(ColorAttribute.AmbientLight, 0.4f, 0.4f, 0.4f, 1f));
	environment.add(new DirectionalLight().set(0.8f, 0.8f, 0.8f, -1f, -0.8f, -0.2f));

	VirtualReality.renderer.listeners.add(this);
	// VirtualReality.head.setCyclops(true);
}
 
Example #2
Source File: SceneManager.java    From gdx-gltf with Apache License 2.0 5 votes vote down vote up
public SceneManager(ShaderProvider shaderProvider, DepthShaderProvider depthShaderProvider, RenderableSorter renderableSorter)
{
	this.renderableSorter = renderableSorter;
	
	batch = new ModelBatch(shaderProvider, renderableSorter);
	
	depthBatch = new ModelBatch(depthShaderProvider);
	
	float lum = 1f;
	environment.set(new ColorAttribute(ColorAttribute.AmbientLight, lum, lum, lum, 1));
}
 
Example #3
Source File: GLTFDemo.java    From gdx-gltf with Apache License 2.0 4 votes vote down vote up
@Override
public void render() {
	float delta = Gdx.graphics.getDeltaTime();
	stage.act();
	
	// recreate shaders if needed
	validateShaders();

	sceneManager.update(delta);
	
	if(cameraControl != null){
		cameraControl.update();
	}
	
	Gdx.gl.glClearColor(ui.fogColor.value.r, ui.fogColor.value.g, ui.fogColor.value.b, 0f);
	Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT | GL20.GL_DEPTH_BUFFER_BIT);
	
	sceneManager.setAmbientLight(ui.ambiantSlider.getValue());
	
	ColorAttribute fog = sceneManager.environment.get(ColorAttribute.class, ColorAttribute.Fog);
	if(fog != null) fog.color.set(ui.fogColor.value);
	
	FogAttribute fogEquation = sceneManager.environment.get(FogAttribute.class, FogAttribute.FogEquation);
	if(fogEquation != null){
		fogEquation.value.set(
				MathUtils.lerp(sceneManager.camera.near, sceneManager.camera.far, (ui.fogEquation.value.x + 1f) / 2f),
				MathUtils.lerp(sceneManager.camera.near, sceneManager.camera.far, (ui.fogEquation.value.y + 1f) / 2f),
				10f * (ui.fogEquation.value.z + 1f) / 2f
				);
	}
	
	skybox.getColor().set(ui.skyBoxColor.value);
	
	DirectionalLight light = sceneManager.getFirstDirectionalLight();
	if(light != null){
		float lum = ui.lightSlider.getValue();
		if(light instanceof DirectionalLightEx){
			DirectionalLightEx lightEx = (DirectionalLightEx)light;
			lightEx.intensity = lum;
			lightEx.updateColor();
		}
		light.direction.set(ui.lightDirectionControl.value).nor();
		
		PBRFloatAttribute shadowBias = sceneManager.environment.get(PBRFloatAttribute.class, PBRFloatAttribute.ShadowBias);
		shadowBias.value = ui.shadowBias.getValue() / 50f;
	}

	sceneManager.render();

	if(ui.outlinesEnabled.isOn()){
		captureDepth();

		outlineShader.begin();
		float size = 1 - ui.outlinesWidth.getValue();
		
		// float depthMin = ui.outlineDepthMin.getValue() * .001f;
		float depthMin = (float)Math.pow(ui.outlineDepthMin.getValue(), 10); // 0.35f
		float depthMax = (float)Math.pow(ui.outlineDepthMax.getValue(), 10); // 0.9f
		
		// TODO use an integer instead and divide w and h
		outlineShader.setUniformf("u_size", Gdx.graphics.getWidth() * size, Gdx.graphics.getHeight() * size);
		outlineShader.setUniformf("u_depth_min", depthMin);
		outlineShader.setUniformf("u_depth_max", depthMax);
		outlineShader.setUniformf("u_inner_color", ui.outlineInnerColor.getValue());
		outlineShader.setUniformf("u_outer_color", ui.outlineOuterColor.getValue());
		
		if(ui.outlineDistFalloffOption.isOn()){
			
			float distanceFalloff = ui.outlineDistFalloff.getValue();
			if(distanceFalloff <= 0){
				distanceFalloff = .001f;
			}
			outlineShader.setUniformf("u_depthRange", sceneManager.camera.far / (sceneManager.camera.near * distanceFalloff));
		}
		
		spriteBatch.enableBlending();
		spriteBatch.getProjectionMatrix().setToOrtho2D(0, 0, 1, 1);
		spriteBatch.setShader(outlineShader);
		spriteBatch.begin();
		spriteBatch.draw(depthFbo.getColorBufferTexture(), 0, 0, 1, 1, 0f, 0f, 1f, 1f);
		spriteBatch.end();
		spriteBatch.setShader(null);
	}
	
	renderOverlays();
	
	int shaderCount = 0;
	ShaderProvider shaderProvider = sceneManager.getBatch().getShaderProvider();
	if(shaderProvider instanceof PBRShaderProvider){
		shaderCount = ((PBRShaderProvider) shaderProvider).getShaderCount();
	}
	ui.shaderCount.setText(String.valueOf(shaderCount));
	
	stage.draw();
}
 
Example #4
Source File: SceneManager.java    From gdx-gltf with Apache License 2.0 4 votes vote down vote up
public SceneManager(ShaderProvider shaderProvider, DepthShaderProvider depthShaderProvider)
{
	this(shaderProvider, depthShaderProvider, new SceneRenderableSorter());
}