[LayaAir 2.0]3d 轮廓描边示例改描边颜色无效
BlurEffect.init();
var unlitMaterial = new UnlitMaterial();
unlitMaterial.albedoColor = new Vector4(255,0,0,255);
var shurikenMaterial:ShurikenParticleMaterial = new ShurikenParticleMaterial();
shurikenMaterial.color = new Vector4(255,0,0,255);
按我的理解,官方示例上的unlitMaterial.albedoColor不是描边颜色吗?为何修改了还一直是红色描边。如果想要修改描边颜色 去哪修改呢?下面这一段代码里也没看到哪里改颜色,我现在的需求是不同的模型需要不同的描边颜色,这种能实现吗?
createDrawMeshCommandBuffer(camera:Camera,renders:BaseRender[],materials:Material[]):CommandBuffer{
var buf:CommandBuffer = new CommandBuffer();
//当需要在流程中拿摄像机渲染效果的时候 设置true
camera.enableBuiltInRenderTexture = true;
//创建和屏幕一样大的Rendertexture
var viewPort:Viewport = camera.viewport;
var renderTexture = RenderTexture.createFromPool(viewPort.width,viewPort.height,RenderTextureFormat.R8G8B8A8,RenderTextureDepthFormat.DEPTHSTENCIL_NONE);
//将RenderTexture设置为渲染目标
buf.setRenderTarget(renderTexture);
//清楚渲染目标的颜色为黑色,不清理深度
buf.clearRenderTarget(true,false,new Vector4(0,0,0,0));
//将传入的Render渲染到纹理上
for(var i = 0,n = renders.length;i<n;i++){
buf.drawRender(renders[i],materials[i],0);
}
//创建新的RenderTexture
var subRendertexture = RenderTexture.createFromPool(viewPort.width,viewPort.height,RenderTextureFormat.R8G8B8A8,RenderTextureDepthFormat.DEPTHSTENCIL_NONE);
//将renderTexture的结果复制到subRenderTexture
buf.blitScreenQuad(renderTexture,subRendertexture);
//设置模糊的参数
var downSampleFactor:number = 2;
var downSampleWidth:number = viewPort.width/downSampleFactor;
var downSampleheigh:number = viewPort.height/downSampleFactor;
var texSize:Vector4 = new Vector4(1.0/viewPort.width,1.0/viewPort.height,viewPort.width,downSampleheigh);
//创建模糊材质
var blurMaterial:BlurMaterial = new BlurMaterial(texSize,1);
//创建降采样RenderTexture1
var downRenderTexture = RenderTexture.createFromPool(downSampleWidth,downSampleheigh,RenderTextureFormat.R8G8B8,RenderTextureDepthFormat.DEPTHSTENCIL_NONE);
//降采样 使用blurMaterial材质的0SubShader将Rendertexture渲染到DownRendertexture
buf.blitScreenQuadByMaterial(renderTexture,downRenderTexture,null,blurMaterial,0);
//创建降采样RenderTexture2
var blurTexture:RenderTexture = RenderTexture.createFromPool(downSampleWidth,downSampleheigh,RenderTextureFormat.R8G8B8,RenderTextureDepthFormat.DEPTHSTENCIL_NONE);
blurTexture.filterMode = FilterMode.Bilinear;
//Horizontal blur 使用blurMaterial材质的1SubShader
buf.blitScreenQuadByMaterial(downRenderTexture,blurTexture,null,blurMaterial,1);
//vertical blur 使用blurMaterial材质的2SubShader
buf.blitScreenQuadByMaterial(blurTexture,downRenderTexture,null,blurMaterial,2);
//Horizontal blur 使用blurMaterial材质的1SubShader
buf.blitScreenQuadByMaterial(downRenderTexture,blurTexture,null,blurMaterial,1);
//vertical blur 使用blurMaterial材质的2SubShader
buf.blitScreenQuadByMaterial(blurTexture,downRenderTexture,null,blurMaterial,2);
//在命令流里面插入设置图片命令流,在调用的时候会设置blurMaterial的图片数据
buf.setShaderDataTexture(blurMaterial._shaderValues,BlurMaterial.SHADERVALUE_SOURCETEXTURE0,downRenderTexture);
buf.setShaderDataTexture(blurMaterial._shaderValues,BlurMaterial.ShADERVALUE_SOURCETEXTURE1,subRendertexture);
//caculate edge计算边缘图片
buf.blitScreenQuadByMaterial(blurTexture,renderTexture,null,blurMaterial,3);
//重新传入图片
buf.setShaderDataTexture(blurMaterial._shaderValues,BlurMaterial.SHADERVALUE_SOURCETEXTURE0,renderTexture);
//将camera渲染结果复制到subRendertexture,使用blurMaterial的4通道shader
buf.blitScreenQuadByMaterial(null,subRendertexture,null,blurMaterial,4);
//将subRenderTexture重新赋值到camera的渲染结果上面
buf.blitScreenQuadByMaterial(subRendertexture,null);
return buf;
}
var unlitMaterial = new UnlitMaterial();
unlitMaterial.albedoColor = new Vector4(255,0,0,255);
var shurikenMaterial:ShurikenParticleMaterial = new ShurikenParticleMaterial();
shurikenMaterial.color = new Vector4(255,0,0,255);
按我的理解,官方示例上的unlitMaterial.albedoColor不是描边颜色吗?为何修改了还一直是红色描边。如果想要修改描边颜色 去哪修改呢?下面这一段代码里也没看到哪里改颜色,我现在的需求是不同的模型需要不同的描边颜色,这种能实现吗?
createDrawMeshCommandBuffer(camera:Camera,renders:BaseRender[],materials:Material[]):CommandBuffer{
var buf:CommandBuffer = new CommandBuffer();
//当需要在流程中拿摄像机渲染效果的时候 设置true
camera.enableBuiltInRenderTexture = true;
//创建和屏幕一样大的Rendertexture
var viewPort:Viewport = camera.viewport;
var renderTexture = RenderTexture.createFromPool(viewPort.width,viewPort.height,RenderTextureFormat.R8G8B8A8,RenderTextureDepthFormat.DEPTHSTENCIL_NONE);
//将RenderTexture设置为渲染目标
buf.setRenderTarget(renderTexture);
//清楚渲染目标的颜色为黑色,不清理深度
buf.clearRenderTarget(true,false,new Vector4(0,0,0,0));
//将传入的Render渲染到纹理上
for(var i = 0,n = renders.length;i<n;i++){
buf.drawRender(renders[i],materials[i],0);
}
//创建新的RenderTexture
var subRendertexture = RenderTexture.createFromPool(viewPort.width,viewPort.height,RenderTextureFormat.R8G8B8A8,RenderTextureDepthFormat.DEPTHSTENCIL_NONE);
//将renderTexture的结果复制到subRenderTexture
buf.blitScreenQuad(renderTexture,subRendertexture);
//设置模糊的参数
var downSampleFactor:number = 2;
var downSampleWidth:number = viewPort.width/downSampleFactor;
var downSampleheigh:number = viewPort.height/downSampleFactor;
var texSize:Vector4 = new Vector4(1.0/viewPort.width,1.0/viewPort.height,viewPort.width,downSampleheigh);
//创建模糊材质
var blurMaterial:BlurMaterial = new BlurMaterial(texSize,1);
//创建降采样RenderTexture1
var downRenderTexture = RenderTexture.createFromPool(downSampleWidth,downSampleheigh,RenderTextureFormat.R8G8B8,RenderTextureDepthFormat.DEPTHSTENCIL_NONE);
//降采样 使用blurMaterial材质的0SubShader将Rendertexture渲染到DownRendertexture
buf.blitScreenQuadByMaterial(renderTexture,downRenderTexture,null,blurMaterial,0);
//创建降采样RenderTexture2
var blurTexture:RenderTexture = RenderTexture.createFromPool(downSampleWidth,downSampleheigh,RenderTextureFormat.R8G8B8,RenderTextureDepthFormat.DEPTHSTENCIL_NONE);
blurTexture.filterMode = FilterMode.Bilinear;
//Horizontal blur 使用blurMaterial材质的1SubShader
buf.blitScreenQuadByMaterial(downRenderTexture,blurTexture,null,blurMaterial,1);
//vertical blur 使用blurMaterial材质的2SubShader
buf.blitScreenQuadByMaterial(blurTexture,downRenderTexture,null,blurMaterial,2);
//Horizontal blur 使用blurMaterial材质的1SubShader
buf.blitScreenQuadByMaterial(downRenderTexture,blurTexture,null,blurMaterial,1);
//vertical blur 使用blurMaterial材质的2SubShader
buf.blitScreenQuadByMaterial(blurTexture,downRenderTexture,null,blurMaterial,2);
//在命令流里面插入设置图片命令流,在调用的时候会设置blurMaterial的图片数据
buf.setShaderDataTexture(blurMaterial._shaderValues,BlurMaterial.SHADERVALUE_SOURCETEXTURE0,downRenderTexture);
buf.setShaderDataTexture(blurMaterial._shaderValues,BlurMaterial.ShADERVALUE_SOURCETEXTURE1,subRendertexture);
//caculate edge计算边缘图片
buf.blitScreenQuadByMaterial(blurTexture,renderTexture,null,blurMaterial,3);
//重新传入图片
buf.setShaderDataTexture(blurMaterial._shaderValues,BlurMaterial.SHADERVALUE_SOURCETEXTURE0,renderTexture);
//将camera渲染结果复制到subRendertexture,使用blurMaterial的4通道shader
buf.blitScreenQuadByMaterial(null,subRendertexture,null,blurMaterial,4);
//将subRenderTexture重新赋值到camera的渲染结果上面
buf.blitScreenQuadByMaterial(subRendertexture,null);
return buf;
}
没有找到相关结果
已邀请:
要回复问题请先登录
0 个回复