[LayaAir3]求助,尝试把示例中的描边shader改写成独立shader文件时的问题
官网有描边shader,但是是运行时才起效的ts文件,现在我把里面的核心部分复制到独立的 .shader文件里,但是效果不对
如图,描边部分完全遮盖了纹理部分,应该要设置描边部分的pass的cull=front吧,但是在 .shader中应该怎么写?
这个是 .shader部分的代码:
Shader3D Start
{
type:Shader3D,
name:myShader,
enableInstancing:true,
supportReflectionProbe:true,
uniformMap:{
u_OutlineLightness:{type:Float},
u_OutlineColor:{type:Color},
u_AlbedoTexture:{type:Texture2D},
u_OutlineWidth:{type:Float}
},
defines: {
ENABLEVERTEXCOLOR: { type: bool, default: false }
}
shaderPass:[
{
pipeline:Forward,
VS:unlitVS,
FS:unlitPS
},
{
pipeline:Forward,
VS:unlitVs2,
FS:unlitPs2
}
]
}
Shader3D End
GLSL Start
#defineGLSL unlitVS
#include "Sprite3DVertex.glsl";
#include "VertexCommon.glsl";
#include "Camera.glsl";
void main()
{
Vertex vertex;
getVertexParams(vertex);
vec4 position = vec4((vertex.positionOS) + (vertex.normalOS) * u_OutlineWidth, 1.0);
mat4 worldMat = getWorldMatrix();
vec3 positionWS = (worldMat * vec4(position)).xyz;
gl_Position = getPositionCS(positionWS);
gl_Position = remapPositionZ(gl_Position);
}
#endGLSL
#defineGLSL unlitPS
#if defined(GL_FRAGMENT_PRECISION_HIGH)
precision highp float;
#else
precision mediump float;
#endif
void main()
{
vec3 finalColor = u_OutlineColor.rgb * u_OutlineLightness;
gl_FragColor = vec4(finalColor,0.0);
}
#endGLSL
#defineGLSL unlitVs2
#include "Camera.glsl";
#include "Sprite3DVertex.glsl";
#include "VertexCommon.glsl";
varying vec3 v_Normal;
varying vec2 v_Texcoord0;
void main()
{
Vertex vertex;
getVertexParams(vertex);
mat4 worldMat = getWorldMatrix();
vec3 positionWS = (worldMat * vec4(vertex.positionOS, 1.0)).xyz;
gl_Position = getPositionCS(positionWS);
v_Normal = normalize((worldMat * vec4(vertex.normalOS, 0.0)).xyz);
v_Texcoord0 = vertex.texCoord0;
gl_Position=remapPositionZ(gl_Position);
}
#endGLSL
#defineGLSL unlitPs2
#if defined(GL_FRAGMENT_PRECISION_HIGH)
precision highp float;
#else
precision mediump float;
#endif
varying vec2 v_Texcoord0;
varying vec3 v_Normal;
void main()
{
vec4 albedoTextureColor = vec4(1.0);
albedoTextureColor = texture2D(u_AlbedoTexture, v_Texcoord0);
gl_FragColor = albedoTextureColor;
}
#endGLSL
GLSL End
如图,描边部分完全遮盖了纹理部分,应该要设置描边部分的pass的cull=front吧,但是在 .shader中应该怎么写?
这个是 .shader部分的代码:
Shader3D Start
{
type:Shader3D,
name:myShader,
enableInstancing:true,
supportReflectionProbe:true,
uniformMap:{
u_OutlineLightness:{type:Float},
u_OutlineColor:{type:Color},
u_AlbedoTexture:{type:Texture2D},
u_OutlineWidth:{type:Float}
},
defines: {
ENABLEVERTEXCOLOR: { type: bool, default: false }
}
shaderPass:[
{
pipeline:Forward,
VS:unlitVS,
FS:unlitPS
},
{
pipeline:Forward,
VS:unlitVs2,
FS:unlitPs2
}
]
}
Shader3D End
GLSL Start
#defineGLSL unlitVS
#include "Sprite3DVertex.glsl";
#include "VertexCommon.glsl";
#include "Camera.glsl";
void main()
{
Vertex vertex;
getVertexParams(vertex);
vec4 position = vec4((vertex.positionOS) + (vertex.normalOS) * u_OutlineWidth, 1.0);
mat4 worldMat = getWorldMatrix();
vec3 positionWS = (worldMat * vec4(position)).xyz;
gl_Position = getPositionCS(positionWS);
gl_Position = remapPositionZ(gl_Position);
}
#endGLSL
#defineGLSL unlitPS
#if defined(GL_FRAGMENT_PRECISION_HIGH)
precision highp float;
#else
precision mediump float;
#endif
void main()
{
vec3 finalColor = u_OutlineColor.rgb * u_OutlineLightness;
gl_FragColor = vec4(finalColor,0.0);
}
#endGLSL
#defineGLSL unlitVs2
#include "Camera.glsl";
#include "Sprite3DVertex.glsl";
#include "VertexCommon.glsl";
varying vec3 v_Normal;
varying vec2 v_Texcoord0;
void main()
{
Vertex vertex;
getVertexParams(vertex);
mat4 worldMat = getWorldMatrix();
vec3 positionWS = (worldMat * vec4(vertex.positionOS, 1.0)).xyz;
gl_Position = getPositionCS(positionWS);
v_Normal = normalize((worldMat * vec4(vertex.normalOS, 0.0)).xyz);
v_Texcoord0 = vertex.texCoord0;
gl_Position=remapPositionZ(gl_Position);
}
#endGLSL
#defineGLSL unlitPs2
#if defined(GL_FRAGMENT_PRECISION_HIGH)
precision highp float;
#else
precision mediump float;
#endif
varying vec2 v_Texcoord0;
varying vec3 v_Normal;
void main()
{
vec4 albedoTextureColor = vec4(1.0);
albedoTextureColor = texture2D(u_AlbedoTexture, v_Texcoord0);
gl_FragColor = albedoTextureColor;
}
#endGLSL
GLSL End
没有找到相关结果
已邀请:
要回复问题请先登录
0 个回复