mirror of
https://github.com/cocos/cocos4.git
synced 2026-12-01 07:42:38 +08:00
add tonemap flow
This commit is contained in:
@@ -141,7 +141,10 @@ export class Material extends Asset {
|
||||
success = true;
|
||||
}
|
||||
}
|
||||
if (!success) { console.warn(`illegal property name: ${name}.`); return; }
|
||||
if (!success) {
|
||||
console.warn(`illegal property name: ${name}.`);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
public getProperty (name: string, passIdx?: number) {
|
||||
|
||||
Vendored
+37
-12
@@ -1,13 +1,13 @@
|
||||
// absolute essential effects
|
||||
export default [
|
||||
{
|
||||
"name": "builtin-effect-particle",
|
||||
"name": "builtin-particle",
|
||||
"techniques": [
|
||||
{"name":"add", "passes":[{"rasterizerState":{"cullMode":0}, "depthStencilState":{"depthTest":true, "depthWrite":false}, "blendState":{"targets":[{"blend":true, "blendSrc":2, "blendDst":8, "blendSrcAlpha":2, "blendDstAlpha":8}]}, "program":"builtin-effect-particle|particle-vs-legacy:lpvs_main|tinted-fs:add", "properties":{"mainTexture":{"type":29, "value":"grey"}, "mainTiling":{"type":14, "value":[1, 1]}, "mainOffset":{"type":14, "value":[0, 0]}, "frameTile":{"type":14, "value":[1, 1]}, "velocityScale":{"type":13, "value":[0]}, "lengthScale":{"type":13, "value":[0]}, "tintColor":{"type":17, "value":[0.5, 0.5, 0.5, 0.5]}}}]}
|
||||
{"name":"add", "passes":[{"rasterizerState":{"cullMode":0}, "depthStencilState":{"depthTest":true, "depthWrite":false}, "blendState":{"targets":[{"blend":true, "blendSrc":2, "blendDst":8, "blendSrcAlpha":2, "blendDstAlpha":8}]}, "program":"builtin-particle|particle-vs-legacy:lpvs_main|tinted-fs:add", "properties":{"mainTexture":{"type":29, "value":"grey"}, "mainTiling":{"type":14, "value":[1, 1]}, "mainOffset":{"type":14, "value":[0, 0]}, "frameTile":{"type":14, "value":[1, 1]}, "velocityScale":{"type":13, "value":[0]}, "lengthScale":{"type":13, "value":[0]}, "tintColor":{"type":17, "value":[0.5, 0.5, 0.5, 0.5]}}}]}
|
||||
],
|
||||
"shaders": [
|
||||
{
|
||||
"name": "builtin-effect-particle|particle-vs-legacy:lpvs_main|tinted-fs:add",
|
||||
"name": "builtin-particle|particle-vs-legacy:lpvs_main|tinted-fs:add",
|
||||
"glsl3": {
|
||||
"vert": `precision mediump float;\nuniform Constants {\n vec2 frameTile;\n vec2 mainTiling;\n vec2 mainOffset;\n float velocityScale;\n float lengthScale;\n};\nuniform CCGlobal {\n \n vec4 cc_time; \n vec4 cc_screenSize; \n vec4 cc_screenScale; \n \n mat4 cc_matView;\n mat4 cc_matViewInv;\n mat4 cc_matProj;\n mat4 cc_matProjInv;\n mat4 cc_matViewProj;\n mat4 cc_matViewProjInv;\n vec4 cc_cameraPos; \n};\nuniform CCLocal {\n mat4 cc_matWorld;\n mat4 cc_matWorldIT;\n};\nout vec2 uv;\nout vec4 color;\nvoid computeVertPos(inout vec4 pos, vec2 vertOffset\n#if USE_BILLBOARD || USE_VERTICAL_BILLBOARD\n , mat4 view\n#endif\n#if USE_STRETCHED_BILLBOARD\n , vec3 eye\n , vec4 velocity\n , float velocityScale\n , float lengthScale\n , float size\n , float xIndex\n#endif\n) {\n#if USE_BILLBOARD\n vec3 camRight = normalize(vec3(view[0][0], view[1][0], view[2][0]));\n vec3 camUp = normalize(vec3(view[0][1], view[1][1], view[2][1]));\n pos.xyz += (camRight * vertOffset.x) + (camUp * vertOffset.y);\n#elif USE_STRETCHED_BILLBOARD\n vec3 camRight = normalize(cross(pos.xyz - eye, velocity.xyz));\n vec3 camUp = velocity.xyz * velocityScale + normalize(velocity.xyz) * lengthScale * size;\n pos.xyz += (camRight * abs(vertOffset.x) * sign(vertOffset.y)) - camUp * xIndex;\n#elif USE_HORIZONTAL_BILLBOARD\n vec3 camRight = vec3(1, 0, 0);\n vec3 camUp = vec3(0, 0, -1);\n pos.xyz += (camRight * vertOffset.x) + (camUp * vertOffset.y);\n#elif USE_VERTICAL_BILLBOARD\n vec3 camRight = normalize(vec3(view[0][0], view[1][0], view[2][0]));\n vec3 camUp = vec3(0, 1, 0);\n pos.xyz += (camRight * vertOffset.x) + (camUp * vertOffset.y);\n#else\n pos.x += vertOffset.x;\n pos.y += vertOffset.y;\n#endif\n}\nvec2 computeUV(float frameIndex, vec2 vertIndex, vec2 frameTile) {\n vec2 aniUV = vec2(0, floor(frameIndex * frameTile.y));\n aniUV.x = floor(frameIndex * frameTile.x * frameTile.y - aniUV.y * frameTile.x);\n \n vertIndex.x = 1. - vertIndex.x;\n return (aniUV.xy + vertIndex) / vec2(frameTile.x, frameTile.y);\n}\nvoid rotateCorner(inout vec2 corner, float angle) {\n float xOS = cos(angle) * corner.x - sin(angle) * corner.y;\n float yOS = sin(angle) * corner.x + cos(angle) * corner.y;\n corner.x = xOS;\n corner.y = yOS;\n}\nin vec3 a_position; \nin vec3 a_texCoord; \nin vec2 a_texCoord1; \nin vec4 a_color;\n#if USE_STRETCHED_BILLBOARD\nin vec3 a_color1; \n#endif\nvec4 lpvs_main() {\n vec4 pos = vec4(a_position, 1);\n#if USE_STRETCHED_BILLBOARD\n vec4 velocity = vec4(a_color1.xyz, 0);\n#endif\n#if !USE_WORLD_SPACE\n pos = cc_matWorld * pos;\n #if USE_STRETCHED_BILLBOARD\n velocity = cc_matWorld * velocity;\n #endif\n#endif\n vec2 cornerOffset = vec2((a_texCoord.xy - 0.5) * a_texCoord1.x);\n#if !USE_STRETCHED_BILLBOARD\n \n rotateCorner(cornerOffset, a_texCoord1.y);\n#endif\n computeVertPos(pos, cornerOffset\n #if USE_BILLBOARD || USE_VERTICAL_BILLBOARD\n , cc_matView\n #endif\n #if USE_STRETCHED_BILLBOARD\n , cc_cameraPos.xyz\n , velocity\n , velocityScale\n , lengthScale\n , a_texCoord1.x\n , a_texCoord.x\n #endif\n );\n pos = cc_matViewProj * pos;\n uv = computeUV(a_texCoord.z, a_texCoord.xy, frameTile) * mainTiling + mainOffset;\n color = a_color;\n return pos;\n}\nvoid main() { gl_Position = lpvs_main(); }\n`,
|
||||
"frag": `\n precision mediump float;\n in vec2 uv;\n in vec4 color;\n uniform sampler2D mainTexture;\n uniform FragConstants {\n vec4 tintColor;\n };\n vec4 add () {\n return 2.0 * color * tintColor * texture(mainTexture, uv);\n }\n vec4 multiply () {\n vec4 col;\n vec4 texColor = texture(mainTexture, uv);\n col.rgb = tintColor.rgb * texColor.rgb * color.rgb * vec3(2.0);\n col.a = (1.0 - texColor.a) * (tintColor.a * color.a * 2.0);\n return col;\n }\nout vec4 cc_FragColor;\nvoid main() { cc_FragColor = add(); }\n`
|
||||
@@ -43,13 +43,13 @@ export default [
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "builtin-effect-skybox",
|
||||
"name": "builtin-skybox",
|
||||
"techniques": [
|
||||
{"passes":[{"rasterizerState":{"cullMode":0}, "depthStencilState":{"depthTest":true, "depthWrite":false}, "program":"builtin-effect-skybox|sky-vs:vert|sky-fs:frag", "properties":{"cubeMap":{"type":32, "value":"default-cube"}}, "priority":10}]}
|
||||
{"passes":[{"rasterizerState":{"cullMode":0}, "depthStencilState":{"depthTest":true, "depthWrite":false}, "program":"builtin-skybox|sky-vs:vert|sky-fs:frag", "properties":{"cubeMap":{"type":32, "value":"default-cube"}}, "priority":10}]}
|
||||
],
|
||||
"shaders": [
|
||||
{
|
||||
"name": "builtin-effect-skybox|sky-vs:vert|sky-fs:frag",
|
||||
"name": "builtin-skybox|sky-vs:vert|sky-fs:frag",
|
||||
"glsl3": {
|
||||
"vert": `\n precision mediump float;\n in vec3 a_position;\n \nuniform CCGlobal {\n \n vec4 cc_time; \n vec4 cc_screenSize; \n vec4 cc_screenScale; \n \n mat4 cc_matView;\n mat4 cc_matViewInv;\n mat4 cc_matProj;\n mat4 cc_matProjInv;\n mat4 cc_matViewProj;\n mat4 cc_matViewProjInv;\n vec4 cc_cameraPos; \n};\n out vec3 viewDir;\n vec4 vert () {\n mat4 matViewRotOnly = mat4(mat3(cc_matView));\n vec4 clipPos = cc_matProj * matViewRotOnly * vec4(a_position, 1.0);\n viewDir = a_position;\n vec4 pos = clipPos;\n pos.z = clipPos.w * 0.99999;\n return pos;\n }\nvoid main() { gl_Position = vert(); }\n`,
|
||||
"frag": `\n precision mediump float;\n in vec3 viewDir;\n uniform samplerCube cubeMap;\n \nvec3 gammaToLinearSpaceRGB(vec3 sRGB) { \n return sRGB * (sRGB * (sRGB * 0.305306011 + 0.682171111) + 0.012522878);\n}\nvec3 linearToGammaSpaceRGB(vec3 RGB) { \n vec3 S1 = sqrt(RGB);\n vec3 S2 = sqrt(S1);\n vec3 S3 = sqrt(S2);\n return 0.585122381 * S1 + 0.783140355 * S2 - 0.368262736 * S3;\n}\nvec4 gammaToLinearSpaceRGBA(vec4 sRGBA) {\n return vec4(gammaToLinearSpaceRGB(sRGBA.rgb), sRGBA.a);\n}\nvec4 linearToGammaSpaceRGBA(vec4 RGBA) {\n return vec4(linearToGammaSpaceRGB(RGBA.rgb), RGBA.a);\n}\nfloat gammaToLinearSpaceExact(float val) {\n if (val <= 0.04045) {\n return val / 12.92;\n } else if (val < 1.0) {\n return pow((val + 0.055) / 1.055, 2.4);\n } else {\n return pow(val, 2.2);\n }\n}\nfloat linearToGammaSpaceExact(float val) {\n if (val <= 0.0) {\n return 0.0;\n } else if (val <= 0.0031308) {\n return 12.92 * val;\n } else if (val < 1.0) {\n return 1.055 * pow(val, 0.4166667) - 0.055;\n } else {\n return pow(val, 0.45454545);\n }\n}\n \nvec3 unpackNormal(vec4 nmap) {\n return nmap.xyz * 2.0 - 1.0;\n}\nvec3 unpackRGBE(vec4 rgbe) {\n return rgbe.rgb * pow(2.0, rgbe.a * 255.0 - 128.0);\n}\n vec4 frag () {\n #if USE_RGBE_CUBEMAP\n vec3 c = unpackRGBE(texture(cubeMap, viewDir));\n c = linearToGammaSpaceRGB(c / (1.0 + c));\n return vec4(c, 1.0);\n #else\n return texture(cubeMap, viewDir);\n #endif\n }\nout vec4 cc_FragColor;\nvoid main() { cc_FragColor = frag(); }\n`
|
||||
@@ -70,13 +70,13 @@ export default [
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "builtin-effect-sprite",
|
||||
"name": "builtin-sprite",
|
||||
"techniques": [
|
||||
{"passes":[{"depthStencilState":{"depthTest":true, "depthWrite":false}, "blendState":{"targets":[{"blend":true, "blendSrc":2, "blendDst":4, "blendDstAlpha":4}]}, "program":"builtin-effect-sprite|sprite-vs:vert|sprite-fs:frag", "properties":{"mainTexture":{"type":29, "value":"white"}}}]}
|
||||
{"passes":[{"depthStencilState":{"depthTest":true, "depthWrite":false}, "blendState":{"targets":[{"blend":true, "blendSrc":2, "blendDst":4, "blendDstAlpha":4}]}, "program":"builtin-sprite|sprite-vs:vert|sprite-fs:frag", "properties":{"mainTexture":{"type":29, "value":"white"}}}]}
|
||||
],
|
||||
"shaders": [
|
||||
{
|
||||
"name": "builtin-effect-sprite|sprite-vs:vert|sprite-fs:frag",
|
||||
"name": "builtin-sprite|sprite-vs:vert|sprite-fs:frag",
|
||||
"glsl3": {
|
||||
"vert": `\n precision mediump float;\n \nuniform CCGlobal {\n \n vec4 cc_time; \n vec4 cc_screenSize; \n vec4 cc_screenScale; \n \n mat4 cc_matView;\n mat4 cc_matViewInv;\n mat4 cc_matProj;\n mat4 cc_matProjInv;\n mat4 cc_matViewProj;\n mat4 cc_matViewProjInv;\n vec4 cc_cameraPos; \n};\n in vec3 a_position;\n in vec2 a_texCoord;\n in vec4 a_color;\n out vec2 uv0;\n out vec4 color;\n vec4 vert () {\n vec4 pos = vec4(a_position, 1);\n pos = cc_matViewProj * pos;\n uv0 = a_texCoord;\n color = a_color;\n return pos;\n }\nvoid main() { gl_Position = vert(); }\n`,
|
||||
"frag": `\n precision mediump float;\n in vec2 uv0;\n in vec4 color;\n uniform sampler2D mainTexture;\n vec4 frag () {\n vec4 o = vec4(1, 1, 1, 1);\n o *= texture(mainTexture, uv0);\n o *= color;\n return o;\n }\nout vec4 cc_FragColor;\nvoid main() { cc_FragColor = frag(); }\n`
|
||||
@@ -95,13 +95,38 @@ export default [
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "builtin-effect-unlit",
|
||||
"name": "builtin-tonemap",
|
||||
"techniques": [
|
||||
{"name":"opaque", "passes":[{"program":"builtin-effect-unlit|unlit-vs:vert|unlit-fs:frag", "properties":{"color":{"type":17, "value":[1, 1, 1, 1]}, "tilingOffset":{"type":16, "value":[1, 1, 0, 0]}, "mainTexture":{"type":29, "value":"grey"}}}]}
|
||||
{"name":"tonemap", "passes":[{"depthStencilState":{"depthTest":false, "depthWrite":false}, "program":"builtin-tonemap|tonemap-vs:vert|tonemap-fs:frag", "properties":{"u_texSampler":{"type":29, "sampler":{"minFilter":2, "magFilter":2, "mipFilter":0}}}}]}
|
||||
],
|
||||
"shaders": [
|
||||
{
|
||||
"name": "builtin-effect-unlit|unlit-vs:vert|unlit-fs:frag",
|
||||
"name": "builtin-tonemap|tonemap-vs:vert|tonemap-fs:frag",
|
||||
"glsl3": {
|
||||
"vert": `\n precision mediump float;\n \n#define PI 3.14159265359\n#define PI2 6.28318530718\n#define EPSILON 1e-6\n#define LOG2 1.442695\n#define saturate(a) clamp( a, 0.0, 1.0 )\nvec2 ScreenSpaceTexCoord(vec2 pos) {\n return pos * 0.5 + 0.5;\n}\n \nuniform CCGlobal {\n \n vec4 cc_time; \n vec4 cc_screenSize; \n vec4 cc_screenScale; \n \n mat4 cc_matView;\n mat4 cc_matViewInv;\n mat4 cc_matProj;\n mat4 cc_matProjInv;\n mat4 cc_matViewProj;\n mat4 cc_matViewProjInv;\n vec4 cc_cameraPos; \n};\n in vec2 a_position;\n in vec2 a_texCoord;\n out vec2 v_uv;\n vec4 vert () {\n vec4 pos = vec4(a_position, 0, 1);\n v_uv = a_texCoord * cc_screenScale.xy;\n return pos;\n }\nvoid main() { gl_Position = vert(); }\n`,
|
||||
"frag": `\n precision mediump float;\n in vec2 v_uv;\n uniform sampler2D u_texSampler;\n vec4 frag () {\n vec4 o = texture(u_texSampler, v_uv);\n return o;\n }\nout vec4 cc_FragColor;\nvoid main() { cc_FragColor = frag(); }\n`
|
||||
},
|
||||
"glsl1": {
|
||||
"vert": `\n precision mediump float;\n \n#define PI 3.14159265359\n#define PI2 6.28318530718\n#define EPSILON 1e-6\n#define LOG2 1.442695\n#define saturate(a) clamp( a, 0.0, 1.0 )\nvec2 ScreenSpaceTexCoord(vec2 pos) {\n return pos * 0.5 + 0.5;\n}\n \n uniform vec4 cc_time;\n uniform vec4 cc_screenSize;\n uniform vec4 cc_screenScale;\n uniform mat4 cc_matView;\n uniform mat4 cc_matViewInv;\n uniform mat4 cc_matProj;\n uniform mat4 cc_matProjInv;\n uniform mat4 cc_matViewProj;\n uniform mat4 cc_matViewProjInv;\n uniform vec4 cc_cameraPos;\n attribute vec2 a_position;\n attribute vec2 a_texCoord;\n varying vec2 v_uv;\n vec4 vert () {\n vec4 pos = vec4(a_position, 0, 1);\n v_uv = a_texCoord * cc_screenScale.xy;\n return pos;\n }\nvoid main() { gl_Position = vert(); }\n`,
|
||||
"frag": `\n precision mediump float;\n varying vec2 v_uv;\n uniform sampler2D u_texSampler;\n vec4 frag () {\n vec4 o = texture2D(u_texSampler, v_uv);\n return o;\n }\nvoid main() { gl_FragColor = frag(); }\n`
|
||||
},
|
||||
"defines": [],
|
||||
"blocks": [],
|
||||
"samplers": [
|
||||
{"name":"u_texSampler", "type":29, "count":1, "defines":[], "binding":0}
|
||||
],
|
||||
"dependencies": {}
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "builtin-unlit",
|
||||
"techniques": [
|
||||
{"name":"opaque", "passes":[{"program":"builtin-unlit|unlit-vs:vert|unlit-fs:frag", "properties":{"color":{"type":17, "value":[1, 1, 1, 1]}, "tilingOffset":{"type":16, "value":[1, 1, 0, 0]}, "mainTexture":{"type":29, "value":"grey"}}}]}
|
||||
],
|
||||
"shaders": [
|
||||
{
|
||||
"name": "builtin-unlit|unlit-vs:vert|unlit-fs:frag",
|
||||
"glsl3": {
|
||||
"vert": `\n precision mediump float;\n \nuniform CCGlobal {\n \n vec4 cc_time; \n vec4 cc_screenSize; \n vec4 cc_screenScale; \n \n mat4 cc_matView;\n mat4 cc_matViewInv;\n mat4 cc_matProj;\n mat4 cc_matProjInv;\n mat4 cc_matViewProj;\n mat4 cc_matViewProjInv;\n vec4 cc_cameraPos; \n};\n \nuniform CCLocal {\n mat4 cc_matWorld;\n mat4 cc_matWorldIT;\n};\n #if CC_USE_SKINNING\n \nin vec4 a_weights;\nin vec4 a_joints;\nuniform CCSkinning {\n mat4 cc_matJoint[128];\n vec4 cc_jointsTextureSize;\n};\n#if CC_USE_JOINTS_TEXTURE\nuniform sampler2D cc_jointsTexture;\nmat4 getBoneMatrix(const in float i) {\n float size = cc_jointsTextureSize.x;\n float j = i * 4.0;\n float x = mod(j, size);\n float y = floor(j / size);\n float dx = 1.0 / size;\n float dy = 1.0 / size;\n y = dy * (y + 0.5);\n vec4 v1 = texture(cc_jointsTexture, vec2(dx * (x + 0.5), y));\n vec4 v2 = texture(cc_jointsTexture, vec2(dx * (x + 1.5), y));\n vec4 v3 = texture(cc_jointsTexture, vec2(dx * (x + 2.5), y));\n vec4 v4 = texture(cc_jointsTexture, vec2(dx * (x + 3.5), y));\n return mat4(v1, v2, v3, v4);\n}\n#else\nmat4 getBoneMatrix(const in float i) {\n return cc_matJoint[int(i)];\n}\n#endif\nmat4 skinMatrix() {\n return\n getBoneMatrix(a_joints.x) * a_weights.x +\n getBoneMatrix(a_joints.y) * a_weights.y +\n getBoneMatrix(a_joints.z) * a_weights.z +\n getBoneMatrix(a_joints.w) * a_weights.w;\n}\nvoid skinVertex(inout vec4 a1) {\n mat4 m = skinMatrix();\n a1 = m * a1;\n}\nvoid skinVertex(inout vec4 a1, inout vec4 a2) {\n mat4 m = skinMatrix();\n a1 = m * a1;\n a2 = m * a2;\n}\nvoid skinVertex(inout vec4 a1, inout vec4 a2, inout vec4 a3) {\n mat4 m = skinMatrix();\n a1 = m * a1;\n a2 = m * a2;\n a3 = m * a3;\n}\n #endif\n in vec3 a_position;\n #if USE_TEXTURE\n in vec2 a_texCoord;\n out vec2 uv0;\n uniform TexCoords {\n vec4 tilingOffset;\n };\n #endif\n vec4 vert () {\n vec4 pos = vec4(a_position, 1);\n #if CC_USE_SKINNING\n skinVertex(pos);\n #endif\n pos = cc_matViewProj * cc_matWorld * pos;\n #if USE_TEXTURE\n uv0 = a_texCoord * tilingOffset.xy + tilingOffset.zw;\n #endif\n return pos;\n }\nvoid main() { gl_Position = vert(); }\n`,
|
||||
"frag": `\n precision mediump float;\n #if USE_TEXTURE\n in vec2 uv0;\n uniform sampler2D mainTexture;\n #endif\n #if USE_COLOR\n uniform Constant {\n vec4 color;\n };\n #endif\n vec4 frag () {\n vec4 o = vec4(1, 1, 1, 1);\n #if USE_TEXTURE\n o *= texture(mainTexture, uv0);\n #endif\n #if USE_COLOR\n o *= color;\n #endif\n return o;\n }\nout vec4 cc_FragColor;\nvoid main() { cc_FragColor = frag(); }\n`
|
||||
|
||||
@@ -131,7 +131,7 @@ class BuiltinResMgr {
|
||||
defaultMtl._uuid = 'default-material';
|
||||
defaultMtl.initialize({
|
||||
defines: { USE_COLOR: true },
|
||||
effectName: 'builtin-effect-unlit',
|
||||
effectName: 'builtin-unlit',
|
||||
});
|
||||
defaultMtl.setProperty('color', cc.color('#FF00FF'));
|
||||
resources[defaultMtl._uuid] = defaultMtl;
|
||||
@@ -139,14 +139,14 @@ class BuiltinResMgr {
|
||||
// sprite material
|
||||
const spriteMtl = new cc.Material();
|
||||
spriteMtl._uuid = 'sprite-material';
|
||||
spriteMtl.initialize({ effectName: 'builtin-effect-sprite' });
|
||||
spriteMtl.initialize({ effectName: 'builtin-sprite' });
|
||||
spriteMtl.setProperty('mainTexture', defaultTexture);
|
||||
resources[spriteMtl._uuid] = spriteMtl;
|
||||
|
||||
// default particle material
|
||||
const defaultParticleMtl = new cc.Material();
|
||||
defaultParticleMtl._uuid = 'default-particle-material';
|
||||
defaultParticleMtl.initialize({ effectName: 'builtin-effect-particle-add' });
|
||||
defaultParticleMtl.initialize({ effectName: 'builtin-particle-add' });
|
||||
resources[defaultParticleMtl._uuid] = defaultParticleMtl;
|
||||
}
|
||||
|
||||
|
||||
+3
-1
@@ -775,8 +775,10 @@ var game = {
|
||||
}
|
||||
|
||||
this._gfxDevice.initialize({
|
||||
canvasElm : localCanvas,
|
||||
canvasElm: localCanvas,
|
||||
debug: true,
|
||||
nativeWidth: screen.width,
|
||||
nativeHeight: screen.height,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
+1
-2
@@ -87,13 +87,12 @@ export class Root {
|
||||
this._curWindow = this._mainWindow;
|
||||
|
||||
let pipeline: RenderPipeline = new ForwardPipeline(this);
|
||||
this._pipeline = pipeline;
|
||||
if (!pipeline.initialize()) {
|
||||
this.destroy();
|
||||
return false;
|
||||
}
|
||||
|
||||
this._pipeline = pipeline;
|
||||
|
||||
this.registerRenderPipeline('forward', pipeline);
|
||||
pipeline = new UIPipeline(this);
|
||||
if (!pipeline.initialize()) {
|
||||
|
||||
@@ -34,6 +34,8 @@ export interface IGFXDeviceInfo {
|
||||
isAntialias?: boolean;
|
||||
isPremultipliedAlpha?: boolean;
|
||||
debug?: boolean;
|
||||
nativeWidth?: number;
|
||||
nativeHeight?: number;
|
||||
}
|
||||
|
||||
// tslint:disable: max-line-length
|
||||
@@ -63,6 +65,14 @@ export abstract class GFXDevice {
|
||||
return this._height;
|
||||
}
|
||||
|
||||
public get nativeWidth (): number {
|
||||
return this._nativeWidth;
|
||||
}
|
||||
|
||||
public get nativeHeight (): number {
|
||||
return this._nativeHeight;
|
||||
}
|
||||
|
||||
public get mainWindow (): GFXWindow {
|
||||
return this._mainWindow as GFXWindow;
|
||||
}
|
||||
@@ -138,6 +148,8 @@ export abstract class GFXDevice {
|
||||
protected _queue: GFXQueue | null = null;
|
||||
protected _width: number = 0;
|
||||
protected _height: number = 0;
|
||||
protected _nativeWidth: number = 0;
|
||||
protected _nativeHeight: number = 0;
|
||||
protected _mainWindow: GFXWindow | null = null;
|
||||
protected _cmdAllocator: GFXCommandAllocator | null = null;
|
||||
protected _maxVertexAttributes: number = 0;
|
||||
|
||||
@@ -256,9 +256,9 @@ export class WebGLGFXDevice extends GFXDevice {
|
||||
console.info('VENDOR: ' + this._vendor);
|
||||
console.info('VERSION: ' + this._version);
|
||||
console.info('SCREEN_SIZE: ' + this._width + ' x ' + this._height);
|
||||
console.info('COLOR_FORMAT: ' + GFXFormatInfos[this._colorFmt].name);
|
||||
console.info('DEPTH_STENCIL_FORMAT: ' + GFXFormatInfos[this._depthStencilFmt].name);
|
||||
|
||||
console.info('NATIVE_SIZE: ' + this._nativeWidth + ' x ' + this._nativeHeight);
|
||||
// console.info('COLOR_FORMAT: ' + GFXFormatInfos[this._colorFmt].name);
|
||||
// console.info('DEPTH_STENCIL_FORMAT: ' + GFXFormatInfos[this._depthStencilFmt].name);
|
||||
// console.info('MAX_VERTEX_ATTRIBS: ' + this._maxVertexAttributes);
|
||||
console.info('MAX_VERTEX_UNIFORM_VECTORS: ' + this._maxVertexUniformVectors);
|
||||
console.info('MAX_FRAGMENT_UNIFORM_VECTORS: ' + this._maxFragmentUniformVectors);
|
||||
|
||||
@@ -163,6 +163,9 @@ export class WebGL2GFXDevice extends GFXDevice {
|
||||
|
||||
this._width = this._canvas.width;
|
||||
this._height = this._canvas.height;
|
||||
this._nativeWidth = Math.max(info.nativeWidth || this._width, 0);
|
||||
this._nativeHeight = Math.max(info.nativeHeight || this._width, 0);
|
||||
|
||||
this._colorFmt = GFXFormat.RGBA8;
|
||||
|
||||
if (this._depthBits === 32) {
|
||||
@@ -189,9 +192,9 @@ export class WebGL2GFXDevice extends GFXDevice {
|
||||
console.info('VENDOR: ' + this._vendor);
|
||||
console.info('VERSION: ' + this._version);
|
||||
console.info('SCREEN_SIZE: ' + this._width + ' x ' + this._height);
|
||||
console.info('COLOR_FORMAT: ' + GFXFormatInfos[this._colorFmt].name);
|
||||
console.info('DEPTH_STENCIL_FORMAT: ' + GFXFormatInfos[this._depthStencilFmt].name);
|
||||
|
||||
console.info('NATIVE_SIZE: ' + this._nativeWidth + ' x ' + this._nativeHeight);
|
||||
// console.info('COLOR_FORMAT: ' + GFXFormatInfos[this._colorFmt].name);
|
||||
// console.info('DEPTH_STENCIL_FORMAT: ' + GFXFormatInfos[this._depthStencilFmt].name);
|
||||
// console.info('MAX_VERTEX_ATTRIBS: ' + this._maxVertexAttributes);
|
||||
console.info('MAX_VERTEX_UNIFORM_VECTORS: ' + this._maxVertexUniformVectors);
|
||||
console.info('MAX_FRAGMENT_UNIFORM_VECTORS: ' + this._maxFragmentUniformVectors);
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import { IRenderFlowInfo, RenderFlow } from '../render-flow';
|
||||
import { RenderPipeline } from '../render-pipeline';
|
||||
// import { TestStage } from "./test-stage";
|
||||
import { ForwardStage } from './forward-stage';
|
||||
|
||||
export enum ForwardStagePriority {
|
||||
@@ -21,33 +20,15 @@ export class ForwardFlow extends RenderFlow {
|
||||
|
||||
this._priority = info.priority;
|
||||
|
||||
const mainWindow = this._pipeline.root.mainWindow;
|
||||
if (!mainWindow || !mainWindow.framebuffer) {
|
||||
return false;
|
||||
}
|
||||
const framebuffer = this._pipeline.root.mainWindow!.framebuffer!;
|
||||
|
||||
this.createStage(ForwardStage, {
|
||||
name: 'ForwardStage',
|
||||
priority: ForwardStagePriority.FORWARD,
|
||||
framebuffer: mainWindow.framebuffer,
|
||||
// framebuffer: this._pipeline.shadingFBO,
|
||||
framebuffer,
|
||||
});
|
||||
|
||||
/*
|
||||
this.createStage<TestModelStage>(TestModelStage, {
|
||||
name: 'TestModelStage',
|
||||
priority: ForwardStagePriority.FORWARD,
|
||||
framebuffer: mainWindow.framebuffer,
|
||||
});
|
||||
*/
|
||||
|
||||
/*
|
||||
this.createStage<TestStage>(TestStage, {
|
||||
name: 'TestStage',
|
||||
priority: ForwardStagePriority.FORWARD,
|
||||
framebuffer: mainWindow.framebuffer,
|
||||
});
|
||||
*/
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ import { RenderPassStage } from '../define';
|
||||
import { RenderPipeline } from '../render-pipeline';
|
||||
import { RenderView } from '../render-view';
|
||||
import { ForwardFlow } from './forward-flow';
|
||||
import { ToneMapFlow } from '../ppfx/tonemap-flow';
|
||||
|
||||
export enum ForwardFlowPriority {
|
||||
FORWARD = 0,
|
||||
@@ -88,11 +89,17 @@ export class ForwardPipeline extends RenderPipeline {
|
||||
this.addRenderPass(RenderPassStage.DEFAULT, windowPass);
|
||||
|
||||
// create flows
|
||||
this.createFlow<ForwardFlow>(ForwardFlow, {
|
||||
this.createFlow(ForwardFlow, {
|
||||
name: 'ForwardFlow',
|
||||
priority: ForwardFlowPriority.FORWARD,
|
||||
});
|
||||
|
||||
/*
|
||||
this.createFlow(ToneMapFlow, {
|
||||
name: 'ToneMapFlow',
|
||||
priority: 0,
|
||||
});
|
||||
*/
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -101,6 +108,7 @@ export class ForwardPipeline extends RenderPipeline {
|
||||
this.clearRenderPasses();
|
||||
this.destroyUBOs();
|
||||
this.destroyQuadInputAssembler();
|
||||
this.destroyShadingTarget();
|
||||
}
|
||||
|
||||
protected createUBOs (): boolean {
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
import { GFXCommandBuffer } from '../../gfx/command-buffer';
|
||||
import { GFXCommandBufferType, IGFXColor } from '../../gfx/define';
|
||||
import { GFXFramebuffer } from '../../gfx/framebuffer';
|
||||
import { Camera } from '../../renderer/scene/camera';
|
||||
import { RenderFlow } from '../render-flow';
|
||||
import { IRenderStageInfo, RenderStage } from '../render-stage';
|
||||
import { RenderView } from '../render-view';
|
||||
@@ -33,7 +31,6 @@ export class ForwardStage extends RenderStage {
|
||||
}
|
||||
|
||||
public destroy () {
|
||||
|
||||
if (this._cmdBuff) {
|
||||
this._cmdBuff.destroy();
|
||||
this._cmdBuff = null;
|
||||
@@ -45,8 +42,6 @@ export class ForwardStage extends RenderStage {
|
||||
|
||||
public render (view: RenderView) {
|
||||
|
||||
const framebuffer = view.window!.framebuffer;
|
||||
|
||||
const cmdBuff = this._cmdBuff!;
|
||||
const queue = this._pipeline.queue;
|
||||
|
||||
@@ -57,7 +52,7 @@ export class ForwardStage extends RenderStage {
|
||||
colors[0] = camera.clearColor;
|
||||
|
||||
cmdBuff.begin();
|
||||
cmdBuff.beginRenderPass(framebuffer, this._renderArea,
|
||||
cmdBuff.beginRenderPass(this._framebuffer!, this._renderArea,
|
||||
colors, camera.clearDepth, camera.clearStencil);
|
||||
|
||||
cmdBuff.execute(queue.cmdBuffs.array, queue.cmdBuffCount);
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
import { IRenderFlowInfo, RenderFlow } from '../render-flow';
|
||||
import { RenderPipeline } from '../render-pipeline';
|
||||
import { ToneMapStage } from './tonemap-stage';
|
||||
|
||||
export class ToneMapFlow extends RenderFlow {
|
||||
|
||||
constructor (pipeline: RenderPipeline) {
|
||||
super(pipeline);
|
||||
}
|
||||
|
||||
public initialize (info: IRenderFlowInfo): boolean {
|
||||
|
||||
if (info.name !== undefined) {
|
||||
this._name = info.name;
|
||||
}
|
||||
|
||||
this._priority = info.priority;
|
||||
|
||||
const material = new cc.Material();
|
||||
material.initialize({
|
||||
effectName: 'builtin-tonemap',
|
||||
});
|
||||
|
||||
this._material = material;
|
||||
|
||||
const framebuffer = this._pipeline.root.mainWindow!.framebuffer!;
|
||||
|
||||
this.createStage(ToneMapStage, {
|
||||
name: 'ToneMapStage',
|
||||
priority: 0,
|
||||
framebuffer,
|
||||
});
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public destroy (): void {
|
||||
this.destroyStages();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
import { GFXCommandBuffer } from '../../gfx/command-buffer';
|
||||
import { GFXCommandBufferType, IGFXColor } from '../../gfx/define';
|
||||
import { GFXFramebuffer } from '../../gfx/framebuffer';
|
||||
import { Camera } from '../../renderer/scene/camera';
|
||||
import { RenderFlow } from '../render-flow';
|
||||
import { IRenderStageInfo, RenderStage } from '../render-stage';
|
||||
import { RenderView } from '../render-view';
|
||||
import { GFXPipelineState } from '../../gfx/pipeline-state';
|
||||
|
||||
const colors: IGFXColor[] = [];
|
||||
const bufs: GFXCommandBuffer[] = [];
|
||||
|
||||
export class ToneMapStage extends RenderStage {
|
||||
|
||||
constructor (flow: RenderFlow) {
|
||||
super(flow);
|
||||
}
|
||||
|
||||
public initialize (info: IRenderStageInfo): boolean {
|
||||
|
||||
if (info.name !== undefined) {
|
||||
this._name = info.name;
|
||||
}
|
||||
|
||||
this._priority = info.priority;
|
||||
this._framebuffer = info.framebuffer;
|
||||
|
||||
this._cmdBuff = this._device.createCommandBuffer({
|
||||
allocator: this._device.commandAllocator,
|
||||
type: GFXCommandBufferType.PRIMARY,
|
||||
});
|
||||
|
||||
this._pass = this._flow.material.passes[0];
|
||||
this._pso = this._pass.createPipelineState();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public destroy () {
|
||||
if (this._cmdBuff) {
|
||||
this._cmdBuff.destroy();
|
||||
this._cmdBuff = null;
|
||||
}
|
||||
}
|
||||
|
||||
public resize (width: number, height: number) {
|
||||
}
|
||||
|
||||
public render (view: RenderView) {
|
||||
|
||||
const camera = view.camera!;
|
||||
|
||||
if (this._cmdBuff && camera.view.window) {
|
||||
|
||||
this._renderArea.width = camera.width;
|
||||
this._renderArea.height = camera.height;
|
||||
const framebuffer = camera.view.window.framebuffer;
|
||||
|
||||
this._cmdBuff.begin();
|
||||
this._cmdBuff.beginRenderPass(framebuffer, this._renderArea, [{ r: 0.0, g: 0.0, b: 0.0, a: 1.0 }], 1.0, 0);
|
||||
this._cmdBuff.bindPipelineState(this._pso!);
|
||||
this._cmdBuff.bindBindingLayout(this._pso!.pipelineLayout.layouts[0]);
|
||||
this._cmdBuff.bindInputAssembler(this._pipeline.quadIA);
|
||||
this._cmdBuff.draw(this._pipeline.quadIA);
|
||||
this._cmdBuff.endRenderPass();
|
||||
this._cmdBuff.end();
|
||||
}
|
||||
|
||||
this._device.queue.submit([this._cmdBuff!]);
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
import { Material } from '../3d/assets/material';
|
||||
import { GFXDevice } from '../gfx/device';
|
||||
import { Camera } from '../renderer/scene/camera';
|
||||
import { RenderPipeline } from './render-pipeline';
|
||||
import { IRenderStageInfo, RenderStage } from './render-stage';
|
||||
import { RenderView } from './render-view';
|
||||
@@ -23,12 +23,16 @@ export abstract class RenderFlow {
|
||||
return this._priority;
|
||||
}
|
||||
|
||||
public get material (): Material {
|
||||
return this._material!;
|
||||
}
|
||||
|
||||
protected _device: GFXDevice;
|
||||
protected _pipeline: RenderPipeline;
|
||||
protected _name: string = '';
|
||||
protected _priority: number = 0;
|
||||
protected _stages: RenderStage[] = [];
|
||||
protected _material: null = null; // TODO
|
||||
protected _material: Material | null = null;
|
||||
|
||||
constructor (pipeline: RenderPipeline) {
|
||||
this._device = pipeline.device;
|
||||
|
||||
@@ -3,8 +3,9 @@ import { Root } from '../core/root';
|
||||
import { Mat4 } from '../core/value-types';
|
||||
import { mat4, vec3 } from '../core/vmath';
|
||||
import { GFXBuffer } from '../gfx/buffer';
|
||||
import { GFXBufferUsageBit, GFXFormat, GFXMemoryUsageBit, GFXType, GFXLoadOp, GFXStoreOp, GFXTextureLayout, GFXFormatInfos } from '../gfx/define';
|
||||
import { GFXDevice, GFXFeature, GFXAPI } from '../gfx/device';
|
||||
import { GFXBufferUsageBit, GFXFormat, GFXFormatInfos, GFXLoadOp, GFXMemoryUsageBit, GFXStoreOp, GFXTextureLayout, GFXTextureType, GFXTextureUsageBit, GFXTextureViewType, GFXType } from '../gfx/define';
|
||||
import { GFXAPI, GFXDevice, GFXFeature } from '../gfx/device';
|
||||
import { GFXFramebuffer } from '../gfx/framebuffer';
|
||||
import { GFXInputAssembler, IGFXInputAttribute } from '../gfx/input-assembler';
|
||||
import { GFXRenderPass } from '../gfx/render-pass';
|
||||
import { GFXUniformBlock } from '../gfx/shader';
|
||||
@@ -13,7 +14,6 @@ import { GFXTextureView } from '../gfx/texture-view';
|
||||
import { IRenderFlowInfo, RenderFlow } from './render-flow';
|
||||
import { RenderQueue } from './render-queue';
|
||||
import { RenderView } from './render-view';
|
||||
import { GFXFramebuffer } from '../gfx/framebuffer';
|
||||
|
||||
export class UBOGlobal {
|
||||
public static TIME_OFFSET: number = 0;
|
||||
@@ -87,14 +87,18 @@ export abstract class RenderPipeline {
|
||||
return this._flows;
|
||||
}
|
||||
|
||||
public get shadingTex (): GFXTexture {
|
||||
return this._shadingTex!;
|
||||
}
|
||||
|
||||
public get shadingTexView (): GFXTextureView {
|
||||
return this._shadingTexView!;
|
||||
}
|
||||
|
||||
public get shadingFBO (): GFXFramebuffer {
|
||||
return this._shadingFBO!;
|
||||
}
|
||||
|
||||
public get depthStencilTexView (): GFXTextureView {
|
||||
return this._depthStencilTexView!;
|
||||
}
|
||||
|
||||
public get quadIA (): GFXInputAssembler {
|
||||
return this._quadIA!;
|
||||
}
|
||||
@@ -120,6 +124,8 @@ export abstract class RenderPipeline {
|
||||
protected _shadingPass: GFXRenderPass | null = null;
|
||||
protected _shadingTex: GFXTexture | null = null;
|
||||
protected _shadingTexView: GFXTextureView | null = null;
|
||||
protected _depthStencilTex: GFXTexture | null = null;
|
||||
protected _depthStencilTexView: GFXTextureView | null = null;
|
||||
protected _shadingFBO: GFXFramebuffer | null = null;
|
||||
protected _quadVB: GFXBuffer | null = null;
|
||||
protected _quadIB: GFXBuffer | null = null;
|
||||
@@ -232,6 +238,20 @@ export abstract class RenderPipeline {
|
||||
console.info('Shading Color Format: ' + GFXFormatInfos[colorFmt].name);
|
||||
console.info('Shading Depth Format: ' + GFXFormatInfos[depthFmt].name);
|
||||
|
||||
this._shadingTex = this._device.createTexture({
|
||||
type: GFXTextureType.TEX2D,
|
||||
usage: GFXTextureUsageBit.COLOR_ATTACHMENT | GFXTextureUsageBit.SAMPLED,
|
||||
format: colorFmt,
|
||||
width: this._device.nativeWidth,
|
||||
height: this._device.nativeHeight,
|
||||
});
|
||||
|
||||
this._shadingTexView = this._device.createTextureView({
|
||||
texture : this._shadingTex,
|
||||
type : GFXTextureViewType.TV2D,
|
||||
format : colorFmt,
|
||||
});
|
||||
|
||||
this._shadingPass = this._device.createRenderPass({
|
||||
colorAttachments: [{
|
||||
format: colorFmt,
|
||||
@@ -253,9 +273,37 @@ export abstract class RenderPipeline {
|
||||
},
|
||||
});
|
||||
|
||||
this._shadingFBO = this._device.createFramebuffer({
|
||||
renderPass: this._shadingPass,
|
||||
colorViews: [ this._shadingTexView ],
|
||||
depthStencilView: this._depthStencilTexView!,
|
||||
});
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
protected destroyShadingTarget () {
|
||||
if (this._shadingTexView) {
|
||||
this._shadingTexView.destroy();
|
||||
this._shadingTexView = null;
|
||||
}
|
||||
|
||||
if (this._shadingTex) {
|
||||
this._shadingTex.destroy();
|
||||
this._shadingTex = null;
|
||||
}
|
||||
|
||||
if (this._shadingFBO) {
|
||||
this._shadingFBO.destroy();
|
||||
this._shadingFBO = null;
|
||||
}
|
||||
|
||||
if (this._shadingPass) {
|
||||
this._shadingPass.destroy();
|
||||
this._shadingPass = null;
|
||||
}
|
||||
}
|
||||
|
||||
protected createQuadInputAssembler (): boolean {
|
||||
|
||||
// create vertex buffer
|
||||
|
||||
@@ -6,6 +6,8 @@ import { Camera } from '../renderer/scene/camera';
|
||||
import { RenderFlow } from './render-flow';
|
||||
import { RenderPipeline } from './render-pipeline';
|
||||
import { RenderView } from './render-view';
|
||||
import { GFXPipelineState } from '../gfx/pipeline-state';
|
||||
import { Pass } from '../renderer';
|
||||
|
||||
export interface IRenderStageInfo {
|
||||
name?: string;
|
||||
@@ -42,6 +44,8 @@ export abstract class RenderStage {
|
||||
protected _clearDepth: number = 1.0;
|
||||
protected _clearStencil: number = 0;
|
||||
protected _renderArea: IGFXRect;
|
||||
protected _pass: Pass | null = null;
|
||||
protected _pso: GFXPipelineState | null = null;
|
||||
|
||||
constructor (flow: RenderFlow) {
|
||||
this._flow = flow;
|
||||
|
||||
@@ -194,7 +194,9 @@ export class Pass {
|
||||
|
||||
public getHandle (name: string) {
|
||||
const handle = this._handleMap[name];
|
||||
if (!handle) { console.warn('illegal property name ' + name); }
|
||||
if (!handle) {
|
||||
console.warn('illegal property name ' + name);
|
||||
}
|
||||
return handle;
|
||||
}
|
||||
|
||||
@@ -283,7 +285,7 @@ export class Pass {
|
||||
}
|
||||
}
|
||||
|
||||
public createPipelineState () {
|
||||
public createPipelineState (): GFXPipelineState | null {
|
||||
if (!this._renderPass || !this._shader) { return null; }
|
||||
const bindingLayout = this._device.createBindingLayout({ bindings: this._bindings });
|
||||
for (const b of Object.keys(this._buffers)) {
|
||||
|
||||
@@ -303,9 +303,12 @@ export class UI {
|
||||
if (idx !== -1) {
|
||||
this._screens.splice(idx, 1);
|
||||
}
|
||||
|
||||
let camera;
|
||||
for (let i = idx; i < this._screens.length;) {
|
||||
if (this._screens[i].camera) {
|
||||
this._screens[i].camera.view.visibility = ++i;
|
||||
camera = this._screens[i].camera;
|
||||
if (camera) {
|
||||
camera.view.visibility = ++i;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user