Tweak pointlight3d sample to work in Raster backend
- Once we add all the missing intrinsics, the locally defined ones
can go away.
- Having the default interpreter vector width match the raster pipeline
is a huge perf win.
Change-Id: I482e409e57791b78a0e6fb15929ae77eb0e76bf3
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/265600
Reviewed-by: Mike Reed <reed@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
diff --git a/samplecode/Sample3D.cpp b/samplecode/Sample3D.cpp
index 648f2db..252cf5e 100644
--- a/samplecode/Sample3D.cpp
+++ b/samplecode/Sample3D.cpp
@@ -338,13 +338,22 @@
uniform float4x4 localToWorld;
uniform float3 lightPos;
+ // TODO: Remove these helpers once all intrinsics work on the raster backend
+ float3 normalize_(float3 v) {
+ return v / sqrt(dot(v, v));
+ }
+
+ float max_(float a, float b) {
+ return a > b ? a : b;
+ }
+
void main(float x, float y, inout half4 color) {
float3 plane_pos = (localToWorld * float4(x, y, 0, 1)).xyz;
- float3 plane_norm = normalize((localToWorld * float4(0, 0, 1, 0)).xyz);
- float3 light_dir = normalize(lightPos - plane_pos);
+ float3 plane_norm = normalize_((localToWorld * float4(0, 0, 1, 0)).xyz);
+ float3 light_dir = normalize_(lightPos - plane_pos);
float ambient = 0.5;
float dp = dot(plane_norm, light_dir);
- float scale = ambient + max(dp, 0);
+ float scale = ambient + max_(dp, 0);
color = color * half4(float4(scale, scale, scale, 1));
}