[LayaAir3]3.3 beta3 ios 15pro偶尔材质会变黑
Shader3D Start
{
type:Shader3D
name:slicePBR
enableInstancing:true,
supportReflectionProbe:true,
uniformMap:{
u_AlphaTestValue: { type: Float, default: 0.5, range: [0.0, 1.0] },
u_TilingOffset: { type: Vector4, default: [1, 1, 0, 0] },
u_AlbedoColor: { type: Color, default: [1, 1, 1, 1] },
u_AlbedoColorScale: { type: Float, default: 1.0 },
u_AlbedoTexture: { type: Texture2D, options: { define: "ALBEDOTEXTURE" } },
// u_AlbedoTexture2: { type: Texture2D, options: { define: "ALBEDOTEXTURE2" } },
// u_AlbedoTexture2Offset: { type: Vector4, default: [1, 1, 0, 0] },
u_RimColor: { type: Color, default: [1.0, 1.0, 1.0, 1.0] },
u_RimPower: { type: Float, default: 4.0, range: [0.0, 10.0] },
u_SliceTexture: { type: Texture2D, options: { define: "SliceTexture" } },
u_SliceProgress: { type: Float, default: 0., range: [0.0, 1.0] },
u_SliceRotation:{ type: Float, default: 0.0, range: [0.0, 360.0] },
u_outlineColor: { type: Color, default: [1.0, 1.0, 1.0, 1.0] },
u_outlineWidth: { type: Float, default: 0.0, range: [0.0, 1.0] },
u_NormalTexture: { type: Texture2D, options: { define: "NORMALTEXTURE" } },
u_NormalScale: { type: Float, default: 1.0, range: [0.0, 2.0] },
u_Metallic: { type: Float, default: 0.0, range: [0.0, 1.0] },
u_Smoothness: { type: Float, default: 0.0, range: [0.0, 1.0] },
u_MetallicGlossTexture: { type: Texture2D, options: { define: "METALLICGLOSSTEXTURE" } },
u_OcclusionTexture: { type: Texture2D, options: { define: "OCCLUSIONTEXTURE" } },
u_OcclusionStrength: { type: Float, default: 1.0 },
u_EmissionColor: { type: Color, default: [0, 0, 0, 0] },
u_EmissionIntensity: { type: Float, default: 1.0 },
u_EmissionTexture: { type: Texture2D, options: { define: "EMISSIONTEXTURE" } },
},
defines: {
EMISSION: { type: bool, default: false },
ENABLEVERTEXCOLOR: { type: bool, default: false },
RIMLIGHT: { type: bool, default: false },
SLICE: { type: bool, default: false },
INNEROUTLINE: { type: bool, default: false },
}
shaderPass:[
{
pipeline:Forward,
VS:LitVS,
FS:LitFS
}
]
}
Shader3D End
GLSL Start
#defineGLSL LitVS
#define SHADER_NAME slicePBR
#include "Math.glsl";
#include "Scene.glsl";
#include "SceneFogInput.glsl"
#include "Camera.glsl";
#include "Sprite3DVertex.glsl";
#include "VertexCommon.glsl";
#include "PBRVertex.glsl";
varying vec3 v_wPos;
void main()
{
Vertex vertex;
getVertexParams(vertex);
PixelParams pixel;
initPixelParams(pixel, vertex);
v_wPos = pixel.positionWS;
gl_Position = getPositionCS(pixel.positionWS);
gl_Position = remapPositionZ(gl_Position);
#ifdef FOG
FogHandle(gl_Position.z);
#endif // FOG
}
#endGLSL
#defineGLSL LitFS
#define SHADER_NAME slicePBR
#include "Color.glsl";
#include "Scene.glsl";
#include "SceneFog.glsl";
#include "Camera.glsl";
#include "Sprite3DFrag.glsl";
#include "PBRMetallicFrag.glsl";
varying vec3 v_wPos;
void initSurfaceInputs(inout SurfaceInputs inputs, inout PixelParams pixel)
{
inputs.alphaTest = u_AlphaTestValue;
#ifdef UV
vec2 uv = transformUV(pixel.uv0, u_TilingOffset);
#else // UV
vec2 uv = vec2(0.0);
#endif // UV
inputs.diffuseColor = u_AlbedoColor.rgb * u_AlbedoColorScale;
inputs.alpha = u_AlbedoColor.a;
#ifdef COLOR
#ifdef ENABLEVERTEXCOLOR
inputs.diffuseColor *= pixel.vertexColor.xyz;
inputs.alpha *= pixel.vertexColor.a;
#endif // ENABLEVERTEXCOLOR
#endif // COLOR
#ifdef ALBEDOTEXTURE
vec4 albedoSampler = texture2D(u_AlbedoTexture, uv);
#ifdef Gamma_u_AlbedoTexture
albedoSampler = gammaToLinear(albedoSampler);
#endif // Gamma_u_AlbedoTexture
inputs.diffuseColor *= albedoSampler.rgb;
inputs.alpha *= albedoSampler.a;
#endif // ALBEDOTEXTURE
inputs.normalTS = vec3(0.0, 0.0, 1.0);
#ifdef NORMALTEXTURE
vec3 normalSampler = texture2D(u_NormalTexture, uv).rgb;
normalSampler = normalize(normalSampler * 2.0 - 1.0);
normalSampler.y *= -1.0;
inputs.normalTS = normalScale(normalSampler, u_NormalScale);
#endif
inputs.metallic = u_Metallic;
inputs.smoothness = u_Smoothness;
#ifdef METALLICGLOSSTEXTURE
vec4 metallicSampler = texture2D(u_MetallicGlossTexture, uv);
inputs.metallic = metallicSampler.x;
inputs.smoothness = (metallicSampler.a * u_Smoothness);
#endif // METALLICGLOSSTEXTURE
inputs.occlusion = 1.0;
#ifdef OCCLUSIONTEXTURE
vec4 occlusionSampler = texture2D(u_OcclusionTexture, uv);
float occlusion = occlusionSampler.g;
inputs.occlusion = (1.0 - u_OcclusionStrength) + occlusion * u_OcclusionStrength;
#endif // OCCLUSIONTEXTURE
inputs.emissionColor = vec3(0.0);
#ifdef EMISSION
inputs.emissionColor = u_EmissionColor.rgb * u_EmissionIntensity;
#ifdef EMISSIONTEXTURE
vec4 emissionSampler = texture2D(u_EmissionTexture, uv);
#ifdef Gamma_u_EmissionTexture
emissionSampler = gammaToLinear(emissionSampler);
#endif // Gamma_u_EmissionTexture
inputs.emissionColor *= emissionSampler.rgb;
#endif // EMISSIONTEXTURE
#endif // EMISSION
}
vec2 rotateUV(vec2 uv, float degrees) {
float rad = radians(degrees);
// 将 uv 平移到中心
vec2 centered = uv - vec2(0.5);
// 计算旋转矩阵
float cosA = cos(rad);
float sinA = sin(rad);
mat2 rotation = mat2(
cosA, -sinA,
sinA, cosA
);
// 应用旋转
centered = rotation * centered;
// 移回 [0, 1] 空间
return centered + vec2(0.5);
}
void main()
{
//坐标平面剔除
// if(u_sliceObjForward.x != 0.0 || u_sliceObjForward.y != 0.0 || u_sliceObjForward.z != 0.0){
// vec3 toSliceDir = normalize(u_sliceObjWPos - v_wPos);
// float sliceDis = dot(u_sliceObjForward, toSliceDir);
// if(sliceDis < 0.0){
// discard;
// }
// }
PixelParams pixel;
getPixelParams(pixel);
//纹理剔除
#ifdef SLICE
#ifdef UV
vec2 uv = pixel.uv0;
#else // UV
vec2 uv = vec2(0.0);
#endif // UV
vec4 sliceSampler = texture2D(u_SliceTexture, rotateUV(uv,u_SliceRotation));
if(sliceSampler.x <= u_SliceProgress){
discard;
}
#endif
SurfaceInputs inputs;
initSurfaceInputs(inputs, pixel);
vec4 surfaceColor = PBR_Metallic_Flow(inputs, pixel);
// #ifdef ALBEDOTEXTURE2
// #ifdef UV
// vec2 uv2 = transformUV(pixel.uv0, u_AlbedoTexture2Offset);
// #else // UV
// vec2 uv2 = vec2(0.0);
// #endif // UV
// vec4 tex2Color = texture2D(u_AlbedoTexture2, uv2);
// surfaceColor *= tex2Color;
// #endif
#ifdef RIMLIGHT
// 边缘光效果
vec3 viewDir = normalize(u_CameraPos - pixel.positionWS);
float rim = 1.0 - max(dot(viewDir, pixel.normalWS), 0.0);
rim = pow(rim, u_RimPower);
vec3 rimColor = u_RimColor.rgb * rim;
// 与最终颜色混合
surfaceColor.rgb += rimColor;
#endif
#ifdef FOG
surfaceColor.rgb = sceneLitFog(surfaceColor.rgb);
#endif // FOG
#ifdef INNEROUTLINE
vec3 viewDir2 = normalize(u_CameraPos - pixel.positionWS);
float d = dot(viewDir2, pixel.normalWS);
if(d <= u_outlineWidth){
float edgeFactor = 1.0 - smoothstep(u_outlineWidth - 0.1, u_outlineWidth, d);
surfaceColor = mix(surfaceColor, u_outlineColor, edgeFactor);
}
#endif
gl_FragColor = surfaceColor;
gl_FragColor = outputTransform(gl_FragColor);
}
#endGLSL
GLSL End这里是写的自定义shader,不知道怎么回事
{
type:Shader3D
name:slicePBR
enableInstancing:true,
supportReflectionProbe:true,
uniformMap:{
u_AlphaTestValue: { type: Float, default: 0.5, range: [0.0, 1.0] },
u_TilingOffset: { type: Vector4, default: [1, 1, 0, 0] },
u_AlbedoColor: { type: Color, default: [1, 1, 1, 1] },
u_AlbedoColorScale: { type: Float, default: 1.0 },
u_AlbedoTexture: { type: Texture2D, options: { define: "ALBEDOTEXTURE" } },
// u_AlbedoTexture2: { type: Texture2D, options: { define: "ALBEDOTEXTURE2" } },
// u_AlbedoTexture2Offset: { type: Vector4, default: [1, 1, 0, 0] },
u_RimColor: { type: Color, default: [1.0, 1.0, 1.0, 1.0] },
u_RimPower: { type: Float, default: 4.0, range: [0.0, 10.0] },
u_SliceTexture: { type: Texture2D, options: { define: "SliceTexture" } },
u_SliceProgress: { type: Float, default: 0., range: [0.0, 1.0] },
u_SliceRotation:{ type: Float, default: 0.0, range: [0.0, 360.0] },
u_outlineColor: { type: Color, default: [1.0, 1.0, 1.0, 1.0] },
u_outlineWidth: { type: Float, default: 0.0, range: [0.0, 1.0] },
u_NormalTexture: { type: Texture2D, options: { define: "NORMALTEXTURE" } },
u_NormalScale: { type: Float, default: 1.0, range: [0.0, 2.0] },
u_Metallic: { type: Float, default: 0.0, range: [0.0, 1.0] },
u_Smoothness: { type: Float, default: 0.0, range: [0.0, 1.0] },
u_MetallicGlossTexture: { type: Texture2D, options: { define: "METALLICGLOSSTEXTURE" } },
u_OcclusionTexture: { type: Texture2D, options: { define: "OCCLUSIONTEXTURE" } },
u_OcclusionStrength: { type: Float, default: 1.0 },
u_EmissionColor: { type: Color, default: [0, 0, 0, 0] },
u_EmissionIntensity: { type: Float, default: 1.0 },
u_EmissionTexture: { type: Texture2D, options: { define: "EMISSIONTEXTURE" } },
},
defines: {
EMISSION: { type: bool, default: false },
ENABLEVERTEXCOLOR: { type: bool, default: false },
RIMLIGHT: { type: bool, default: false },
SLICE: { type: bool, default: false },
INNEROUTLINE: { type: bool, default: false },
}
shaderPass:[
{
pipeline:Forward,
VS:LitVS,
FS:LitFS
}
]
}
Shader3D End
GLSL Start
#defineGLSL LitVS
#define SHADER_NAME slicePBR
#include "Math.glsl";
#include "Scene.glsl";
#include "SceneFogInput.glsl"
#include "Camera.glsl";
#include "Sprite3DVertex.glsl";
#include "VertexCommon.glsl";
#include "PBRVertex.glsl";
varying vec3 v_wPos;
void main()
{
Vertex vertex;
getVertexParams(vertex);
PixelParams pixel;
initPixelParams(pixel, vertex);
v_wPos = pixel.positionWS;
gl_Position = getPositionCS(pixel.positionWS);
gl_Position = remapPositionZ(gl_Position);
#ifdef FOG
FogHandle(gl_Position.z);
#endif // FOG
}
#endGLSL
#defineGLSL LitFS
#define SHADER_NAME slicePBR
#include "Color.glsl";
#include "Scene.glsl";
#include "SceneFog.glsl";
#include "Camera.glsl";
#include "Sprite3DFrag.glsl";
#include "PBRMetallicFrag.glsl";
varying vec3 v_wPos;
void initSurfaceInputs(inout SurfaceInputs inputs, inout PixelParams pixel)
{
inputs.alphaTest = u_AlphaTestValue;
#ifdef UV
vec2 uv = transformUV(pixel.uv0, u_TilingOffset);
#else // UV
vec2 uv = vec2(0.0);
#endif // UV
inputs.diffuseColor = u_AlbedoColor.rgb * u_AlbedoColorScale;
inputs.alpha = u_AlbedoColor.a;
#ifdef COLOR
#ifdef ENABLEVERTEXCOLOR
inputs.diffuseColor *= pixel.vertexColor.xyz;
inputs.alpha *= pixel.vertexColor.a;
#endif // ENABLEVERTEXCOLOR
#endif // COLOR
#ifdef ALBEDOTEXTURE
vec4 albedoSampler = texture2D(u_AlbedoTexture, uv);
#ifdef Gamma_u_AlbedoTexture
albedoSampler = gammaToLinear(albedoSampler);
#endif // Gamma_u_AlbedoTexture
inputs.diffuseColor *= albedoSampler.rgb;
inputs.alpha *= albedoSampler.a;
#endif // ALBEDOTEXTURE
inputs.normalTS = vec3(0.0, 0.0, 1.0);
#ifdef NORMALTEXTURE
vec3 normalSampler = texture2D(u_NormalTexture, uv).rgb;
normalSampler = normalize(normalSampler * 2.0 - 1.0);
normalSampler.y *= -1.0;
inputs.normalTS = normalScale(normalSampler, u_NormalScale);
#endif
inputs.metallic = u_Metallic;
inputs.smoothness = u_Smoothness;
#ifdef METALLICGLOSSTEXTURE
vec4 metallicSampler = texture2D(u_MetallicGlossTexture, uv);
inputs.metallic = metallicSampler.x;
inputs.smoothness = (metallicSampler.a * u_Smoothness);
#endif // METALLICGLOSSTEXTURE
inputs.occlusion = 1.0;
#ifdef OCCLUSIONTEXTURE
vec4 occlusionSampler = texture2D(u_OcclusionTexture, uv);
float occlusion = occlusionSampler.g;
inputs.occlusion = (1.0 - u_OcclusionStrength) + occlusion * u_OcclusionStrength;
#endif // OCCLUSIONTEXTURE
inputs.emissionColor = vec3(0.0);
#ifdef EMISSION
inputs.emissionColor = u_EmissionColor.rgb * u_EmissionIntensity;
#ifdef EMISSIONTEXTURE
vec4 emissionSampler = texture2D(u_EmissionTexture, uv);
#ifdef Gamma_u_EmissionTexture
emissionSampler = gammaToLinear(emissionSampler);
#endif // Gamma_u_EmissionTexture
inputs.emissionColor *= emissionSampler.rgb;
#endif // EMISSIONTEXTURE
#endif // EMISSION
}
vec2 rotateUV(vec2 uv, float degrees) {
float rad = radians(degrees);
// 将 uv 平移到中心
vec2 centered = uv - vec2(0.5);
// 计算旋转矩阵
float cosA = cos(rad);
float sinA = sin(rad);
mat2 rotation = mat2(
cosA, -sinA,
sinA, cosA
);
// 应用旋转
centered = rotation * centered;
// 移回 [0, 1] 空间
return centered + vec2(0.5);
}
void main()
{
//坐标平面剔除
// if(u_sliceObjForward.x != 0.0 || u_sliceObjForward.y != 0.0 || u_sliceObjForward.z != 0.0){
// vec3 toSliceDir = normalize(u_sliceObjWPos - v_wPos);
// float sliceDis = dot(u_sliceObjForward, toSliceDir);
// if(sliceDis < 0.0){
// discard;
// }
// }
PixelParams pixel;
getPixelParams(pixel);
//纹理剔除
#ifdef SLICE
#ifdef UV
vec2 uv = pixel.uv0;
#else // UV
vec2 uv = vec2(0.0);
#endif // UV
vec4 sliceSampler = texture2D(u_SliceTexture, rotateUV(uv,u_SliceRotation));
if(sliceSampler.x <= u_SliceProgress){
discard;
}
#endif
SurfaceInputs inputs;
initSurfaceInputs(inputs, pixel);
vec4 surfaceColor = PBR_Metallic_Flow(inputs, pixel);
// #ifdef ALBEDOTEXTURE2
// #ifdef UV
// vec2 uv2 = transformUV(pixel.uv0, u_AlbedoTexture2Offset);
// #else // UV
// vec2 uv2 = vec2(0.0);
// #endif // UV
// vec4 tex2Color = texture2D(u_AlbedoTexture2, uv2);
// surfaceColor *= tex2Color;
// #endif
#ifdef RIMLIGHT
// 边缘光效果
vec3 viewDir = normalize(u_CameraPos - pixel.positionWS);
float rim = 1.0 - max(dot(viewDir, pixel.normalWS), 0.0);
rim = pow(rim, u_RimPower);
vec3 rimColor = u_RimColor.rgb * rim;
// 与最终颜色混合
surfaceColor.rgb += rimColor;
#endif
#ifdef FOG
surfaceColor.rgb = sceneLitFog(surfaceColor.rgb);
#endif // FOG
#ifdef INNEROUTLINE
vec3 viewDir2 = normalize(u_CameraPos - pixel.positionWS);
float d = dot(viewDir2, pixel.normalWS);
if(d <= u_outlineWidth){
float edgeFactor = 1.0 - smoothstep(u_outlineWidth - 0.1, u_outlineWidth, d);
surfaceColor = mix(surfaceColor, u_outlineColor, edgeFactor);
}
#endif
gl_FragColor = surfaceColor;
gl_FragColor = outputTransform(gl_FragColor);
}
#endGLSL
GLSL End这里是写的自定义shader,不知道怎么回事
没有找到相关结果
已邀请:
要回复问题请先登录
2 个回复
LayaAir小牛
赞同来自: layabox
layabox
赞同来自: