/CreatorShaderDemo

Shader demo based on the material system of Cocos Creator 2.2. And add the branch v2.3.0 for Cocos Creator v2.3.0.

Primary LanguageTypeScript

CreatorShaderDemo

Shader demo based on the material system of Cocos Creator. The master branch corresponds to CocosCreator v2.2.0. Please use v2.3.0 branch for CocosCreator v2.3.0.

CustomRenderComponent & CustomAssembler

CustomRenderComponent must override the two methods _resetAssembler and _activateMaterial.

    //override
    _resetAssembler () {
        this.setVertsDirty(true);
        this._assembler = new CustomAssembler();
        this._assembler.init(this);
    }

    //override
    _activateMaterial () {
        let material = this.sharedMaterials[0];
        if (!material) {
            this.disableRender();
            return;
        }
        
        material = cc.Material.getInstantiatedMaterial(material, this);
        this.setMaterial(0, material);
        this.markForRender(true);
    }

CustomAssembler must override methods init, updateRenderData and fillBuffers.

   init (comp) {
        super.init(comp);
        this._renderData = new cc.RenderData();
        this._renderData.init(this);

        this.initLocal();
        this.initData();
    }

    //override
    updateRenderData (comp) {
        if (comp._vertsDirty) {
            this.updateUVs(comp);
            this.updateVerts(comp);
            comp._vertsDirty = false;
        }
    }

Material & Effect

Transplant some 2D Shaders to learn the new material system.

天气相关:

滚动背景

预览

预览

预览

预览

图片相关:

使用RenderTexture进行屏幕后处理:

预览

GamePlay:

点光源:

预览