如何将Blender属性传递给自定义着色器[libGdx]

时间:2018-07-26 08:28:36

标签: libgdx shader 3d-model

我是libGdx编程的新手。我看到某些属性(例如顶点法线)会作为a_normal属性从g3db 3d模型文件自动传输到自定义着色器。在默认的着色器属性(如漫射照明)中,镜面照明也将自动传输。现在我想知道如何将它们传输到我的自定义着色器。这是我的代码。

public class MyGdxGame implements ApplicationListener {
    public PerspectiveCamera cam;
    public CameraInputController camController;
    public ModelBatch modelBatch;
    public AssetManager assets;
    public ModelInstance instance;
    public Model model;
    public Renderable renderable;
    public RenderContext renderContext;
    public Shader shader ;

@Override
public void create () {
    modelBatch = new ModelBatch();

    UBJsonReader jsonReader = new UBJsonReader();
    G3dModelLoader modelLoader = new G3dModelLoader(jsonReader);
    model = modelLoader.loadModel(Gdx.files.getFileHandle("untitled.g3db", Files.FileType.Internal));
    instance = new ModelInstance(model);
    cam = new PerspectiveCamera(67, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
    cam.position.set(2f, 2f, 2f);
    cam.lookAt(0,0,0);
    cam.near = 1f;
    cam.far = 300f;
    cam.update();

    camController = new CameraInputController(cam);
    Gdx.input.setInputProcessor(camController);

    NodePart blockPart = model.nodes.get(0).parts.get(0);

    renderable = new Renderable();
    blockPart.setRenderable(renderable);
    renderable.environment = null;
    renderable.worldTransform.idt();

    renderContext = new RenderContext(new DefaultTextureBinder(DefaultTextureBinder.WEIGHTED, 1));
    String vert = Gdx.files.internal("shader.vert").readString();
    String frag = Gdx.files.internal("shader.frag").readString();
    shader = new DefaultShader(renderable, new DefaultShader.Config(vert, frag));
    shader.init();
}


@Override
public void render () {
    camController.update();

    Gdx.gl.glViewport(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT | GL20.GL_DEPTH_BUFFER_BIT);

    renderContext.begin();
    shader.begin(cam, renderContext);
    shader.render(renderable);
    shader.end();
    renderContext.end();
}

@Override
public void dispose () {
    modelBatch.dispose();
    assets.dispose();
}

@Override
public void resize(int width, int height) {
}

@Override
public void pause() {
}

@Override
public void resume() {
}

}

0 个答案:

没有答案