Skip to content

Commit

Permalink
refactor: Cleanup lighting code and remove unused Standard Material (#…
Browse files Browse the repository at this point in the history
…3179)

Cleanup lighting code and remove unused Standard Material.
  • Loading branch information
luanpotter committed Jul 9, 2024
1 parent 140a631 commit db1465f
Show file tree
Hide file tree
Showing 18 changed files with 32 additions and 154 deletions.
4 changes: 4 additions & 0 deletions .github/.cspell/gamedev_dictionary.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ goldens # test files used as reference for Golden Tests
hitbox # the collision box around objects for the purposes of collision detection
hitboxes # plural of hitbox
ints # short for integers
impellerc # Flutter's impeller compiler
jank # stutter or inconsistent gap or timing
lerp # short for linear interpolation
LTRB # left top right bottom
Expand All @@ -49,15 +50,18 @@ respawn # when the player character dies and is brought back after some time and
retarget # to direct (something) toward a different target
RGBA # red green blue alpha
RGBO # red green blue opacity
BGRA # blue green red alpha
rrect # rounded rect
scos # cosine of a rotation multiplied by the scale factor
shaderbundle # a file extension used to bundle shaders for GLSL
spritesheet # a single image packing multiple sprites, normally in a grid
ssin # sine of a rotation multiplied by the scale factor
stylesheet # name of a CSS style file
subfolders # plural of subfolders
sublist # any sub-set of elements of a given list
sublists # plural of sublist
subrange # a range entirely contained on a given range
struct # a type of data model in programming that aggregates fields
SVGs # plural of SVG
tileset # image with a collection of tiles. in games, tiles are small square sprites laid out in a grid to form the game map
tilesets # plural of tileset
Expand Down
1 change: 1 addition & 0 deletions .github/.cspell/people_usernames.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# specific people's names and/or usernames
akida # github.com/akida
bdero # github.com/bdero
bluefireteam # github.com/bluefireteam
erayzesen # erayzesen.itch.io
erickzanardo # github.com/erickzanardo
Expand Down
2 changes: 1 addition & 1 deletion packages/flame_3d/example/lib/crate.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class Crate extends MeshComponent {
@override
FutureOr<void> onLoad() async {
final crateTexture = await Flame.images.loadTexture('crate.jpg');
mesh.addMaterialToSurface(0, StandardMaterial(albedoTexture: crateTexture));
mesh.addMaterialToSurface(0, SpatialMaterial(albedoTexture: crateTexture));
}

double direction = 0.1;
Expand Down
13 changes: 6 additions & 7 deletions packages/flame_3d/example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class ExampleGame3D extends FlameGame<World3D>
position: Vector3(5, 5, 5),
mesh: SphereMesh(
radius: 1,
material: StandardMaterial(
material: SpatialMaterial(
albedoTexture: ColorTexture(Colors.purple),
),
),
Expand All @@ -56,7 +56,7 @@ class ExampleGame3D extends FlameGame<World3D>
MeshComponent(
mesh: PlaneMesh(
size: Vector2(32, 32),
material: StandardMaterial(albedoTexture: ColorTexture(Colors.grey)),
material: SpatialMaterial(albedoTexture: ColorTexture(Colors.grey)),
),
),

Expand All @@ -65,8 +65,7 @@ class ExampleGame3D extends FlameGame<World3D>
position: Vector3(16.5, 2.5, 0),
mesh: CuboidMesh(
size: Vector3(1, 5, 32),
material:
StandardMaterial(albedoTexture: ColorTexture(Colors.yellow)),
material: SpatialMaterial(albedoTexture: ColorTexture(Colors.yellow)),
),
),

Expand All @@ -75,7 +74,7 @@ class ExampleGame3D extends FlameGame<World3D>
position: Vector3(0, 2.5, 16.5),
mesh: CuboidMesh(
size: Vector3(32, 5, 1),
material: StandardMaterial(albedoTexture: ColorTexture(Colors.blue)),
material: SpatialMaterial(albedoTexture: ColorTexture(Colors.blue)),
),
),

Expand All @@ -84,7 +83,7 @@ class ExampleGame3D extends FlameGame<World3D>
position: Vector3(0, 2.5, -16.5),
mesh: CuboidMesh(
size: Vector3(32, 5, 1),
material: StandardMaterial(albedoTexture: ColorTexture(Colors.lime)),
material: SpatialMaterial(albedoTexture: ColorTexture(Colors.lime)),
),
),
]);
Expand All @@ -98,7 +97,7 @@ class ExampleGame3D extends FlameGame<World3D>
position: Vector3(rnd.range(-15, 15), height / 2, rnd.range(-15, 15)),
mesh: CuboidMesh(
size: Vector3(1, height, 1),
material: StandardMaterial(
material: SpatialMaterial(
albedoTexture: ColorTexture(
Color.fromRGBO(rnd.iRange(20, 255), rnd.iRange(10, 55), 30, 1),
),
Expand Down
2 changes: 1 addition & 1 deletion packages/flame_3d/example/lib/player_box.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class PlayerBox extends MeshComponent with HasGameReference<ExampleGame3D> {
mesh: CuboidMesh(
size: Vector3.all(0.5),
material:
StandardMaterial(albedoTexture: ColorTexture(Colors.purple)),
SpatialMaterial(albedoTexture: ColorTexture(Colors.purple)),
),
);

Expand Down
10 changes: 2 additions & 8 deletions packages/flame_3d/lib/src/camera/world_3d.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import 'dart:ui';

import 'package:flame/components.dart' as flame;
import 'package:flame_3d/camera.dart';
import 'package:flame_3d/components.dart';
import 'package:flame_3d/graphics.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/widgets.dart';
import 'package:meta/meta.dart';

/// {@template world_3d}
Expand Down Expand Up @@ -46,15 +44,11 @@ class World3D extends flame.World with flame.HasGameReference {
..projection.setFrom(camera.projectionMatrix)
..begin(size);

// print(position);
// print(Matrix4.inverted(viewMatrix).transform3(Vector3.all(0)));

culled = 0;
// ignore: invalid_use_of_internal_member
super.renderFromCamera(canvas);

final image = device.end();
// canvas.drawImage(image, (-viewport.virtualSize / 2).toOffset(), _paint);
canvas.drawImageRect(
image,
Offset.zero & size,
Expand All @@ -65,6 +59,6 @@ class World3D extends flame.World with flame.HasGameReference {
image.dispose();
}

// TODO(wolfen): this is only here for testing purposes
// TODO(wolfenrain): this is only here for testing purposes
int culled = 0;
}
3 changes: 2 additions & 1 deletion packages/flame_3d/lib/src/components/component_3d.dart
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ class Component3D extends Component with HasWorldReference<World3D> {
// This ensures that our rendering is done in a specific order allowing for
// alpha blending.
//
// Note(wolfen): we should optimize this in the long run it currently sucks.
// Note(wolfenrain): we should optimize this in the long run it currently
// sucks.
priority = -(CameraComponent3D.currentCamera!.position - position)
.length
.abs()
Expand Down
4 changes: 2 additions & 2 deletions packages/flame_3d/lib/src/extensions/matrix4.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ extension Matrix4Extension on Matrix4 {

/// Set the matrix to use a projection view.
void setAsPerspective(
double fovy,
double fovY,
double aspectRatio,
double zNear,
double zFar,
) {
final fovYRadians = fovy * degrees2Radians;
final fovYRadians = fovY * degrees2Radians;
setPerspectiveMatrix(this, fovYRadians, aspectRatio, zNear, zFar);
}

Expand Down
16 changes: 4 additions & 12 deletions packages/flame_3d/lib/src/graphics/graphics_device.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ enum DepthStencilState {
/// by binding different resources to it.
///
/// A single render call starts with a call to [begin] and only ends when [end]
/// is called. Anything that gets binded to the device in between will be
/// is called. Anything that gets bound to the device in between will be
/// uploaded to the GPU and returns as an [Image] in [end].
/// {@endtemplate}
class GraphicsDevice {
Expand All @@ -46,14 +46,6 @@ class GraphicsDevice {
Matrix4 get projection => _projectionMatrix;
final Matrix4 _projectionMatrix = Matrix4.zero();

// @Deprecated('Use model, view and projection instead')
// // Matrix4 get transform => _transformMatrix;
// // final _transformMatrix = Matrix4.identity();

// @Deprecated('Use model, view and projection instead')
// Matrix4 get viewModel => _viewModelMatrix;
// final _viewModelMatrix = Matrix4.identity();

Size _previousSize = Size.zero;

/// Begin a new rendering batch.
Expand All @@ -65,9 +57,9 @@ class GraphicsDevice {
/// GPU with [end].
void begin(
Size size, {
// TODO(wolfen): unused at the moment
// TODO(wolfenrain): unused at the moment
BlendState blendState = BlendState.alphaBlend,
// TODO(wolfen): used incorrectly
// TODO(wolfenrain): used incorrectly
DepthStencilState depthStencilState = DepthStencilState.depthRead,
}) {
_commandBuffer = gpu.gpuContext.createCommandBuffer();
Expand All @@ -83,7 +75,7 @@ class GraphicsDevice {
)
..setDepthWriteEnable(depthStencilState == DepthStencilState.depthRead)
..setDepthCompareOperation(
// TODO(wolfen): this is not correctly implemented AT all.
// TODO(wolfenrain): this is not correctly implemented AT all.
switch (depthStencilState) {
DepthStencilState.none => gpu.CompareFunction.never,
DepthStencilState.standard => gpu.CompareFunction.always,
Expand Down
1 change: 0 additions & 1 deletion packages/flame_3d/lib/src/resources/material.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
export 'material/material.dart';
export 'material/spatial_material.dart';
export 'material/standard_material.dart';
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import 'dart:ui';
import 'dart:math';
import 'dart:ui';

import 'package:flame_3d/extensions.dart';

Check notice on line 4 in packages/flame_3d/lib/src/resources/material/spatial_material.dart

View workflow job for this annotation

GitHub Actions / analyze

The import of 'package:flame_3d/extensions.dart' is unnecessary because all of the used elements are also provided by the import of 'package:flame_3d/game.dart'.

Try removing the import directive. See https://dart.dev/diagnostics/unnecessary_import to learn more about this problem.

Check notice on line 4 in packages/flame_3d/lib/src/resources/material/spatial_material.dart

View workflow job for this annotation

GitHub Actions / analyze-latest

The import of 'package:flame_3d/extensions.dart' is unnecessary because all of the used elements are also provided by the import of 'package:flame_3d/game.dart'.

Try removing the import directive. See https://dart.dev/diagnostics/unnecessary_import to learn more about this problem.
import 'package:flame_3d/game.dart';
Expand Down
112 changes: 0 additions & 112 deletions packages/flame_3d/lib/src/resources/material/standard_material.dart

This file was deleted.

4 changes: 2 additions & 2 deletions packages/flame_3d/lib/src/resources/mesh/vertex.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class Vertex {
...position.storage, // 1, 2, 3
...texCoord.storage, // 4, 5
...color.storage, // 6,7,8
// `TODO`(wolfen): uhh normals fuck shit up, I should read up on it
// `TODO`(wolfenrain): uhh normals fuck shit up, I should read up on it

Check notice on line 27 in packages/flame_3d/lib/src/resources/mesh/vertex.dart

View workflow job for this annotation

GitHub Actions / analyze

The line length exceeds the 80-character limit.

Try breaking the line across multiple lines. See https://dart.dev/lints/lines_longer_than_80_chars to learn more about this problem.

Check notice on line 27 in packages/flame_3d/lib/src/resources/mesh/vertex.dart

View workflow job for this annotation

GitHub Actions / analyze-latest

The line length exceeds the 80-character limit.

Try breaking the line across multiple lines. See https://dart.dev/lints/lines_longer_than_80_chars to learn more about this problem.
...(normal ?? Vector3.zero()).storage, // 9, 10, 11
]);

Expand Down Expand Up @@ -60,7 +60,7 @@ class Vertex {
Vector3? normal,
Color? color,
}) {
// TODO(wolfen): optimize this.
// TODO(wolfenrain): optimize this.
return Vertex(
position: position ?? this.position.mutable,
texCoord: texCoord ?? this.texCoord.mutable,
Expand Down
2 changes: 1 addition & 1 deletion packages/flame_3d/lib/src/resources/resource.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'package:flutter/foundation.dart';

// TODO(wolfen): in the long run it would be nice of we can make it
// TODO(wolfenrain): in the long run it would be nice of we can make it
// automatically refer to same type of objects to prevent memory leaks

/// {@template resource}
Expand Down
4 changes: 2 additions & 2 deletions packages/flame_3d/lib/src/resources/shader.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export 'shader/shader.dart';
export 'shader/uniform_slot.dart';
export 'shader/uniform_instance.dart';
export 'shader/uniform_value.dart';
export 'shader/uniform_sampler.dart';
export 'shader/uniform_slot.dart';
export 'shader/uniform_value.dart';
2 changes: 1 addition & 1 deletion packages/flame_3d/test/vector2_extensions_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ void main() {
expect(mutable.y, 2);
});
});
}
}
2 changes: 1 addition & 1 deletion packages/flame_3d/test/vector3_extensions_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ void main() {
expect((a - b.immutable).storage, [-1, 8, -3]);
});
});
}
}
2 changes: 1 addition & 1 deletion packages/flame_3d/test/vector4_extensions_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ void main() {
expect(mutable.w, 4);
});
});
}
}

0 comments on commit db1465f

Please sign in to comment.