Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/dev' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
LiuYi0526 committed May 3, 2024
2 parents e760560 + 77368aa commit 69811d4
Show file tree
Hide file tree
Showing 318 changed files with 20,839 additions and 4,546 deletions.
9 changes: 5 additions & 4 deletions TMessagesProj/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ repositories {
}
}

def verName = "10.10.1"
def verCode = 1169
def verName = "10.12.0"
def verCode = 1171


def officialVer = "10.10.1"
def officialCode = 4583
def officialVer = "10.12.0"
def officialCode = 4710

def serviceAccountCredentialsFile = rootProject.file("service_account_credentials.json")

Expand Down Expand Up @@ -306,6 +306,7 @@ dependencies {
implementation 'com.google.guava:guava:31.1-android'

implementation 'com.google.android.gms:play-services-mlkit-subject-segmentation:16.0.0-beta1'
implementation 'com.google.android.gms:play-services-mlkit-image-labeling:16.0.8'

compileOnly 'org.yaml:snakeyaml:1.29'
implementation 'org.yaml:snakeyaml:1.29'
Expand Down
29 changes: 27 additions & 2 deletions TMessagesProj/jni/lottie.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,9 +182,34 @@ JNIEXPORT jlong Java_org_telegram_ui_Components_RLottieDrawable_getFramesCount(J
delete info;
return 0;
}
long frameCount = info->animation->totalFrame();
long framesCount = info->animation->totalFrame();
delete info;
return (jlong) frameCount;
return (jlong) framesCount;
}

JNIEXPORT jdouble Java_org_telegram_ui_Components_RLottieDrawable_getDuration(JNIEnv *env, jclass clazz, jstring src, jstring json) {
auto info = new LottieInfo();
char const *srcString = env->GetStringUTFChars(src, nullptr);
info->path = srcString;
if (json != nullptr) {
char const *jsonString = env->GetStringUTFChars(json, nullptr);
if (jsonString) {
info->animation = rlottie::Animation::loadFromData(jsonString, info->path, nullptr, FitzModifier::None);
env->ReleaseStringUTFChars(json, jsonString);
}
} else {
info->animation = rlottie::Animation::loadFromFile(info->path, nullptr, FitzModifier::None);
}
if (srcString) {
env->ReleaseStringUTFChars(src, srcString);
}
if (info->animation == nullptr) {
delete info;
return 0;
}
double duration = info->animation->duration();
delete info;
return (jdouble) duration;
}

JNIEXPORT jlong Java_org_telegram_ui_Components_RLottieDrawable_createWithJson(JNIEnv *env, jclass clazz, jstring json, jstring name, jintArray data, jintArray colorReplacement) {
Expand Down
23 changes: 18 additions & 5 deletions TMessagesProj/jni/webm_encoder.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,9 @@ JNIEXPORT jlong JNICALL Java_org_telegram_messenger_video_WebmEncoder_createEnco
ctx->codec_ctx->time_base = (AVRational){ 1, fps };
ctx->codec_ctx->framerate = (AVRational){ fps, 1 };
ctx->codec_ctx->bit_rate = bitrate;
ctx->codec_ctx->gop_size = 10;
ctx->codec_ctx->max_b_frames = 1;
ctx->codec_ctx->rc_min_rate = bitrate / 8;
ctx->codec_ctx->rc_max_rate = bitrate;
// ctx->codec_ctx->rc_buffer_size = 2 * bitrate;

if (ctx->fmt_ctx->oformat->flags & AVFMT_GLOBALHEADER) {
ctx->codec_ctx->flags |= AV_CODEC_FLAG_GLOBAL_HEADER;
Expand Down Expand Up @@ -185,6 +186,9 @@ JNIEXPORT jboolean JNICALL Java_org_telegram_messenger_video_WebmEncoder_writeFr
pkt.stream_index = ctx->video_stream->index;

ret = av_interleaved_write_frame(ctx->fmt_ctx, &pkt);
if (ret < 0) {
LOGE("vp9: failed to av_interleaved_write_frame %d", ret);
}
av_packet_unref(&pkt);
}

Expand All @@ -200,13 +204,16 @@ JNIEXPORT void JNICALL Java_org_telegram_messenger_video_WebmEncoder_stop(
return;
}

avcodec_send_frame(ctx->codec_ctx, NULL);
int ret;
ret = avcodec_send_frame(ctx->codec_ctx, NULL);
if (ret < 0) {
LOGE("vp9: failed to avcodec_send_frame %d", ret);
}
AVPacket pkt;
av_init_packet(&pkt);
pkt.data = NULL;
pkt.size = 0;

int ret;
while (1) {
ret = avcodec_receive_packet(ctx->codec_ctx, &pkt);
if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF) {
Expand All @@ -220,10 +227,16 @@ JNIEXPORT void JNICALL Java_org_telegram_messenger_video_WebmEncoder_stop(
pkt.stream_index = ctx->video_stream->index;

ret = av_interleaved_write_frame(ctx->fmt_ctx, &pkt);
if (ret < 0) {
LOGE("vp9: failed to av_interleaved_write_frame %d", ret);
}
av_packet_unref(&pkt);
}

av_write_trailer(ctx->fmt_ctx);
ret = av_write_trailer(ctx->fmt_ctx);
if (ret < 0) {
LOGE("vp9: failed to av_write_trailer %d", ret);
}

if (ctx->frame) {
av_frame_free(&ctx->frame);
Expand Down
Binary file modified TMessagesProj/src/main/assets/models/coin_border.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
144 changes: 62 additions & 82 deletions TMessagesProj/src/main/assets/shaders/fragment3.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -27,102 +27,82 @@ uniform float time;
uniform mat4 world;

void main() {
vec3 vLightPosition2 = vec3(-400, 40, 400);
vec3 vLightPosition3 = vec3(0, 200, 400);
vec3 vLightPosition4 = vec3(0, 0, 100);
vec3 vLightPositionNormal = vec3(100, -200, 400);

vec3 vNormalW = normalize(vec3(world * vec4(vNormal, 0.0)));
vec3 vTextureNormal = normalize(texture2D(u_NormalMap, vUV + vec2(-f_xOffset, f_xOffset)).xyz * 2.0 - 1.0);
vec3 finalNormal = normalize(vNormalW + vTextureNormal);

vec3 color = texture2D(u_Texture, vUV).xyz;
vec3 viewDirectionW = normalize(cameraPosition - modelViewVertex);

float border = 0.0;
if (modelIndex == 0) {
border = 1.0;
} else if (modelIndex == 2) {
border = texture2D(u_Texture, vUV).a;
}

float modelDiffuse = 0.1;
if (!night && modelIndex != 1) {
modelDiffuse = 0.01;
}
float diffuse = max(dot(vNormalW, viewDirectionW), (1.0 - modelDiffuse));

vec2 uv = vUV;
if (modelIndex == 2) {
uv *= 2.0;
uv = fract(uv);
if (vUV.x > .5) {
uv.x = 1.0 - uv.x;
}
}
float mixValue = clamp(distance(uv.xy, vec2(0.0)), 0.0, 1.0);
vec4 gradientColorFinal = vec4(mix(gradientColor1, gradientColor2, mixValue), 1.0);

float modelNormalSpec = normalSpec, modelSpec1 = 0.0, modelSpec2 = 0.05;
uv.x = 1.0 - uv.x;

float darken = 1. - length(modelViewVertex - vec3(30., -75., 50.)) / 200.;

if (border > 0.) {
modelNormalSpec += border;
modelSpec1 += border;
modelSpec2 += border;
float diagonal = ((uv.x + uv.y) / 2.0 - .15) / .6;
vec3 baseColor;
if (modelIndex == 0) {
baseColor = mix(
vec3(0.95686, 0.47451, 0.93725),
vec3(0.46274, 0.49411, 0.9960),
diagonal
);
} else if (modelIndex == 3) {
baseColor = mix(
vec3(0.95686, 0.47451, 0.93725),
vec3(0.46274, 0.49411, 0.9960),
diagonal
);
baseColor = mix(baseColor, vec3(1.0), .3);
} else if (modelIndex == 1) {
baseColor = mix(
vec3(0.67059, 0.25490, 0.80000),
vec3(0.39608, 0.18824, 0.98039),
diagonal
);
} else {
baseColor = mix(
vec3(0.91373, 0.62353, 0.99608),
vec3(0.67451, 0.58824, 1.00000),
clamp((uv.y - .2) / .6, 0.0, 1.0)
);

baseColor = mix(baseColor, vec3(1.0), .1 + .45 * texture2D(u_Texture, vUV).a);
if (night) {
baseColor = mix(baseColor, vec3(.0), .06);
}
}

vec3 pos = modelViewVertex / 100.0 + .5;
vec3 norm = normalize(vec3(world * vec4(vNormal, 0.0)));

vec3 angleW = normalize(viewDirectionW + vLightPosition2);
float specComp2 = max(0., dot(finalNormal, angleW));
specComp2 = pow(specComp2, max(1., 128.)) * modelSpec1;
vec3 flecksLightPos = vec3(.5, .5, .5);
vec3 flecksLightDir = normalize(flecksLightPos - pos);
vec3 flecksReflectDir = reflect(-flecksLightDir, norm);
float flecksSpec = pow(max(dot(normalize(vec3(0.0) - pos), flecksReflectDir), 0.0), 8.0);
vec3 flecksNormal = normalize(texture2D(u_NormalMap, uv * 1.3 + vec2(.02, .06) * time).xyz * 2.0 - 1.0);
float flecks = max(flecksNormal.x, flecksNormal.y) * flecksSpec;
norm += flecksSpec * flecksNormal;
norm = normalize(norm);

angleW = normalize(viewDirectionW + vLightPosition4);
float specComp3 = max(0., dot(finalNormal, angleW));
specComp3 = pow(specComp3, max(1., 30.)) * modelSpec2;
vec3 lightPos = vec3(-3., -3., 20.);
vec3 lightDir = normalize(lightPos - pos);
float diffuse = max(dot(norm, lightDir), 0.0);

angleW = normalize(viewDirectionW + vLightPositionNormal);
float normalSpecComp = max(0., dot(finalNormal, angleW));
normalSpecComp = pow(normalSpecComp, max(1., 128.)) * modelNormalSpec;
float spec = 0.0;

angleW = normalize(viewDirectionW + vLightPosition2);
float normalSpecComp2 = max(0., dot(finalNormal, angleW));
normalSpecComp2 = pow(normalSpecComp2, max(1., 128.)) * modelNormalSpec;
lightPos = vec3(-3., -3., .5);
spec += 2.0 * pow(max(dot(normalize(vec3(0.0) - pos), reflect(-normalize(lightPos - pos), norm)), 0.0), 2.0);

vec4 normalSpecFinal = vec4(normalSpecColor, 0.0) * normalSpecComp2;
vec4 specFinal = vec4(color, 0.0) * (specComp2 + specComp3);
lightPos = vec3(-3., .5, 30.);
spec += (modelIndex == 1 ? 1.5 : 0.5) * pow(max(dot(normalize(vec3(0.0) - pos), reflect(-normalize(lightPos - pos), norm)), 0.0), 32.0);

// float snap = fract((-gl_FragCoord.x / resolution.x + gl_FragCoord.y / resolution.y) / 20.0 + .2 * time) > .9 ? 1. : 0.;
// lightPos = vec3(3., .5, .5);
// spec += pow(max(dot(normalize(vec3(0.0) - pos), reflect(-normalize(lightPos - pos), norm)), 0.0), 32.0);

vec4 fragColor = gradientColorFinal + specFinal;
vec4 backgroundColor = texture2D(u_BackgroundTexture, vec2(gradientPosition.x + (gl_FragCoord.x / resolution.x) * gradientPosition.y, gradientPosition.z + (1.0 - (gl_FragCoord.y / resolution.y)) * gradientPosition.w));
vec4 color4 = mix(backgroundColor, fragColor, diffuse);
if (night) {
angleW = normalize(viewDirectionW + vLightPosition2);
float normalSpecComp = max(0., dot(finalNormal, angleW));
normalSpecComp = pow(normalSpecComp, max(1., 128.));
if (normalSpecComp > .2 && modelIndex != 0) {
color4.rgb += vec3(.5) * max(0., vTextureNormal.x) * normalSpecComp;
}
if (modelIndex == 1) {
color4.rgb *= .9;
} else {
color4.rgb += vec3(1.0) * .17;
}
} else {
if (modelIndex == 1) {
if (darken > .5) {
color4.rgb *= vec3(0.78039, 0.77254, 0.95294);
} else {
color4.rgb *= vec3(0.83921, 0.83529, 0.96862);
}
} else {
if (darken > .5) {
color4.rgb *= vec3(.945098, .94117, 1.0);
color4.rgb += vec3(.06) * border;
}
}
if (modelIndex != 0) {
spec *= .25;
}
gl_FragColor = color4 * f_alpha;

vec3 color = baseColor;
color *= .94 + .22 * diffuse;
color = mix(color, vec3(1.0), spec);
// color = mix(color, vec3(1.0), 0.35 * flecks);

gl_FragColor = vec4(color, 1.0);
}
Loading

0 comments on commit 69811d4

Please sign in to comment.