@Override public Shader getShader(Renderable renderable) { int shader = 0; boolean fogFlag = Settings.getBooleanSettingValue(Settings.GRAPHICS_FOG); if (renderable.userData instanceof RenderingSettings) fogFlag &= ((RenderingSettings) renderable.userData).fogEnabled; if (fogFlag) shader |= FEATURE_FOG; boolean aoFlag = renderable.meshPart.mesh.getVertexAttributes() == CubesVertexAttributes.VERTEX_ATTRIBUTES_AO; if (aoFlag) shader |= FEATURE_AO; getShaderIf(shader, renderable, fogFlag, aoFlag); return shaders[shader]; }
@Override public Shader getShader(Renderable renderable) { // небольшой такой КОСТЫЛЬ из за убогости LibGDX // явно укажем версию шейдеров. и немного поправим совместимость... ShaderProgram.prependVertexCode = SHADER_VERSION + "\n"; ShaderProgram.prependFragmentCode = SHADER_VERSION + "\n"; Shader shader = super.getShader(renderable); ShaderProgram.prependVertexCode = null; ShaderProgram.prependFragmentCode = null; return shader; }
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 Shader getShader (Renderable renderable) { try { return super.getShader(renderable); } catch (Throwable e) { if (tempFolder != null && Gdx.app.getType() == ApplicationType.Desktop) Gdx.files.absolute(tempFolder).child(name + ".log.txt").writeString(e.getMessage(), false); if (!revert()) { Gdx.app.error("ShaderCollectionTest", e.getMessage()); throw new GdxRuntimeException("Error creating shader, cannot revert to default shader", e); } error = true; Gdx.app.error("ShaderTest", "Could not create shader, reverted to default shader.", e); return super.getShader(renderable); } }
@Override public void create () { modelBatch = new ModelBatch(new BaseShaderProvider() { @Override protected Shader createShader (Renderable renderable) { return new TestShader(); } }); 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(); camController = new CameraInputController(cam); Gdx.input.setInputProcessor(camController); Material material = new Material(new TestAttribute(1f)); ModelBuilder builder = new ModelBuilder(); model = builder.createCone(5, 5, 5, 20, material, Usage.Position); instance = new ModelInstance(model); testAttribute = (TestAttribute)instance.materials.get(0).get(TestAttribute.ID); }
@Override public Shader getShader(Renderable renderable) { int shader = 0; boolean fogFlag = Settings.getBooleanSettingValue(Settings.GRAPHICS_FOG); if (renderable.userData instanceof RenderingSettings) fogFlag &= ((RenderingSettings) renderable.userData).fogEnabled; if (fogFlag) shader |= FEATURE_FOG; boolean aoFlag = renderable.meshPart.mesh.getVertexAttributes() == CubesVertexAttributes.VERTEX_ATTRIBUTES_AO; if (aoFlag) shader |= FEATURE_AO; if (shaders[shader] == null) { if (shader == 0) { shaders[shader] = new CubesShader(renderable); } else { ArrayList<Feature> f = new ArrayList<Feature>(); if (fogFlag) f.add(new FogFeature()); if (aoFlag) f.add(new AmbientOcclusionFeature()); shaders[shader] = new FeatureShader(renderable, f); } ShaderProgram program = shaders[shader].program; if (!program.isCompiled()) { Log.error("Failed to compile shader"); Log.error("Shader log: \n" + program.getLog()); Log.error("Fragment shader source: \n" + program.getFragmentShaderSource()); Log.error("Vertex shader source: \n" + program.getVertexShaderSource()); throw new CubesException("Failed to compile shader"); } shaders[shader].init(); } return shaders[shader]; }
@Override protected Shader createShader(final Renderable renderable) { DepthMapShader.Params params = new DepthMapShader.Params(); params.useBones = ShaderUtils.useBones(renderable); return new DepthMapShader(renderable, params); }
@Override protected Shader createShader(Renderable renderable) { PBRShader.Params params = new PBRShader.Params(); params.albedo = ShaderUtils.hasAlbedo(renderable); params.metalness = ShaderUtils.hasMetalness(renderable); params.roughness = ShaderUtils.hasRoughness(renderable); params.normal = ShaderUtils.hasPbrNormal(renderable); params.ambientOcclusion = ShaderUtils.hasAmbientOcclusion(renderable); params.useBones = ShaderUtils.useBones(renderable); params.lit = ShaderUtils.hasLights(environment); params.gammaCorrection = ShaderUtils.useGammaCorrection(environment); params.imageBasedLighting = ShaderUtils.useImageBasedLighting(environment); return new PBRShader(renderable, environment, params); }
public static Renderable createRenderableFromMesh(Mesh mesh, Material material, Shader shader, Environment environment) { Renderable outRend=new Renderable(); outRend.meshPart.mesh=mesh; outRend.meshPart.primitiveType=GL20.GL_TRIANGLES; if(material!=null) outRend.material=material; if(environment!=null) outRend.environment=environment; outRend.meshPart.offset=0; //strada.shader=elrShader; if(shader!=null) outRend.shader=shader; outRend.meshPart.size=mesh.getNumIndices(); return outRend; }
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); } }); }
@Override public void dispose () { for (Shader shader : shaders) { shader.dispose(); } shaders.clear(); }
@Override protected Shader createShader (Renderable renderable) { if (config.vertexShader != null && config.fragmentShader != null && tempFolder != null && Gdx.app.getType() == ApplicationType.Desktop) { String prefix = DefaultShader.createPrefix(renderable, config); Gdx.files.absolute(tempFolder).child(name + ".vertex.glsl").writeString(prefix + config.vertexShader, false); Gdx.files.absolute(tempFolder).child(name + ".fragment.glsl").writeString(prefix + config.fragmentShader, false); } BaseShader result = new MultiPassShader(renderable, config); if (tempFolder != null && Gdx.app.getType() == ApplicationType.Desktop) Gdx.files.absolute(tempFolder).child(name + ".log.txt").writeString(result.program.getLog(), false); return result; }
@Override public int compareTo(Shader other) { if (other == null) return -1; if (other == this) return 0; return 0; }
@Override public int compareTo(Shader other) { return other == null ? -1 : 0; }
protected Shader createShader(Renderable renderable) { return new EmissiveShader(renderable, this.config); }
@Override public int compareTo(Shader other) { return 0; }
@Override public int compareTo(final Shader other) { return 0; }
@Override protected Shader createShader (final Renderable renderable) { return new DefShader(renderable, config); }
@Override protected Shader createShader (final Renderable renderable) { return new ModelShader(renderable, config); }
@Override protected Shader createShader(Renderable renderable) { return new WireframeShader(renderable, config); }
@Override protected Shader createShader(Renderable renderable) { return new ModelShader(renderable, _config); }
@Override protected Shader createShader(Renderable renderable) { return new ShadowShader(renderable, _shaderProgram); }