public GameRenderer(Viewport viewport, Camera camera, GameEngine engine) { this.viewport = viewport; this.camera = camera; this.engine = engine; shapeRenderer = new MyShapeRenderer(); shapeRenderer.setAutoShapeType(true); spriteBatch = new SpriteBatch(); font = new BitmapFont(); font.setColor(Color.WHITE); font.setUseIntegerPositions(false); font.getData().setScale(0.01f); shadowBatch = new ModelBatch(new DepthShaderProvider()); ShaderProgram.pedantic = false; final String vertUber = Gdx.files.internal("shaders/uber.vert").readString(); final String fragUber = Gdx.files.internal("shaders/uber.frag").readString(); modelBatch = new ModelBatch(new DefaultShaderProvider(vertUber, fragUber) { @Override protected Shader createShader(final Renderable renderable) { return new UberShader(renderable, config); } }); }
@Override public void create () { modelBatch = new ModelBatch(new DefaultShaderProvider()); // modelBatch = new ModelBatch(); environment = new Environment(); environment.set(new ColorAttribute(ColorAttribute.AmbientLight, .4f, .4f, .4f, 1f)); environment.add(new DirectionalLight().set(0.8f, 0.8f, 0.8f, -1f, -0.8f, -0.2f)); cam = new PerspectiveCamera(67, Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); cam.position.set(10f, 10f, 10f); cam.lookAt(0, 0, 0); cam.near = 0.1f; cam.far = 300f; cam.update(); ModelBuilder modelBuilder = new ModelBuilder(); model = modelBuilder.createBox(5f, 5f, 5f, new Material(ColorAttribute.createDiffuse(Color.GREEN)), Usage.Position | Usage.Normal); instance = new ModelInstance(model); // model = new G3dModelLoader(new UBJsonReader()).loadModel(Gdx.files.internal("data/g3d/knight.g3db")); // instance = new ModelInstance(model); Gdx.input.setInputProcessor(new InputMultiplexer(this, inputController = new CameraInputController(cam))); }
@Override protected void initialize() { displayableCollections = new Array<Array<? extends Displayable>>(); modelDisplayables = new Array<ModelDisplayable>(); displayableCollections.add(modelDisplayables); decalDisplayables = new Array<DecalDisplayable>(); displayableCollections.add(decalDisplayables); renderContext = new RenderContext( new DefaultTextureBinder(DefaultTextureBinder.WEIGHTED)); renderContext.setCullFace(GL20.GL_BACK); modelBatch = new ModelBatch(renderContext, new DefaultShaderProvider(), new HelixRenderableSorter()); decalBatch = new DecalBatch(new CameraGroupStrategy(camera)); spriteBatch = new SpriteBatch(); }
@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); }
private void initShaders() { FileHandle vertexFile = Gdx.files.internal("shaders/vertex.glsl"); FileHandle fragFile = Gdx.files.internal("shaders/frag.glsl"); shaderProvider = new DefaultShaderProvider(vertexFile, fragFile); shaderProvider.config.numPointLights = 10; shaderProvider.config.numDirectionalLights = 2; // check shader compile logs /*shader = new ShaderProgram(vertexFile, fragFile); ShaderProgram.pedantic = false; String log = shader.getLog(); if (!shader.isCompiled()) throw new GdxRuntimeException(log); if (log!=null && log.length()!=0) System.out.println("Shader Log: "+log);*/ }
@Override public boolean setup() { modelBatch = new ModelBatch(new DefaultShaderProvider()); lights = new Environment(); lights.set(new ColorAttribute(ColorAttribute.AmbientLight, 1.0f, 1.0f, 1.0f, 1.f)); lights.add(new DirectionalLight().set(0.3f, 0.3f, 0.3f, 0, 1, -0.2f)); cam = new MapCamera(mMap); renderContext = new RenderContext(new DefaultTextureBinder(DefaultTextureBinder.WEIGHTED, 1)); // shader = new DefaultShader(renderable.material, // renderable.mesh.getVertexAttributes(), true, false, 1, 0, 0, 0); // shader.init(); return true; }
@Override public boolean setup() { // if (assets == null) // assets = new AssetManager(); // assets.load("data/g3d/invaders.g3dj", Model.class); // loading = true; modelBatch = new ModelBatch(new DefaultShaderProvider()); lights = new Environment(); // lights.ambientLight.set(1.0f, 1.0f, 1.0f, 1f); // lights.ambientLight.set(215 / 255f, // 240 / 255f, // 51 / 255f, 1f); lights.add(new DirectionalLight().set(0.9f, 0.9f, 0.9f, 0, 1, -0.2f)); cam = new MapCamera(mMap); return true; }
public void compileShader() { try { getRawShader(); } catch (Exception e) { e.printStackTrace(); } String frag = rawFragShader; String vert = rawVertShader; vert = TextUtils.replaceLine("#version", "", vert); vert = "#version 120\n" + "\n" + "#define LIGHT_COUNT "+lightPoints.size()+"\n" + "\n" + vert; shaderProgram = new ShaderProgram(vert, frag); if(!shaderProgram.isCompiled()) { System.out.println(shaderProgram.getLog()); System.out.println(); System.out.println("Vertex"); System.out.println(shaderProgram.getVertexShaderSource()); System.out.println(); System.out.println("Fragment"); System.out.println(shaderProgram.getFragmentShaderSource()); System.out.println(); } for(int i = 0; i < lightPoints.size(); i++){ Quaternion quat = lightPoints.get(i); int loc = shaderProgram.getUniformLocation("u_lightPos[" + i + "]"); float[] pack = new float[]{quat.x, quat.y, quat.z, quat.w}; shaderProgram.setUniform4fv(loc, pack, 0, pack.length); } modelBatch = new ModelBatch(new DefaultShaderProvider(){ @Override protected Shader createShader(Renderable renderable) { return new DepthMapShader(renderable, shaderProgram); } }); }
public LightWrapper(T light) { this.light = light; shaderProgram = WorldRenderer.setupShader("depth/light"); if(!shaderProgram.isCompiled()) throw new GdxRuntimeException("Unable to compile shader: "+shaderProgram.getLog()); batch = new ModelBatch(new DefaultShaderProvider() { @Override protected Shader createShader(Renderable renderable) { return new DepthMapShader(renderable, shaderProgram); } }); }
/** Construct a ModelBatch, using this constructor makes you responsible for calling context.begin() and context.end() yourself. * @param context The {@link RenderContext} to use. * @param shaderProvider The {@link ShaderProvider} to use, will be disposed when this ModelBatch is disposed. * @param sorter The {@link RenderableSorter} to use. */ public ModelBatch (final RenderContext context, final ShaderProvider shaderProvider, final RenderableSorter sorter) { this.sorter = (sorter == null) ? new DefaultRenderableSorter() : sorter; this.ownContext = (context == null); this.context = (context == null) ? new RenderContext(new DefaultTextureBinder(DefaultTextureBinder.WEIGHTED, 1)) : context; this.shaderProvider = (shaderProvider == null) ? new DefaultShaderProvider() : shaderProvider; }
@Override public void create () { Gdx.gl.glClearColor(0.2f, 0.3f, 1.0f, 0.f); atlas = new TextureAtlas(Gdx.files.internal("data/testpack")); regions = atlas.getRegions(); modelBatch = new ModelBatch(new DefaultShaderProvider()); environment = new Environment(); environment.set(new ColorAttribute(ColorAttribute.AmbientLight, .4f, .4f, .4f, 1f)); environment.add(new DirectionalLight().set(0.8f, 0.8f, 0.8f, -1f, -0.8f, -0.2f)); cam = new PerspectiveCamera(67, Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); cam.position.set(10f, 10f, 10f); cam.lookAt(0, 0, 0); cam.near = 0.1f; cam.far = 300f; cam.update(); ModelBuilder modelBuilder = new ModelBuilder(); final Material material = new Material(ColorAttribute.createDiffuse(1f, 1f, 1f, 1f), new TextureAttribute(TextureAttribute.Diffuse)); model = modelBuilder.createBox(5f, 5f, 5f, material, Usage.Position | Usage.Normal | Usage.TextureCoordinates); instance = new ModelInstance(model); attribute = instance.materials.get(0).get(TextureAttribute.class, TextureAttribute.Diffuse); Gdx.input.setInputProcessor(new InputMultiplexer(this, inputController = new CameraInputController(cam))); }
public static void createBatchs() { Config modelConfigShader = new Config(Gdx.files.classpath(VERTEX_SHADER).readString(), Gdx.files.classpath(FRAGMENT_SHADER).readString()); modelConfigShader.numBones = MAX_BONES; modelConfigShader.numDirectionalLights = 0; modelConfigShader.numPointLights = 0; modelConfigShader.numSpotLights = 0; modelBatch = new ModelBatch(new DefaultShaderProvider(modelConfigShader)); shadowBatch = new ModelBatch(new DepthShaderProvider()); floorBatch = new ModelBatch(new DefaultShaderProvider(Gdx.files.classpath(VERTEX_SHADER), Gdx.files.classpath(FLOOR_FRAGMENT_SHADER))); }
@Override public void initialize(AssetManager manager) { ShaderLoader.Pedantic = false; ShaderProgram.pedantic = false; /** LOAD SHADER PROGRAMS WITH ASSET MANAGER **/ manager.load("shader/star.vertex.glsl", ShaderProgram.class); manager.load("shader/gal.vertex.glsl", ShaderProgram.class); manager.load("shader/font.vertex.glsl", ShaderProgram.class); manager.load("shader/sprite.vertex.glsl", ShaderProgram.class); manager.load("atmgrounddefault", GroundShaderProvider.class, new AtmosphereGroundShaderProviderParameter("shader/default.vertex.glsl", "shader/default.fragment.glsl")); manager.load("spsurface", DefaultShaderProvider.class, new DefaultShaderProviderParameter("shader/starsurface.vertex.glsl", "shader/starsurface.fragment.glsl")); manager.load("spbeam", DefaultShaderProvider.class, new DefaultShaderProviderParameter("shader/default.vertex.glsl", "shader/beam.fragment.glsl")); manager.load("spdepth", DefaultShaderProvider.class, new DefaultShaderProviderParameter("shader/normal.vertex.glsl", "shader/depth.fragment.glsl")); manager.load("spopaque", DefaultShaderProvider.class, new DefaultShaderProviderParameter("shader/normal.vertex.glsl", "shader/opaque.fragment.glsl")); manager.load("atm", AtmosphereShaderProvider.class, new AtmosphereShaderProviderParameter("shader/atm.vertex.glsl", "shader/atm.fragment.glsl")); if (!Constants.webgl) { manager.load("atmground", GroundShaderProvider.class, new AtmosphereGroundShaderProviderParameter("shader/normal.vertex.glsl", "shader/normal.fragment.glsl")); } stars = new Array<IRenderable>(); pixelRenderSystems = new AbstractRenderSystem[3]; renderProcesses = new Array<IRenderSystem>(); blendNoDepthRunnable = new RenderSystemRunnable() { @Override public void run(AbstractRenderSystem renderSystem, Array<IRenderable> renderables, ICamera camera) { Gdx.gl.glEnable(GL20.GL_BLEND); Gdx.gl.glDisable(GL20.GL_DEPTH_TEST); Gdx.gl.glDepthMask(false); } }; blendDepthRunnable = new RenderSystemRunnable() { @Override public void run(AbstractRenderSystem renderSystem, Array<IRenderable> renderables, ICamera camera) { Gdx.gl.glEnable(GL20.GL_BLEND); Gdx.gl.glEnable(GL20.GL_DEPTH_TEST); Gdx.gl.glDepthMask(true); } }; if (GlobalConf.scene.SHADOW_MAPPING) { // Shadow map camera cameraLight = new PerspectiveCamera(0.5f, GlobalConf.scene.SHADOW_MAPPING_RESOLUTION, GlobalConf.scene.SHADOW_MAPPING_RESOLUTION); // Aux vectors aux1 = new Vector3(); aux1d = new Vector3d(); // Build frame buffers and arrays buildShadowMapData(); } if (GlobalConf.postprocess.POSTPROCESS_LIGHT_SCATTERING) { buildGlowData(); } }
@Override public void loadAsync(AssetManager manager, String fileName, FileHandle file, T parameter) { shaderProvider = new DefaultShaderProvider(Gdx.files.internal(parameter.vertexShader), Gdx.files.internal(parameter.fragmentShader)); }
@Override public DefaultShaderProvider loadSync(AssetManager manager, String fileName, FileHandle file, DefaultShaderProviderParameter parameter) { return shaderProvider; }
/** Construct a ModelBatch with the default implementation and the specified ubershader. See {@link DefaultShader} for more * information about using a custom ubershader. Requires OpenGL ES 2.0. * @param vertexShader The {@link FileHandle} of the vertex shader to use. * @param fragmentShader The {@link FileHandle} of the fragment shader to use. */ public ModelBatch (final FileHandle vertexShader, final FileHandle fragmentShader) { this(null, new DefaultShaderProvider(vertexShader, fragmentShader), null); }
/** Construct a ModelBatch with the default implementation and the specified ubershader. See {@link DefaultShader} for more * information about using a custom ubershader. Requires OpenGL ES 2.0. * @param vertexShader The vertex shader to use. * @param fragmentShader The fragment shader to use. */ public ModelBatch (final String vertexShader, final String fragmentShader) { this(null, new DefaultShaderProvider(vertexShader, fragmentShader), null); }