Commit 1e9dd75d authored by wjf's avatar wjf

2.0.40

parent 8ffe35a0
declare namespace FYGE{export const VERSION = "2.0.39";
declare namespace FYGE{export const VERSION = "2.0.40";
export const osType: "ios" | "android" | "pc";
......@@ -9709,7 +9709,11 @@ export enum UniformType {
/**
* m3对象
*/
matrix3 = "m3"
matrix3 = "m3",
/**
* 其他类型,不转换,直接赋值
*/
any = "any"
}
export class Sprite3dMaterial extends ShaderMaterial {
......
This diff is collapsed.
This diff is collapsed.
export const VERSION = "2.0.39";
export const VERSION = "2.0.40";
export const osType: "ios" | "android" | "pc";
......@@ -9709,7 +9709,11 @@ export enum UniformType {
/**
* m3对象
*/
matrix3 = "m3"
matrix3 = "m3",
/**
* 其他类型,不转换,直接赋值
*/
any = "any"
}
export class Sprite3dMaterial extends ShaderMaterial {
......
{
"name": "fyge",
"version": "2.0.39",
"version": "2.0.40",
"description": "canvas渲染引擎",
"main": "./build/fyge.min.js",
"types": "./build/types.d.ts",
......
......@@ -447,8 +447,11 @@
D3Renderer的flush方法里mat.map和mat.envMap添加判断valid
getCusShader的useMap和useEnvMap添加判断valid
2.0.40 为了解决透明像素裁切导致uv获取到图集内其他区域的像素(暂时传值,后续考虑宏定义区分着色器)
D3Renderer的flush方法里mat.map里新传了uFrameUvs
getCusShader的片元着色器新增uniform量uFrameUvs,在获取纹理uMap之后多计算一步(是否在texture的frame内)
ShaderMaterial文件里UniformType新增any类型
Sprite3dMaterial添加uFrameUvs,涉及片元着色器,uniforms字段,map的set方法需要多处理uFrameUvs
外层canvas标签的transform数据在获取鼠标坐标时并未考虑,比如旋转
......
......@@ -7,7 +7,7 @@
* @name VERSION
* @type {string}
*/
export const VERSION = "2.0.39";
export const VERSION = "2.0.40";
/**
......
......@@ -223,6 +223,9 @@ export class D3Renderer extends ObjectRenderer {
map.transform.update();
//赋值偏移
uniforms["uUvTransform"] = map.transform.mapCoord.toArray(true);
//对于透明像素有裁切的
const { x0, y0, x2, y2 } = map._uvs;
uniforms["uFrameUvs"] = [x0, y0, x2, y2];
}
//是否带环境贴图
if (mat.envMap && mat.envMap.valid) {//环境贴图先不考虑图集的情况,一般一张大jpg
......
......@@ -121,4 +121,8 @@ export enum UniformType {
* m3对象
*/
matrix3 = "m3",
/**
* 其他类型,不转换,直接赋值
*/
any = "any"
}
\ No newline at end of file
......@@ -50,9 +50,12 @@ const sprite3dFragmentShader =
uniform vec3 color;
uniform float alpha;
uniform sampler2D map;
uniform vec4 uFrameUvs;
varying vec2 vTextureCoord;
void main() {
vec4 mapColor = texture2D( map, vTextureCoord );
vec2 s = step(vec2(uFrameUvs.x,uFrameUvs.y),vTextureCoord) - step(vec2(uFrameUvs.z,uFrameUvs.w),vTextureCoord);
mapColor *= abs(s.x * s.y);
gl_FragColor = vec4( color*alpha, alpha )*mapColor;
}`;
......@@ -66,6 +69,7 @@ export class Sprite3dMaterial extends ShaderMaterial {
alpha: { type: UniformType.float, value: 1.0 },
map: { type: UniformType.texture, value: Texture.WHITE },
uvTransform: { type: UniformType.matrix3, value: new Matrix() },
uFrameUvs: { type: UniformType.any, value: [0, 0, 1, 1] },
});
this._instanceType = "Sprite3dMaterial";
}
......@@ -118,5 +122,8 @@ export class Sprite3dMaterial extends ShaderMaterial {
v.transform.update();
//赋值偏移
(this.uniforms.uvTransform.value as Matrix).copy(v.transform.mapCoord);
//对于透明像素有裁切的
const { x0, y0, x2, y2 } = v._uvs;
this.uniforms.uFrameUvs.value = [x0, y0, x2, y2];
}
}
\ No newline at end of file
......@@ -466,6 +466,7 @@ const FRAG = [
"uniform float uMatAlpha;", //材质上的透明度
"#ifdef USE_MAP",
' uniform sampler2D uMap;',//纹理
" uniform vec4 uFrameUvs;",//为了trim的纹理需要多传一个,为了判断边缘透明
" varying vec2 vTextureCoord;",//传到着色器的纹理坐标
"#endif",
......@@ -602,6 +603,9 @@ const FRAG = [
" #ifdef USE_MAP",
" vec4 mapColor = texture2D( uMap, vTextureCoord );",
" color *= mapColor;",
" vec2 s = step(vec2(uFrameUvs.x,uFrameUvs.y),vTextureCoord) - step(vec2(uFrameUvs.z,uFrameUvs.w),vTextureCoord);",
// " vec2 s = step(vec2(0.6669921875,0.4111328125),vTextureCoord) - step(vec2(0.951171875,0.65625),vTextureCoord);",
" color *= abs(s.x * s.y);",
" #endif",
//计算顶点颜色
" #ifdef USE_VERTEXCOLOR",
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment