Skip to content

Instantly share code, notes, and snippets.

View nahkd123's full-sized avatar

An nahkd123

View GitHub Profile
@nahkd123
nahkd123 / README.md
Created May 19, 2024 18:24
2D Sprite with Normal map

2D Sprite + Normal map

Get the nice looking 2D sprite with some 3D lightning effects on it through the power of normal maps!

image

To try it, go to https://glsl.app/#~c4wr7h4l5n7i040yt4r29vp0 Make sure to upload the assets below! Or you can copy the fragment shader below.

Assets

Base color map Normal map Emission map
@nahkd123
nahkd123 / Expression.java
Created April 2, 2024 17:48
450 lines math expression engine
/*
* (c) Tran Huu An 2024. Licensed under MIT license.
*/
import java.io.Serial;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.function.DoubleBinaryOperator;
import java.util.function.DoubleUnaryOperator;
import java.util.regex.Matcher;
@nahkd123
nahkd123 / ServerSide_SetCameraEntityS2CPacket.md
Last active April 2, 2024 07:07
The "SetCameraEntityS2CPacket" trick

The SetCameraEntityS2CPacket trick

What is this?

SetCameraEntityS2CPacket is a clientbound packet that will be sent to client when player interacts an entity while in spectator mode. This packet is mainly used for setting the player's camera to entity's position.

The jank: Not in spectator mode

But what if we send SetCameraEntityS2CPacket when player is NOT in spectator mode? Surprisingly, player didn't kick themselves from server, plus their camera is now attached to target entity! The camera behavior is what you would normally expect like spectating mob the normal way (eg: hide hotbars, add linear interpolation to camera). Setting the camera to self (self as in the player whose connection handler is controlling) returns everything to normal. I haven't tested what happens when you set the camera to other players.

Another jank: Player's input

While the camera is attached to another entity, player's input like moving, sneaking, jumping and looking around will still working normally. You can

@nahkd123
nahkd123 / README.md
Created March 26, 2024 14:55
Can we write a better WebGPU Shading Language specification?

Can we write a better WebGPU Shading Language specification?

Yes, maybe...

fragment.wgsl is the example WGSL (WebGPU Shading Language) coed found in the official specification. fragment.nwgsl (NGLSL stands for "Not WebGPU Shading Language") is the exact same fragment shader as fragment.wgsl, except small changes to the language.

@nahkd123
nahkd123 / gift_and_destroy.js
Last active January 4, 2022 12:50
Gift and Destroy (DF plugin)
// Gift and Destroy
// Gift then destroy planets
let createElement = (type, text = "", className = "") => {
let e = document.createElement(type);
e.textContent = text;
e.className = className;
return e;
};
let createButton = (text = "") => {