[0]求助:水面流动shader一段时间后卡顿
一个水面流动的3d shader
在PC上正常!!!
在手机网页上、微信里面会逐渐变得卡顿(刚开始正常)
大约1分钟左右后就会变得越来越卡 ,流动跟PPT似的
面板的帧数、内存等都没变化
shader代码:
export default class WaterMaterial extends Laya.Material {
public readonly WATERTEX: number = Shader3D.propertyNameToID("u_WaterTex");
public readonly NORMALTEX: number = Shader3D.propertyNameToID("u_NormalTex");
constructor() {
super();
this.setShaderName("Water");
}
public static initShader() {
var vs: string = `
#include "Lighting.glsl";
attribute vec4 a_Pos;
attribute vec2 a_Coord;
uniform mat4 u_MvpMatrix;
varying vec2 v_Coord;
void main()
{
gl_Position = u_MvpMatrix * a_Pos;
v_Coord=a_Coord;
}`;
var ps: string = `
#ifdef HIGHPRECISION
precision mediump float;
#else
precision mediump float;
#endif
#include "Lighting.glsl";
uniform sampler2D u_WaterTex;
uniform sampler2D u_NormalTex;
uniform float u_Time;
varying vec2 v_Coord;
void main()
{
float speedx = u_Time*0.05;
vec2 tuv = v_Coord + vec2(speedx,0);
vec2 ouv = vec2(texture2D(u_NormalTex,tuv).r,0.6);
ouv-=0.5;
ouv *= 0.5;
vec4 col = texture2D(u_WaterTex,ouv+v_Coord);
gl_FragColor = col;
}
`;
var aMap: object =
{
"a_Pos": Laya.VertexMesh.MESH_POSITION0,
"a_Coord": Laya.VertexMesh.MESH_TEXTURECOORDINATE0,
};
var uMap: object =
{
'u_MvpMatrix': Shader3D.PERIOD_SPRITE,
'u_WaterTex': Shader3D.PERIOD_MATERIAL,
'u_NormalTex': Shader3D.PERIOD_MATERIAL,
}
var shader: Shader3D = Shader3D.add("Water", null, null, false,false);
var subShader: SubShader = new SubShader(aMap, uMap);
shader.addSubShader(subShader);
subShader.addShaderPass(vs, ps);
}
public set waterTex(value: BaseTexture) {
this._shaderValues.setTexture(this.WATERTEX, value);
}
public get waterTex() {
return this._shaderValues.getTexture(this.WATERTEX);
}
public set normalTex(value: BaseTexture) {
this._shaderValues.setTexture(this.NORMALTEX, value);
}
public get normalTex() {
return this._shaderValues.getTexture(this.NORMALTEX);
}
}
在PC上正常!!!
在手机网页上、微信里面会逐渐变得卡顿(刚开始正常)
大约1分钟左右后就会变得越来越卡 ,流动跟PPT似的
面板的帧数、内存等都没变化
shader代码:
export default class WaterMaterial extends Laya.Material {
public readonly WATERTEX: number = Shader3D.propertyNameToID("u_WaterTex");
public readonly NORMALTEX: number = Shader3D.propertyNameToID("u_NormalTex");
constructor() {
super();
this.setShaderName("Water");
}
public static initShader() {
var vs: string = `
#include "Lighting.glsl";
attribute vec4 a_Pos;
attribute vec2 a_Coord;
uniform mat4 u_MvpMatrix;
varying vec2 v_Coord;
void main()
{
gl_Position = u_MvpMatrix * a_Pos;
v_Coord=a_Coord;
}`;
var ps: string = `
#ifdef HIGHPRECISION
precision mediump float;
#else
precision mediump float;
#endif
#include "Lighting.glsl";
uniform sampler2D u_WaterTex;
uniform sampler2D u_NormalTex;
uniform float u_Time;
varying vec2 v_Coord;
void main()
{
float speedx = u_Time*0.05;
vec2 tuv = v_Coord + vec2(speedx,0);
vec2 ouv = vec2(texture2D(u_NormalTex,tuv).r,0.6);
ouv-=0.5;
ouv *= 0.5;
vec4 col = texture2D(u_WaterTex,ouv+v_Coord);
gl_FragColor = col;
}
`;
var aMap: object =
{
"a_Pos": Laya.VertexMesh.MESH_POSITION0,
"a_Coord": Laya.VertexMesh.MESH_TEXTURECOORDINATE0,
};
var uMap: object =
{
'u_MvpMatrix': Shader3D.PERIOD_SPRITE,
'u_WaterTex': Shader3D.PERIOD_MATERIAL,
'u_NormalTex': Shader3D.PERIOD_MATERIAL,
}
var shader: Shader3D = Shader3D.add("Water", null, null, false,false);
var subShader: SubShader = new SubShader(aMap, uMap);
shader.addSubShader(subShader);
subShader.addShaderPass(vs, ps);
}
public set waterTex(value: BaseTexture) {
this._shaderValues.setTexture(this.WATERTEX, value);
}
public get waterTex() {
return this._shaderValues.getTexture(this.WATERTEX);
}
public set normalTex(value: BaseTexture) {
this._shaderValues.setTexture(this.NORMALTEX, value);
}
public get normalTex() {
return this._shaderValues.getTexture(this.NORMALTEX);
}
}
没有找到相关结果
已邀请:
要回复问题请先登录
1 个回复
Laya_z
赞同来自: minigame 、Carson
#if defined(GL_FRAGMENT_PRECISION_HIGH)// 原来的写法会被我们自己的解析流程处理,而我们的解析是不认内置宏的,导致被删掉,所以改成 if defined 了
precision highp float;
precision highp int;
#else
precision mediump float;
precision mediump int;
#endif