Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
a02f756
gpu: portable shader graphs (ShaderNode/ShaderMaterial) on every backend
shai-almog Nov 13, 2026
c9b7ed1
gpu: normal, detail, occlusion, emissive and metal-rough maps; analyt…
shai-almog Nov 13, 2026
4e50ea1
gpu: shader library (com.codename1.gpu.shaders), scene presets, Primi…
shai-almog Nov 13, 2026
5b9bba6
gpu: god rays, chromatic aberration and FXAA; instancing; a running s…
shai-almog Nov 13, 2026
cd36219
hellocodenameone: shader library screenshot tests (harbour scene, gal…
shai-almog Nov 13, 2026
1999d31
docs: custom shaders, the shader library, presets and instancing in t…
shai-almog Nov 13, 2026
eebd5a6
docs: re-capture the Splat screenshots with the shader library materials
shai-almog Nov 13, 2026
490ed54
gpu: shadow casters run their custom shader's vertex offset and discard
shai-almog Nov 13, 2026
ec525de
website: re-record the Splat videos and posters
shai-almog Nov 13, 2026
08ce0a3
gpu: two shadow cascades on every backend
shai-almog Nov 13, 2026
43e9b8b
gpu: image based lighting on every backend
shai-almog Nov 13, 2026
fee8cfd
gpu: render targets on every backend
shai-almog Nov 13, 2026
95da35c
gpu: depth post effects and colour lookup on every backend
shai-almog Nov 13, 2026
bf809c6
gpu: close the macOS shadow-pass stub so the render-target stubs are …
shai-almog Nov 13, 2026
77c5923
gpu: skinning in the vertex stage on every backend
shai-almog Nov 13, 2026
926ba92
gpu: custom full screen passes in the post chain on every backend
shai-almog Nov 13, 2026
58eb529
website: re-record the Splat release demos with the new GPU features
shai-almog Nov 13, 2026
86887aa
gpu: AnimatedModel.getBounds, scalar lowering, logged pass drops; rec…
shai-almog Nov 13, 2026
09f8bc7
port status: register the GPU shader tests; regenerate the embedded s…
shai-almog Nov 13, 2026
d9bfeac
gpu: CI fixes - CLDC-safe math, headers, docs gates, released-API sam…
shai-almog Nov 14, 2026
e6b44c9
gpu tests: wait for rendered frames before capture; seed remaining go…
shai-almog Nov 14, 2026
bbeb014
ci: seed Windows Gpu goldens, include-only guide snippets, rebaseline…
shai-almog Nov 14, 2026
165cb28
docs: accept 'toon' in the developer guide
shai-almog Nov 14, 2026
b34c36d
docs: GPU shader fragments get no Playground button
shai-almog Nov 14, 2026
1d2d78c
initializr: resync the Splat template after restoring ArenaView
shai-almog Nov 14, 2026
9823366
Merge remote-tracking branch 'origin/master' into gpu-shader-nodes
shai-almog Nov 14, 2026
2fb7691
android: filePath is read from an inner class, so it must be final fo…
shai-almog Nov 14, 2026
2d8976a
gpu: Metal stride parse skips shader key segments; JS-safe frame gate…
shai-almog Nov 14, 2026
abf239c
gpu tests: one render request per frame in the frame gate
shai-almog Nov 14, 2026
978cfe0
ci: seed Gpu goldens for iOS Metal 27 and Mac Catalyst
shai-almog Nov 15, 2026
a8753ad
Merge remote-tracking branch 'origin/master' into gpu-shader-nodes
shai-almog Nov 15, 2026
76c2456
Merge remote-tracking branch 'origin/master' into gpu-shader-nodes
shai-almog Nov 15, 2026
ea56630
hellocodenameone: frame-gated GPU tests get the native budget on HTML5
shai-almog Nov 15, 2026
5e3c143
Merge remote-tracking branch 'origin/master' into gpu-shader-nodes
shai-almog Nov 15, 2026
ea7b709
ci: seed iOS Metal and tvOS gpu goldens; raise test server WS message…
shai-almog Nov 15, 2026
0439e29
Merge remote-tracking branch 'origin/master' into gpu-shader-nodes
shai-almog Nov 15, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ on:
# Same: the builder define-toggle lint runs from this workflow and nowhere else.
- 'scripts/check-builder-define-toggles.py'
- 'scripts/check-cast-semantics.sh'
- 'scripts/check-gpu-shaders.sh'
- 'scripts/gpu-shader-check/**'
- 'scripts/cast-semantics-baseline.txt'
# The build hint gates are run from this workflow and nowhere else, and one
# of them holds an empty baseline. Ignoring the whole directory meant a
Expand Down Expand Up @@ -111,6 +113,8 @@ on:
# Same: the builder define-toggle lint runs from this workflow and nowhere else.
- 'scripts/check-builder-define-toggles.py'
- 'scripts/check-cast-semantics.sh'
- 'scripts/check-gpu-shaders.sh'
- 'scripts/gpu-shader-check/**'
- 'scripts/cast-semantics-baseline.txt'
# The build hint gates are run from this workflow and nowhere else, and one
# of them holds an empty baseline. Ignoring the whole directory meant a
Expand Down Expand Up @@ -525,6 +529,16 @@ jobs:
mvn -B -q -f maven/pom.xml -pl windows,linux -am -DskipTests \
-Dcn1.binaries="${CN1_BINARIES}" compile
scripts/check-native-signatures.sh --require-all
# Every shader of com.codename1.gpu.shaders and the post composite,
# through a real GLSL ES 100 compiler and an HLSL one (glslang, via
# SPIR-V). A generator change that prints code a GPU rejects otherwise
# shows only as a model that silently does not draw on that device.
# Metal is checked by the same script on macOS.
- name: Compile the GPU shader library with real compilers
if: ${{ matrix.java-version == 8 }}
run: |
command -v glslangValidator >/dev/null || (sudo apt-get update && sudo apt-get install -y glslang-tools)
scripts/check-gpu-shaders.sh
# Linkage, which the signature gate above cannot see: it verifies that a
# native's NAME matches its Java method, and a mangled C++ symbol has the
# right name too. Needs no compiler and no build output, so it sits on its
Expand Down
133 changes: 131 additions & 2 deletions CodenameOne/src/com/codename1/gaming/AnimatedModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@ public class AnimatedModel {
private final float[] rot = new float[16];
private final float[] skinMatrix = new float[16];
private final float[] jointMatrices;
// GPU skinning: per skin, the joint rows its parts' materials read
// (Material.setSkinning); null when the device skins on the CPU
private final float[][] skinRows;
private final float[] key = new float[4];

private GltfScene.Animation clip;
Expand Down Expand Up @@ -161,13 +164,30 @@ public AnimatedModel(GraphicsDevice device, GltfScene scene) {
maxJoints = Math.max(maxJoints, scene.getSkin(i).getJoints().length);
}
jointMatrices = new float[maxJoints * 16];
boolean gpu = maxJoints > 0 && maxJoints <= Material.MAX_JOINTS && device.isGpuSkinning();
if (gpu) {
skinRows = new float[scene.getSkinCount()][];
for (int i = 0; i < skinRows.length; i++) {
skinRows[i] = new float[Math.max(1, scene.getSkin(i).getJoints().length) * 12];
}
} else {
skinRows = null;
}

int count = scene.getPrimitiveCount();
parts = new Model[count];
hidden = new boolean[count];
for (int i = 0; i < count; i++) {
GltfScene.Primitive p = scene.getPrimitive(i);
VertexBuffer vb = new VertexBuffer(VertexFormat.POSITION_NORMAL_TEXCOORD, p.getVertexCount());
int skinIndex = gpu && p.isSkinned() ? scene.getNode(p.getNode()).getSkin() : -1;
VertexBuffer vb;
if (skinIndex >= 0) {
vb = new VertexBuffer(VertexFormat.SKINNED, p.getVertexCount());
writeBindPose(p, scene.getSkin(skinIndex).getJoints().length, vb.getData());
vb.setDirty();
} else {
vb = new VertexBuffer(VertexFormat.POSITION_NORMAL_TEXCOORD, p.getVertexCount());
}
IndexBuffer ib = new IndexBuffer(p.getIndices().length);
ib.setData(p.getIndices());
Material material = new Material(Material.Type.LAMBERT);
Expand All @@ -181,6 +201,7 @@ public AnimatedModel(GraphicsDevice device, GltfScene scene) {
if (t != null) {
material.setTexture(t);
}
info.applyMaps(scene, device, material);
if (info.isDoubleSided()) {
state.setCullMode(RenderState.CullMode.NONE);
}
Expand All @@ -189,6 +210,10 @@ public AnimatedModel(GraphicsDevice device, GltfScene scene) {
}
}
material.setRenderState(state);
if (skinIndex >= 0) {
float[] rows = skinRows[skinIndex];
material.setSkinning(rows, rows.length / 12);
}
parts[i] = new Model(new Mesh(vb, ib, PrimitiveType.TRIANGLES), material);
}
pose();
Expand All @@ -214,10 +239,63 @@ public GltfScene getScene() {
}

/// The models that draw this instance, one per primitive.
///
/// Do not measure a pose from their vertex buffers: where the device
/// skins on the GPU (`GraphicsDevice.isGpuSkinning`) a skinned part's
/// buffer is `VertexFormat.SKINNED` and holds the bind pose, and the pose
/// is applied in the vertex stage. `getBounds` measures the pose on every
/// device.
public Model[] getParts() {
return parts;
}

/// The bounds of the current pose in the model's own space, node
/// transforms and skinning applied, over the visible parts:
/// `minX, minY, minZ, maxX, maxY, maxZ`. It poses the model first and gives
/// the same answer whether the device skins on the GPU or the CPU.
///
/// #### Returns
///
/// a new array of six floats, or null when no part is visible
public float[] getBounds() {
pose();
float[] b = {Float.MAX_VALUE, Float.MAX_VALUE, Float.MAX_VALUE,
-Float.MAX_VALUE, -Float.MAX_VALUE, -Float.MAX_VALUE};
VertexBuffer scratch = null;
int skinned = -1;
for (int i = 0; i < parts.length; i++) {
if (hidden[i] || !parts[i].isVisible()) {
continue;
}
GltfScene.Primitive p = scene.getPrimitive(i);
VertexBuffer vb = parts[i].getMesh().getVertices();
int skin = scene.getNode(p.getNode()).getSkin();
if (skinRows != null && p.isSkinned() && skin >= 0) {
// the buffer is the bind pose: skin a copy on the CPU to measure it
if (skinned != skin) {
computeJoints(scene.getSkin(skin));
skinned = skin;
}
if (scratch == null || scratch.getVertexCount() < p.getVertexCount()) {
scratch = new VertexBuffer(VertexFormat.POSITION_NORMAL_TEXCOORD, p.getVertexCount());
}
skin(p, scratch);
vb = scratch;
}
float[] d = vb.getData();
int stride = vb.getFormat().getStrideBytes() / 4;
int count = p.getVertexCount();
for (int v = 0; v < count; v++) {
int o = v * stride;
for (int k = 0; k < 3; k++) {
b[k] = Math.min(b[k], d[o + k]);
b[k + 3] = Math.max(b[k + 3], d[o + k]);
}
}
}
return b[0] > b[3] ? null : b;
}

/// Adds every part to `view`.
public void addTo(GameView view) {
for (Model part : parts) {
Expand Down Expand Up @@ -507,9 +585,14 @@ public void pose() {
if (p.isSkinned() && skin >= 0) {
if (skinned != skin) {
computeJoints(scene.getSkin(skin));
if (skinRows != null) {
writeRows(scene.getSkin(skin).getJoints().length, skinRows[skin]);
}
skinned = skin;
}
skin(p, parts[i].getMesh().getVertices());
if (skinRows == null) {
skin(p, parts[i].getMesh().getVertices());
}
} else {
rigid(p, p.getNode(), parts[i].getMesh().getVertices());
}
Expand Down Expand Up @@ -650,6 +733,52 @@ private static void multiplyInto(float[] a, int ao, float[] b, int bo, float[] d
}
}

// The first three rows of each joint matrix (column major), the layout
// Material.setSkinning takes.
private void writeRows(int joints, float[] rows) {
for (int j = 0; j < joints; j++) {
int o = j * 16;
int d = j * 12;
for (int row = 0; row < 3; row++) {
rows[d + row * 4] = jointMatrices[o + row];
rows[d + row * 4 + 1] = jointMatrices[o + 4 + row];
rows[d + row * 4 + 2] = jointMatrices[o + 8 + row];
rows[d + row * 4 + 3] = jointMatrices[o + 12 + row];
}
}
}

// A GPU skinned part's buffer never changes: the bind pose with its
// joints and weights, in VertexFormat.SKINNED. A joint outside the skin
// loses its weight, as the CPU path skips it.
private static void writeBindPose(GltfScene.Primitive p, int jointCount, float[] out) {
float[] pos = p.getPositions();
float[] nor = p.getNormals();
float[] uv = p.getTexcoords();
int[] joints = p.getJoints();
float[] weights = p.getWeights();
int count = p.getVertexCount();
for (int v = 0; v < count; v++) {
int o = v * 16;
out[o] = pos[v * 3];
out[o + 1] = pos[v * 3 + 1];
out[o + 2] = pos[v * 3 + 2];
out[o + 3] = nor[v * 3];
out[o + 4] = nor[v * 3 + 1];
out[o + 5] = nor[v * 3 + 2];
if (uv != null) {
out[o + 6] = uv[v * 2];
out[o + 7] = uv[v * 2 + 1];
}
for (int k = 0; k < 4; k++) {
int j = joints[v * 4 + k];
boolean ok = j >= 0 && j < jointCount;
out[o + 8 + k] = ok ? j : 0;
out[o + 12 + k] = ok ? weights[v * 4 + k] : 0f;
}
}
}

private void skin(GltfScene.Primitive p, VertexBuffer vb) {
float[] pos = p.getPositions();
float[] nor = p.getNormals();
Expand Down
58 changes: 58 additions & 0 deletions CodenameOne/src/com/codename1/gaming/Model.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@ public class Model {
private final float[] scratchA = new float[16];
private final float[] scratchB = new float[16];
private final float[] matrix = new float[16];
private float[] instances;
private int[] instanceColors;
private int instanceCount;
private float[] worldInstances;
private final float[] one = new float[16];
private final float[] oneWorld = new float[16];

/// Creates a model for the given mesh with a default unlit white material.
public Model(Mesh mesh) {
Expand Down Expand Up @@ -176,4 +182,56 @@ public Object getUserData() {
public void setUserData(Object userData) {
this.userData = userData;
}

/// Draws this model as many copies, each placed by its own transform
/// relative to the model's position, rotation and scale: a stack of
/// crates, a row of lamp posts, a field of grass from one blade. The
/// arrays are read every frame, so moving the copies is writing new
/// values into them; they are not copied.
///
/// #### Parameters
///
/// - `matrices`: 16 column-major floats per copy, or null to draw the
/// model once again
///
/// - `colors`: an ARGB colour per copy for `ShaderNode.instanceColor`,
/// or null for white
///
/// - `count`: how many copies to draw
///
/// #### Returns
///
/// this model
public Model setInstances(float[] matrices, int[] colors, int count) {
if (matrices != null && matrices.length < count * 16) {
throw new IllegalArgumentException("Need " + count * 16 + " floats for " + count + " copies");
}
this.instances = matrices;
this.instanceColors = colors;
this.instanceCount = matrices == null ? 0 : count;
return this;
}

/// Returns how many copies `setInstances` asked for, 0 for a single model.
public int getInstanceCount() {
return instanceCount;
}

int[] instanceColors() {
return instanceColors;
}

/// The copies' world transforms for this frame, reused between calls.
float[] instanceMatrices() {
float[] base = modelMatrix();
if (worldInstances == null || worldInstances.length < instanceCount * 16) {
worldInstances = new float[instanceCount * 16];
}
for (int i = 0; i < instanceCount; i++) {
System.arraycopy(instances, i * 16, one, 0, 16);
Matrix4.multiply(base, one, oneWorld);
System.arraycopy(oneWorld, 0, worldInstances, i * 16, 16);
}
return worldInstances;
}
}
22 changes: 21 additions & 1 deletion CodenameOne/src/com/codename1/gaming/SpriteRenderer.java
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,8 @@ public void onResize(GraphicsDevice device, int width, int height) {
device.setViewport(0, 0, width, height);
}

private float shaderClock;

@Override
public void onFrame(GraphicsDevice device) {
long now = System.currentTimeMillis();
Expand All @@ -307,6 +309,13 @@ public void onFrame(GraphicsDevice device) {
updatable.frame(dt);
}
scene.update(dt);
// the clock animated shaders read; wrapped hourly so a float keeps
// sub-millisecond precision in a session that runs for days
shaderClock += (float) dt;
if (shaderClock > 3600f) {
shaderClock -= 3600f;
}
device.setTime(shaderClock);
if (!released.isEmpty()) {
disposeReleased(device);
}
Expand All @@ -330,6 +339,12 @@ public void onFrame(GraphicsDevice device) {
for (int i = 0; i < modelCount; i++) {
Model m = (Model) models.get(i);
if (m.isVisible() && m.getMesh() != null && m.getMaterial().isCastShadows()) {
if (m.getInstanceCount() > 0) {
// copies spread past the model's own position; cull none
device.drawInstanced(m.getMesh(), m.getMaterial(), m.instanceMatrices(),
m.instanceColors(), m.getInstanceCount());
continue;
}
float[] mm = m.modelMatrix();
float dx = mm[12] - cx;
float dz = mm[14] - cz;
Expand All @@ -349,7 +364,12 @@ public void onFrame(GraphicsDevice device) {
for (int i = 0; i < modelCount; i++) {
Model m = (Model) models.get(i);
if (m.isVisible() && m.getMesh() != null) {
device.draw(m.getMesh(), m.getMaterial(), m.modelMatrix());
if (m.getInstanceCount() > 0) {
device.drawInstanced(m.getMesh(), m.getMaterial(), m.instanceMatrices(),
m.instanceColors(), m.getInstanceCount());
} else {
device.draw(m.getMesh(), m.getMaterial(), m.modelMatrix());
}
}
}

Expand Down
23 changes: 23 additions & 0 deletions CodenameOne/src/com/codename1/gpu/Camera.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,19 @@
* published by the Free Software Foundation. Codename One designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Codename One through http://www.codenameone.com/ if you
* need additional information or have any questions.
*/
package com.codename1.gpu;

Expand Down Expand Up @@ -138,6 +151,16 @@ public float getEyeZ() {
return eyeZ;
}

/// Returns the distance to the near clip plane.
public float getNear() {
return near;
}

/// Returns the distance to the far clip plane.
public float getFar() {
return far;
}

/// Returns the 16 element column-major view matrix.
public float[] getViewMatrix() {
recompute();
Expand Down
Loading
Loading