Skip to content

A fast 2D and 3D game engine — TypeScript SDK, C++/WebAssembly core, visual editor. Ship one project to web, desktop, WeChat MiniGames, playable ads, and native Android / iOS.

1.1 KB
Raw Blame
#pragma shader "PrepassHook"
#pragma version 300 es
#pragma domain Lit
#pragma param u_lift texture default(black)
#pragma param u_liftBy float default(40)
#pragma param u_tint color default(0,1,0,1)

// A vertex hook that reads a texture, as the terrain's does: it lifts a vertex toward the eye by what the texel says. The texture is black, so
// nothing is lifted — unless a program reads another unit's texture for it (the mesh's own is white), which lifts the depth a prepass writes off
// the depth the colour pass lands on, and the cube is not drawn at all.
#pragma vertexoffset
void esMaterialVertex(inout vec3 local, inout vec3 localNormal, in vec2 uv) {
    local.z += texelFetch(u_lift, ivec2(0), 0).r * u_liftBy;
}
#pragma end

#pragma vertexoffset wgsl
fn esMaterialVertex(local : ptr<function, vec3f>, localNormal : ptr<function, vec3f>, uv : vec2f) {
    (*local).z = (*local).z + textureLoad(u_lift, vec2i(0), 0).r * mc.u_liftBy;
}
#pragma end

#pragma fragment
precision mediump float;

in vec4 v_color;
in vec2 v_texCoord;

out vec4 fragColor;

void main() {
    fragColor = vec4(u_tint.rgb, 1.0);
}
#pragma end