补充某些必要的文件

This commit is contained in:
SmallMain
2022-06-25 11:52:00 +08:00
parent 4ecc470f86
commit 03533b046c
2869 changed files with 1345388 additions and 2 deletions

View File

@@ -0,0 +1,62 @@
uniform Constants{
vec4 mainTiling_Offset;
vec4 frameTile_velLenScale;
vec4 scale;
};
#include <cc-global>
#include <cc-local>
#include <transform>
out vec2 uv;
out vec4 color;
void computeVertPos(inout vec4 pos, vec2 vertOffset, vec4 q, vec3 s
#if CC_USE_BILLBOARD || CC_USE_VERTICAL_BILLBOARD
, mat4 viewInv
#endif
#if CC_USE_STRETCHED_BILLBOARD
, vec3 eye
, vec4 velocity
, float velocityScale
, float lengthScale
, float xIndex
#endif
) {
#if CC_USE_BILLBOARD
vec3 viewSpaceVert = vec3(vertOffset.x * s.x, vertOffset.y * s.y, 0.);
vec3 camX = normalize(vec3(viewInv[0][0], viewInv[1][0], viewInv[2][0]));
vec3 camY = normalize(vec3(viewInv[0][1], viewInv[1][1], viewInv[2][1]));
vec3 camZ = normalize(vec3(viewInv[0][2], viewInv[1][2], viewInv[2][2]));
pos.xyz += rotateInLocalSpace(viewSpaceVert, camX, camY, camZ, q);
#elif CC_USE_STRETCHED_BILLBOARD
vec3 camRight = normalize(cross(pos.xyz - eye, velocity.xyz)) * s.x;
vec3 camUp = velocity.xyz * velocityScale + normalize(velocity.xyz) * lengthScale * s.y;
pos.xyz += (camRight * abs(vertOffset.x) * sign(vertOffset.y)) - camUp * xIndex;
#elif CC_USE_HORIZONTAL_BILLBOARD
vec3 viewSpaceVert = vec3(vertOffset.x * s.x, vertOffset.y * s.y, 0.);
vec3 camX = vec3(1, 0, 0);
vec3 camY = vec3(0, 0, -1);
pos.xyz += rotateInLocalSpace(viewSpaceVert, camX, camY, cross(camX, camY), q);
#elif CC_USE_VERTICAL_BILLBOARD
vec2 viewSpaceVert = vec2(vertOffset.x * s.x, vertOffset.y * s.y);
rotateCorner(viewSpaceVert, q.z);
vec3 camX = normalize(vec3(cc_matView[0][0], cc_matView[1][0], cc_matView[2][0]));
vec3 camY = vec3(0, 1, 0);
vec3 offset = camX * viewSpaceVert.x + camY * viewSpaceVert.y;
pos.xyz += offset;
#else
pos.x += vertOffset.x;
pos.y += vertOffset.y;
#endif
}
vec2 computeUV(float frameIndex, vec2 vertIndex, vec2 frameTile){
vec2 aniUV = vec2(0, floor(frameIndex * frameTile.y));
aniUV.x = floor(frameIndex * frameTile.x * frameTile.y - aniUV.y * frameTile.x);
#if !CC_USE_MESH
vertIndex.y = 1. - vertIndex.y; // if using billboard ,y must be flipped.but mesh does not,why?
#endif
return (aniUV.xy + vertIndex) / vec2(frameTile.x, frameTile.y);
}

View File

@@ -0,0 +1,33 @@
precision mediump float;
#include <particle-common>
in vec3 a_position; // center position
in vec4 a_texCoord; // x:index y:size zw:texcoord
in vec3 a_texCoord1; // xyz:velocity
in vec3 a_texCoord2;
in vec4 a_color;
#if CC_DRAW_WIRE_FRAME
out vec3 vBarycentric;
#endif
vec4 vs_main() {
highp vec4 pos = vec4(a_position, 1);
vec4 velocity = vec4(a_texCoord1.xyz, 0);
#if !CC_USE_WORLD_SPACE
pos = cc_matWorld * pos;
velocity = cc_matWorld * velocity;
#endif
float vertOffset = (a_texCoord.x - 0.5) * a_texCoord.y;
vec3 camUp = normalize(cross(pos.xyz - cc_cameraPos.xyz, velocity.xyz));
pos.xyz += camUp * vertOffset;
pos = cc_matViewProj * pos;
uv = a_texCoord.zw * mainTiling_Offset.xy + mainTiling_Offset.zw;;
color = a_color;
#if CC_DRAW_WIRE_FRAME
vBarycentric = a_texCoord2;
#endif
return pos;
}

View File

@@ -0,0 +1,395 @@
precision mediump float;
#include <particle-common>
#define MAX_KEY_NUM 8
#define CURVE_MODE_CONSTANT 0
#define CURVE_MODE_RANDOM_CONSTANT 1
#define CURVE_MODE_CURVE 2
#define CURVE_MODE_RANDOM_CURVE 3
#define GRADIENT_MODE_FIX 0
#define GRADIENT_MODE_BLEND 1
#define GRADIENT_RANGE_MODE_COLOR 0
#define GRADIENT_RANGE_MODE_TWO_COLOR 1
#define GRADIENT_RANGE_MODE_RANDOM_COLOR 2
#define GRADIENT_RANGE_MODE_GRADIENT 3
#define GRADIENT_RANGE_MODE_TWO_GRADIENT 4
#define SIMULATE_SPACE_LOCAL 0
#define SIMULATE_SPACE_WORLD 1
#define ANIMATION_MODE_WHOLE_SHEET 0
#define ANIMATION_MODE_SINGLE_ROW 1
#define COLOR_OVERTIME_RAND_OFFSET 91041.
#define FORCE_OVERTIME_RAND_OFFSET 212165.
#define ROTATION_OVERTIME_RAND_OFFSET 125292.
#define SIZE_OVERTIME_RAND_OFFSET 39825.
#define TEXTURE_ANIMATION_RAND_OFFSET 90794.
#define VELOCITY_OVERTIME_RAND_OFFSET 197866.
#define DECL_CURVE_STRUCT(name) \
uniform CurveStruct_##name## { \
int u_##name##_curveMode; \
float u_##name##_minConstant; \
float u_##name##_maxConstant; \
float u_##name##_minKeyTime[MAX_KEY_NUM]; \
vec4 u_##name##_minKeyCoef[MAX_KEY_NUM]; \
vec4 u_##name##_maxKeyCoef[MAX_KEY_NUM]; \
float u_##name##_maxKeyTime[MAX_KEY_NUM]; \
};
#define DECL_CURVE_STRUCT_INT(name) \
uniform CurveStructInt_##name## { \
int u_##name##_curveMode; \
float u_##name##_minConstant; \
float u_##name##_maxConstant; \
float u_##name##_minKeyTime[MAX_KEY_NUM]; \
vec4 u_##name##_minKeyCoef[MAX_KEY_NUM]; \
vec4 u_##name##_maxKeyCoef[MAX_KEY_NUM]; \
float u_##name##_maxKeyTime[MAX_KEY_NUM]; \
float u_##name##_minIntegral[MAX_KEY_NUM - 1]; \
float u_##name##_maxIntegral[MAX_KEY_NUM - 1]; \
};
#define DECL_GRADIENT_STRUCT(name) \
uniform GradientStruct_##name## { \
int u_##name##_rangeMode; \
int u_##name##_minGradMode; \
int u_##name##_maxGradMode; \
vec4 u_##name##_minColor; \
vec4 u_##name##_maxColor; \
vec3 u_##name##_minColorKeyValue[MAX_KEY_NUM]; \
float u_##name##_minColorKeyTime[MAX_KEY_NUM]; \
float u_##name##_minAlphaKeyValue[MAX_KEY_NUM]; \
float u_##name##_minAlphaKeyTime[MAX_KEY_NUM]; \
vec3 u_##name##_maxColorKeyValue[MAX_KEY_NUM]; \
float u_##name##_maxColorKeyTime[MAX_KEY_NUM]; \
float u_##name##_maxAlphaKeyValue[MAX_KEY_NUM]; \
float u_##name##_maxAlphaKeyTime[MAX_KEY_NUM]; \
};
#define EVAL_CURVE_RANGE(name, t, rnd) \
evaluateCurveRange(u_##name##_curveMode, u_##name##_minConstant, u_##name##_maxConstant, u_##name##_minKeyTime, u_##name##_minKeyCoef, u_##name##_maxKeyTime, u_##name##_maxKeyCoef, t, rnd)
#define EVAL_CURVE_INTEGRAL(name, t, ts, rnd) \
evaluateCurveRangeIntegral(u_##name##_curveMode, u_##name##_minConstant, u_##name##_maxConstant, u_##name##_minKeyTime, u_##name##_minKeyCoef, u_##name##_minIntegral, u_##name##_maxKeyTime, u_##name##_maxKeyCoef, u_##name##_maxIntegral, t, ts, rnd)
#define EVAL_CURVE_INTEGRAL_TWICE(name, t, ts, rnd) \
evaluateCurveRangeIntegralTwice(u_##name##_curveMode, u_##name##_minConstant, u_##name##_maxConstant, u_##name##_minKeyTime, u_##name##_minKeyCoef, u_##name##_minIntegral, u_##name##_maxKeyTime, u_##name##_maxKeyCoef, u_##name##_maxIntegral, t, ts, rnd)
#define EVAL_GRADIENT_RANGE(name, t, rnd) \
evaluateGradientRange(u_##name##_rangeMode, u_##name##_minColor, u_##name##_maxColor, \
u_##name##_minGradMode, u_##name##_minColorKeyValue, u_##name##_minColorKeyTime, u_##name##_minAlphaKeyValue, u_##name##_minAlphaKeyTime, \
u_##name##_maxGradMode, u_##name##_maxColorKeyValue, u_##name##_maxColorKeyTime, u_##name##_maxAlphaKeyValue, u_##name##_maxAlphaKeyTime, t, rnd);
in vec4 a_position_starttime; // center position,particle start time
in vec4 a_vertIdx_size_angle; // xy:vertex index,z:size,w:angle
in vec4 a_color;
in vec4 a_dir_life; // xyz:particle start velocity,w:particle lifetime
in float a_rndSeed;
uniform Constants2 {
vec4 u_worldRot;
float u_psTime;
int u_velocity_space;
float u_speedModifier;
int u_force_space;
};
#if VELOCITY_OVERTIME_MODULE_ENABLE
// DECL_CURVE_STRUCT_INT(velocity_pos_x)
// DECL_CURVE_STRUCT_INT(velocity_pos_y)
// DECL_CURVE_STRUCT_INT(velocity_pos_z)
#if USE_STRETCHED_BILLBOARD
// DECL_CURVE_STRUCT(velocity_x)
// DECL_CURVE_STRUCT(velocity_y)
// DECL_CURVE_STRUCT(velocity_z)
#endif
#endif
#if FORCE_OVERTIME_MODULE_ENABLE
// DECL_CURVE_STRUCT_INT(force_pos_x)
// DECL_CURVE_STRUCT_INT(force_pos_y)
// DECL_CURVE_STRUCT_INT(force_pos_z)
#if USE_STRETCHED_BILLBOARD
// DECL_CURVE_STRUCT_INT(force_vel_x)
// DECL_CURVE_STRUCT_INT(force_vel_y)
// DECL_CURVE_STRUCT_INT(force_vel_z)
#endif
#endif
#if SIZE_OVERTIME_MODULE_ENABLE
// DECL_CURVE_STRUCT(size)
#endif
#if COLOR_OVERTIME_MODULE_ENABLE
// DECL_GRADIENT_STRUCT(color)
#endif
#if TEXTURE_ANIMATION_ENABLE
// DECL_CURVE_STRUCT(frameOverTime)
uniform Animation {
float u_cycles;
int u_animation_mode;
bool u_random_row;
int u_row_index;
};
#endif
#if ROTATE_OVERTIME_MODULE_ENABLE
// DECL_CURVE_STRUCT_INT(rotate)
#endif
float repeat(float t, float length) {
return t - floor(t / length) * length;
}
vec4 rotateQuat(vec4 p, vec4 q) {
vec3 iv = cross(q.xyz, p.xyz) + q.w * p.xyz;
vec3 res = p.xyz + 2.0 * cross(q.xyz, iv);
return vec4(res.xyz, p.w);
}
float random(float seed) {
seed = mod(seed, 233280.);
float q = (seed * 9301. + 49297.) / 233280.;
return fract(q);
}
float calcCurveValue(vec4 coef, float t) {
return t * (t * (t * coef.x + coef.y) + coef.z) + coef.w;
}
float evaluateCurve(float keyTime[MAX_KEY_NUM], vec4 keyCoef[MAX_KEY_NUM], float normalizedTime) {
for (int i = 0; i < MAX_KEY_NUM; i++) {
if (keyTime[i] > normalizedTime) {
return calcCurveValue(keyCoef[i], normalizedTime - (i == 0 ? 0. : keyTime[i - 1]));
}
}
}
float evaluateIntegral(float keyTime[MAX_KEY_NUM], vec4 keyCoef[MAX_KEY_NUM], float integral[MAX_KEY_NUM - 1], float normalizedTime, float ts) {
for (int i = 0; i < MAX_KEY_NUM; i++) {
if (keyTime[i] > normalizedTime) {
float t = normalizedTime - (i == 0 ? 0. : keyTime[i - 1]);
return ts * ((i - 1 < 0 ? 0. : integral[i - 1]) + t * calcCurveValue(keyCoef[i], t));
}
}
}
float evaluateIntegralTwice(float keyTime[MAX_KEY_NUM], vec4 keyCoef[MAX_KEY_NUM], float integral[MAX_KEY_NUM - 1], float normalizedTime, float ts) {
for (int i = 0; i < MAX_KEY_NUM; i++) {
if (keyTime[i] > normalizedTime) {
float t = normalizedTime - (i == 0 ? 0. : keyTime[i - 1]);
return ts * ts * ((i - 1 < 0 ? 0. : integral[i - 1]) + t * t * calcCurveValue(keyCoef[i], t));
}
}
}
float evaluateCurveRange(int mode, float minConstant, float maxConstant
, float minKeyTime[MAX_KEY_NUM], vec4 minKeyCoef[MAX_KEY_NUM]
, float maxKeyTime[MAX_KEY_NUM], vec4 maxKeyCoef[MAX_KEY_NUM]
, float t, float rnd) {
if (mode == CURVE_MODE_CONSTANT) {
return minConstant;
} else if (mode == CURVE_MODE_RANDOM_CONSTANT) {
return mix(minConstant, maxConstant, random(rnd));
} else if (mode == CURVE_MODE_CURVE) {
return evaluateCurve(minKeyTime, minKeyCoef, t);
} else if (mode == CURVE_MODE_RANDOM_CURVE) {
return mix(evaluateCurve(minKeyTime, minKeyCoef, t), evaluateCurve(maxKeyTime, maxKeyCoef, t), random(rnd));
}
}
float evaluateCurveRangeIntegral(int mode, float minConstant, float maxConstant
, float minKeyTime[MAX_KEY_NUM], vec4 minKeyCoef[MAX_KEY_NUM], float minIntegral[MAX_KEY_NUM - 1]
, float maxKeyTime[MAX_KEY_NUM], vec4 maxKeyCoef[MAX_KEY_NUM], float maxIntegral[MAX_KEY_NUM - 1]
, float t, float ts, float rnd) {
if (mode == CURVE_MODE_CONSTANT) {
return minConstant * t * ts;
} else if (mode == CURVE_MODE_RANDOM_CONSTANT) {
return mix(minConstant, maxConstant, random(rnd)) * t * ts;
} else if (mode == CURVE_MODE_CURVE) {
return evaluateIntegral(minKeyTime, minKeyCoef, minIntegral, t, ts);
} else if (mode == CURVE_MODE_RANDOM_CURVE) {
return mix(evaluateIntegral(minKeyTime, minKeyCoef, minIntegral, t, ts), evaluateIntegral(maxKeyTime, maxKeyCoef, maxIntegral, t, ts), random(rnd));
}
}
float evaluateCurveRangeIntegralTwice(int mode, float minConstant, float maxConstant
, float minKeyTime[MAX_KEY_NUM], vec4 minKeyCoef[MAX_KEY_NUM], float minIntegral[MAX_KEY_NUM - 1]
, float maxKeyTime[MAX_KEY_NUM], vec4 maxKeyCoef[MAX_KEY_NUM], float maxIntegral[MAX_KEY_NUM - 1]
, float t, float ts, float rnd) {
if (mode == CURVE_MODE_CONSTANT) {
return minConstant * t * t * ts * ts / 2.;
} else if (mode == CURVE_MODE_RANDOM_CONSTANT) {
return mix(minConstant, maxConstant, random(rnd)) * t * t * ts * ts / 2.;
} else if (mode == CURVE_MODE_CURVE) {
return evaluateIntegralTwice(minKeyTime, minKeyCoef, minIntegral, t, ts);
} else if (mode == CURVE_MODE_RANDOM_CURVE) {
return mix(evaluateIntegralTwice(minKeyTime, minKeyCoef, minIntegral, t, ts), evaluateIntegralTwice(maxKeyTime, maxKeyCoef, maxIntegral, t, ts), random(rnd));
}
}
vec4 evaluateGradient(int mode, float colorKeyTime[MAX_KEY_NUM], vec3 colorKeyValue[MAX_KEY_NUM]
, float alphaKeyTime[MAX_KEY_NUM], float alphaKeyValue[MAX_KEY_NUM]
, float t){
vec4 ret;
for (int i = 0; i < MAX_KEY_NUM; i++) {
if (t < colorKeyTime[i]) {
if (mode == GRADIENT_MODE_FIX) {
ret.xyz = colorKeyValue[i];
} else if (mode == GRADIENT_MODE_BLEND) {
ret.xyz = mix(colorKeyValue[i - 1], colorKeyValue[i], (t - colorKeyTime[i - 1]) / (colorKeyTime[i] - colorKeyTime[i - 1]));
}
break;
}
}
for (int i = 0; i < MAX_KEY_NUM; i++) {
if (t < alphaKeyTime[i]) {
if (mode == GRADIENT_MODE_FIX) {
ret.w = alphaKeyValue[i];
} else if (mode == GRADIENT_MODE_BLEND) {
ret.w = mix(alphaKeyValue[i - 1], alphaKeyValue[i], (t - alphaKeyTime[i - 1]) / (alphaKeyTime[i] - alphaKeyTime[i - 1]));
}
break;
}
}
return ret;
}
vec4 evaluateGradientRange(int rangeMode, vec4 minColor, vec4 maxColor,
int minGradMode, vec3 minColorKeyValue[MAX_KEY_NUM], float minColorKeyTime[MAX_KEY_NUM], float minAlphaKeyValue[MAX_KEY_NUM], float minAlphaKeyTime[MAX_KEY_NUM],
int maxGradMode, vec3 maxColorKeyValue[MAX_KEY_NUM], float maxColorKeyTime[MAX_KEY_NUM], float maxAlphaKeyValue[MAX_KEY_NUM], float maxAlphaKeyTime[MAX_KEY_NUM],
float t, float rnd){
if (rangeMode == GRADIENT_RANGE_MODE_COLOR) {
return minColor;
} else if (rangeMode == GRADIENT_RANGE_MODE_TWO_COLOR) {
return mix(minColor, maxColor, rnd);
} else if (rangeMode == GRADIENT_RANGE_MODE_GRADIENT) {
return evaluateGradient(minGradMode, minColorKeyTime, minColorKeyValue, minAlphaKeyTime, minAlphaKeyValue, t);
} else if (rangeMode == GRADIENT_RANGE_MODE_TWO_GRADIENT) {
return mix(evaluateGradient(minGradMode, minColorKeyTime, minColorKeyValue, minAlphaKeyTime, minAlphaKeyValue, t),
evaluateGradient(maxGradMode, maxColorKeyTime, maxColorKeyValue, maxAlphaKeyTime, maxAlphaKeyValue, t), rnd);
}
}
vec4 gpvs_main() {
vec4 pos = vec4(a_position_starttime.xyz, 1.);
float activeTime = u_psTime - a_position_starttime.w;
float normalizedTime = activeTime / a_dir_life.w;
#if VELOCITY_OVERTIME_MODULE_ENABLE
float speedModifier = u_speedModifier;
#else
float speedModifier = 1.;
#endif
pos.xyz += a_dir_life.xyz * activeTime * speedModifier;
#if USE_STRETCHED_BILLBOARD
vec4 velocity = vec4(a_dir_life.xyz, 0.);
velocity *= speedModifier;
#endif
#if !USE_WORLD_SPACE
pos = cc_matWorld * pos;
#if USE_STRETCHED_BILLBOARD
velocity = rotateQuat(velocity, u_worldRot);
#endif
#endif
#if VELOCITY_OVERTIME_MODULE_ENABLE
vec4 velocityTrack = vec4(EVAL_CURVE_INTEGRAL(velocity_pos_x, normalizedTime, a_dir_life.w, a_rndSeed + VELOCITY_OVERTIME_RAND_OFFSET), EVAL_CURVE_INTEGRAL(velocity_pos_y, normalizedTime, a_dir_life.w, a_rndSeed + VELOCITY_OVERTIME_RAND_OFFSET), EVAL_CURVE_INTEGRAL(velocity_pos_z, normalizedTime, a_dir_life.w, a_rndSeed + VELOCITY_OVERTIME_RAND_OFFSET), 0);
velocityTrack = velocityTrack * speedModifier;
if (u_velocity_space == SIMULATE_SPACE_LOCAL) {
velocityTrack = rotateQuat(velocityTrack, u_worldRot);
}
pos += velocityTrack;
#if USE_STRETCHED_BILLBOARD
vec4 velocityVel = vec4(EVAL_CURVE_RANGE(velocity_x, normalizedTime, a_dir_life.w, a_rndSeed + VELOCITY_OVERTIME_RAND_OFFSET), EVAL_CURVE_RANGE(velocity_y, normalizedTime, a_dir_life.w, a_rndSeed + VELOCITY_OVERTIME_RAND_OFFSET), EVAL_CURVE_RANGE(velocity_z, normalizedTime, a_dir_life.w, a_rndSeed + VELOCITY_OVERTIME_RAND_OFFSET), 0);
if (u_velocity_space == SIMULATE_SPACE_LOCAL) {
velocityVel = rotateQuat(velocityVel, u_worldRot);
}
velocityVel *= speedModifier;
velocity += velocityVel;
#endif
#endif
#if FORCE_OVERTIME_MODULE_ENABLE
vec4 forceTrack = vec4(EVAL_CURVE_INTEGRAL_TWICE(force_pos_x, normalizedTime, a_dir_life.w, a_rndSeed + FORCE_OVERTIME_RAND_OFFSET), EVAL_CURVE_INTEGRAL_TWICE(force_pos_y, normalizedTime, a_dir_life.w, a_rndSeed + FORCE_OVERTIME_RAND_OFFSET), EVAL_CURVE_INTEGRAL_TWICE(force_pos_z, normalizedTime, a_dir_life.w, a_rndSeed + FORCE_OVERTIME_RAND_OFFSET), 0);
forceTrack = forceTrack * speedModifier;
if (u_force_space == SIMULATE_SPACE_LOCAL) {
forceTrack = rotateQuat(forceTrack, u_worldRot);
}
pos += forceTrack;
#if USE_STRETCHED_BILLBOARD
vec4 forceVel = vec4(EVAL_CURVE_INTEGRAL(force_vel_x, normalizedTime, a_dir_life.w, a_rndSeed + FORCE_OVERTIME_RAND_OFFSET), EVAL_CURVE_INTEGRAL(force_vel_y, normalizedTime, a_dir_life.w, a_rndSeed + FORCE_OVERTIME_RAND_OFFSET), EVAL_CURVE_INTEGRAL(force_vel_z, normalizedTime, a_dir_life.w, a_rndSeed + FORCE_OVERTIME_RAND_OFFSET), 0);
if (u_force_space == SIMULATE_SPACE_LOCAL) {
forceVel = rotateQuat(forceVel, u_worldRot);
}
forceVel *= speedModifier;
velocity += forceVel;
#endif
#endif
float size = a_vertIdx_size_angle.z;
#if SIZE_OVERTIME_MODULE_ENABLE
float sizeModifier = EVAL_CURVE_RANGE(size, normalizedTime, a_rndSeed + SIZE_OVERTIME_RAND_OFFSET);
size *= sizeModifier;
#endif
vec2 cornerOffset = vec2((a_vertIdx_size_angle.xy - 0.5) * size);
#if !USE_STRETCHED_BILLBOARD
float angle = a_vertIdx_size_angle.w;
#if ROTATE_OVERTIME_MODULE_ENABLE
angle += EVAL_CURVE_INTEGRAL(rotate, normalizedTime, a_dir_life.w, a_rndSeed + ROTATION_OVERTIME_RAND_OFFSET);
#endif
rotateCorner(cornerOffset, angle);
#endif
computeVertPos(pos, cornerOffset
#if USE_BILLBOARD || USE_VERTICAL_BILLBOARD
, cc_matView
#endif
#if USE_STRETCHED_BILLBOARD
, cc_cameraPos
, velocity
, velocityScale
, lengthScale
, size
, a_vertIdx_size_angle.x
#endif
);
pos = cc_matViewProj * pos;
float frameIndex = 0.;
#if TEXTURE_ANIMATION_ENABLE
if (u_animation_mode == ANIMATION_MODE_WHOLE_SHEET) {
frameIndex = repeat(u_cycles * EVAL_CURVE_RANGE(frameOverTime, normalizedTime, a_rndSeed + TEXTURE_ANIMATION_RAND_OFFSET), 1.);
} else if (u_animation_mode == ANIMATION_MODE_SINGLE_ROW) {
float rowLength = 1. / frameTile_velLenScale.y;
if (u_random_row) {
float f = repeat(u_cycles * EVAL_CURVE_RANGE(frameOverTime, normalizedTime, a_rndSeed + TEXTURE_ANIMATION_RAND_OFFSET), 1.);
float startRow = floor(random(floor(u_psTime * 1000.)) * frameTile_velLenScale.y);
float from = startRow * rowLength;
float to = from + rowLength;
frameIndex = mix(from, to, f);
}
else {
float from = float(u_row_index) * rowLength;
float to = from + rowLength;
frameIndex = mix(from, to, repeat(u_cycles * EVAL_CURVE_RANGE(frameOverTime, normalizedTime, a_rndSeed + TEXTURE_ANIMATION_RAND_OFFSET), 1.));
}
}
#endif
uv = computeUV(frameIndex, a_vertIdx_size_angle.xy, frameTile_velLenScale.xy) * mainTiling_Offset.xy + mainOffset.zw;
#if COLOR_OVERTIME_MODULE_ENABLE
color = a_color * EVAL_GRADIENT_RANGE(color, normalizedTime, a_rndSeed + COLOR_OVERTIME_RAND_OFFSET);
#else
color = a_color;
#endif
return pos;
}

View File

@@ -0,0 +1,75 @@
precision highp float;
#include <transform>
#include <particle-common>
#include <cc-local>
in vec3 a_position; // center position
in vec3 a_texCoord; // xy:vertex index,z:frame index
in vec3 a_texCoord1; // size
in vec3 a_texCoord2; // rotation
in vec4 a_color;
#if CC_USE_STRETCHED_BILLBOARD
in vec3 a_color1; // velocity.x, velocity.y, velocity.z, scale
#endif
#if CC_USE_MESH
in vec3 a_texCoord3; // mesh vertices
in vec3 a_normal; // mesh normal
in vec4 a_color1; // mesh color
#endif
vec4 lpvs_main() {
vec3 compScale = scale.xyz * a_texCoord1;
vec4 pos = vec4(a_position, 1);
#if CC_USE_STRETCHED_BILLBOARD
vec4 velocity = vec4(a_color1.xyz, 0);
#endif
#if !CC_USE_WORLD_SPACE
// simulate in world space. apply cc_matWorld matrix on CPU side.
pos = cc_matWorld * pos;
#if CC_USE_STRETCHED_BILLBOARD
velocity = cc_matWorld * velocity;
#endif
#endif
#if !CC_USE_MESH
vec2 cornerOffset = vec2((a_texCoord.xy - 0.5));
#if CC_USE_BILLBOARD
vec3 rotEuler = a_texCoord2;
#elif CC_USE_STRETCHED_BILLBOARD
vec3 rotEuler = vec3(0.);
#else
vec3 rotEuler = vec3(0., 0., a_texCoord2.z);
#endif
computeVertPos(pos, cornerOffset, quaternionFromEuler(rotEuler), compScale
#if CC_USE_BILLBOARD || CC_USE_VERTICAL_BILLBOARD
, cc_matViewInv
#endif
#if CC_USE_STRETCHED_BILLBOARD
, cc_cameraPos.xyz
, velocity
, frameTile_velLenScale.z
, frameTile_velLenScale.w
, a_texCoord.x
#endif
);
color = a_color;
#else
mat4 xformNoScale = matrixFromRT(quaternionFromEuler(a_texCoord2), pos.xyz);
mat4 xform = matFromRTS(quaternionFromEuler(a_texCoord2), pos.xyz, compScale);
pos = xform * vec4(a_texCoord3, 1);
vec4 normal = xformNoScale * vec4(a_normal, 0);
color = a_color * a_color1;
#endif
uv = computeUV(a_texCoord.z, a_texCoord.xy, frameTile_velLenScale.xy) * mainTiling_Offset.xy + mainTiling_Offset.zw;
pos = cc_matViewProj * pos;
return pos;
}

View File

@@ -0,0 +1,102 @@
// Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
precision highp float;
#include <cc-global>
#include <texture>
#include <output>
#include <alpha-test>
uniform PhongFrag {
lowp vec4 diffuseColor;
lowp vec4 specularColor;
lowp vec4 emissiveColor;
float glossiness;
};
#if USE_DIFFUSE_TEXTURE
uniform sampler2D diffuseTexture;
#endif
#if USE_SPECULAR && USE_SPECULAR_TEXTURE
uniform sampler2D specularTexture;
#endif
#if USE_EMISSIVE && USE_EMISSIVE_TEXTURE
uniform sampler2D emissiveTexture;
#endif
#if USE_NORMAL_TEXTURE
in vec3 v_tangent;
in vec3 v_bitangent;
uniform sampler2D normalTexture;
#endif
#define CC_USE_TEXTURE CC_USE_ATTRIBUTE_UV0 && (USE_DIFFUSE_TEXTURE || (USE_EMISSIVE && USE_EMISSIVE_TEXTURE) || (USE_SPECULAR && USE_SPECULAR_TEXTURE) || USE_NORMAL_TEXTURE)
in vec3 v_worldNormal;
in vec3 v_worldPos;
in vec3 v_viewDirection;
#if CC_USE_TEXTURE
in mediump vec2 v_uv0;
#endif
#if CC_USE_ATTRIBUTE_COLOR
in lowp vec4 v_color;
#endif
#include <shading-phong>
void surf (out PhongSurface s) {
vec4 diffuse = vec4(1, 1, 1, 1);
#if CC_USE_ATTRIBUTE_COLOR
diffuse *= v_color;
#endif
diffuse *= diffuseColor;
#if USE_DIFFUSE_TEXTURE
CCTexture(diffuseTexture, v_uv0, diffuse);
#endif
ALPHA_TEST(diffuse);
s.diffuse = diffuse.rgb;
s.opacity = diffuse.a;
#if USE_EMISSIVE
s.emissive = emissiveColor.rgb;
#if USE_EMISSIVE_TEXTURE
CCTextureRGB(emissiveTexture, v_uv0, s.emissive);
#endif
#endif
#if USE_SPECULAR
s.specular = specularColor.rgb;
#if USE_SPECULAR_TEXTURE
CCTextureRGB(specularTexture, v_uv0, s.specular);
#endif
#endif
s.normal = v_worldNormal;
#if USE_NORMAL_TEXTURE
vec3 nmmp = texture(normalTexture, v_uv0).xyz - vec3(0.5);
s.normal =
nmmp.x * normalize(v_tangent) +
nmmp.y * normalize(v_bitangent) +
nmmp.z * normalize(s.normal);
s.normal = normalize(s.normal);
#endif
s.position = v_worldPos;
s.viewDirection = v_viewDirection;
s.glossiness = glossiness;
}
void main () {
PhongSurface s;
surf(s);
vec4 color = CCPhongShading(s);
gl_FragColor = CCFragOutput(color);
}

View File

@@ -0,0 +1,60 @@
// Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
precision highp float;
#include <cc-local>
#include <cc-global>
#include <input-standard>
#include <shadow>
#define CC_USE_TEXTURE CC_USE_ATTRIBUTE_UV0 && (USE_DIFFUSE_TEXTURE || USE_EMISSIVE_TEXTURE || USE_SPECULAR_TEXTURE || USE_NORMAL_TEXTURE)
uniform MAIN_TILING {
vec2 mainTiling;
vec2 mainOffset;
};
#if CC_USE_TEXTURE
out mediump vec2 v_uv0;
#endif
#if CC_USE_ATTRIBUTE_COLOR
out lowp vec4 v_color;
#endif
#if USE_NORMAL_TEXTURE
out vec3 v_tangent;
out vec3 v_bitangent;
#endif
out vec3 v_worldNormal;
out vec3 v_worldPos;
out vec3 v_viewDirection;
void main () {
StandardVertInput In;
CCVertInput(In);
vec4 position = In.position;
v_worldNormal = normalize((cc_matWorldIT * vec4(In.normal, 0)).xyz);
v_worldPos = (cc_matWorld * position).xyz;
v_viewDirection = normalize(cc_cameraPos.xyz - v_worldPos);
#if CC_USE_TEXTURE
v_uv0 = In.uv * mainTiling + mainOffset;
#endif
#if CC_USE_ATTRIBUTE_COLOR
v_color = In.color;
#endif
#if USE_NORMAL_TEXTURE
v_tangent = normalize((cc_matWorld * vec4(In.tangent.xyz, 0.0)).xyz);
v_bitangent = cross(v_worldNormal, v_tangent) * In.tangent.w; // note the cross order
#endif
CCShadowInput(v_worldPos);
gl_Position = cc_matViewProj * cc_matWorld * position;
}

View File

@@ -0,0 +1,11 @@
// Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
precision highp float;
in float v_depth;
#include <packing>
void main () {
gl_FragColor = packDepthToRGBA(v_depth);
}

View File

@@ -0,0 +1,29 @@
// Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
precision highp float;
in vec3 a_position;
#include <cc-local>
#pragma builtin(global)
uniform CC_SHADOW_MAP {
mat4 cc_shadow_map_lightViewProjMatrix;
vec4 cc_shadow_map_info; // [minDepth, maxDepth, depthScale, darkness]
float cc_shadow_map_bias;
};
out float v_depth;
#include <skinning>
void main () {
vec4 position = vec4(a_position, 1);
SKIN_VERTEX(position);
gl_Position = cc_shadow_map_lightViewProjMatrix * cc_matWorld * position;
// compute v_depth according to active camera's minDepth and maxDepth.
v_depth = ((gl_Position.z + cc_shadow_map_info.x) / (cc_shadow_map_info.x + cc_shadow_map_info.y)) + cc_shadow_map_bias;
}

View File

@@ -0,0 +1,41 @@
// Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
precision highp float;
#include <alpha-test>
#include <texture>
#include <output>
uniform UNLIT {
lowp vec4 diffuseColor;
};
#if USE_DIFFUSE_TEXTURE
uniform sampler2D diffuseTexture;
#endif
#define CC_USE_TEXTURE CC_USE_ATTRIBUTE_UV0 && USE_DIFFUSE_TEXTURE
#if CC_USE_ATTRIBUTE_COLOR
in lowp vec4 v_color;
#endif
#if CC_USE_TEXTURE
in mediump vec2 v_uv0;
#endif
void main () {
vec4 color = diffuseColor;
#if CC_USE_TEXTURE
CCTexture(diffuseTexture, v_uv0, color);
#endif
#if CC_USE_ATTRIBUTE_COLOR
color *= v_color;
#endif
ALPHA_TEST(color);
gl_FragColor = CCFragOutput(color);
}

View File

@@ -0,0 +1,38 @@
// Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
precision highp float;
#include <cc-local>
#include <cc-global>
#include <skinning>
#include <input-standard>
#define CC_USE_TEXTURE CC_USE_ATTRIBUTE_UV0 && USE_DIFFUSE_TEXTURE
uniform MAIN_TILING {
vec2 mainTiling;
vec2 mainOffset;
};
#if CC_USE_TEXTURE
out mediump vec2 v_uv0;
#endif
#if CC_USE_ATTRIBUTE_COLOR
out lowp vec4 v_color;
#endif
void main () {
StandardVertInput In;
CCVertInput(In);
#if CC_USE_ATTRIBUTE_COLOR
v_color = In.color;
#endif
#if CC_USE_TEXTURE
v_uv0 = In.uv * mainTiling + mainOffset;
#endif
gl_Position = cc_matViewProj * cc_matWorld * In.position;
}