Flutter Engine
The Flutter Engine
Public Member Functions | List of all members
Bump3DSlide Class Reference
Inheritance diagram for Bump3DSlide:
CubeBaseSlide ThreeDSlide ClickHandlerSlide Slide SkRefCnt SkRefCntBase

Public Member Functions

 Bump3DSlide ()
 
void load (SkScalar w, SkScalar h) override
 
void drawFace (SkCanvas *canvas, SkColor color, int face, bool front, const SkM44 &localToWorld) override
 
- Public Member Functions inherited from CubeBaseSlide
 CubeBaseSlide (Flags flags)
 
bool onChar (SkUnichar uni) override
 
virtual void drawFace (SkCanvas *, SkColor, int face, bool front, const SkM44 &localToWorld)=0
 
void draw (SkCanvas *canvas) override
 
ClickonFindClickHandler (SkScalar x, SkScalar y, skui::ModifierKey modi) override
 
bool onClick (Click *click) override
 
bool animate (double nanos) override
 
- Public Member Functions inherited from ThreeDSlide
void concatCamera (SkCanvas *canvas, const SkRect &area, SkScalar zscale)
 
- Public Member Functions inherited from ClickHandlerSlide
bool onMouse (SkScalar x, SkScalar y, skui::InputState clickState, skui::ModifierKey modifierKeys) final
 
- Public Member Functions inherited from Slide
virtual SkISize getDimensions () const
 
virtual void gpuTeardown ()
 
virtual void draw (SkCanvas *canvas)=0
 
virtual bool animate (double nanos)
 
virtual void load (SkScalar winWidth, SkScalar winHeight)
 
virtual void resize (SkScalar winWidth, SkScalar winHeight)
 
virtual void unload ()
 
virtual bool onChar (SkUnichar c)
 
virtual bool onMouse (SkScalar x, SkScalar y, skui::InputState state, skui::ModifierKey modifiers)
 
virtual bool onGetControls (SkMetaData *)
 
virtual void onSetControls (const SkMetaData &)
 
const SkStringgetName ()
 
- Public Member Functions inherited from SkRefCntBase
 SkRefCntBase ()
 
virtual ~SkRefCntBase ()
 
bool unique () const
 
void ref () const
 
void unref () const
 

Additional Inherited Members

- Protected Types inherited from CubeBaseSlide
enum  Flags { kCanRunOnCPU = 1 << 0 , kShowLightDome = 1 << 1 }
 
virtual ClickonFindClickHandler (SkScalar x, SkScalar y, skui::ModifierKey modi)=0
 
virtual bool onClick (Click *)=0
 
- Protected Attributes inherited from CubeBaseSlide
LightOnSphere fLight = {{200 + DX, 200 + DY}, 800, 12}
 
VSphere fSphere
 
Flags fFlags
 
- Protected Attributes inherited from ThreeDSlide
float fNear = 0.05f
 
float fFar = 4
 
float fAngle = SK_ScalarPI / 12
 
SkV3 fEye { 0, 0, 1.0f/std::tan(fAngle/2) - 1 }
 
SkV3 fCOA { 0, 0, 0 }
 
SkV3 fUp { 0, 1, 0 }
 
- Protected Attributes inherited from Slide
SkString fName
 

Detailed Description

Definition at line 358 of file 3DSlide.cpp.

Constructor & Destructor Documentation

◆ Bump3DSlide()

Bump3DSlide::Bump3DSlide ( )
inline

Definition at line 364 of file 3DSlide.cpp.

CubeBaseSlide(Flags flags)
Definition: 3DSlide.cpp:256
SkString fName
Definition: Slide.h:54

Member Function Documentation

◆ drawFace()

void Bump3DSlide::drawFace ( SkCanvas canvas,
SkColor  color,
int  face,
bool  front,
const SkM44 localToWorld 
)
inlineoverridevirtual

Implements CubeBaseSlide.

Definition at line 408 of file 3DSlide.cpp.

409 {
410 if (!front || !isFrontFacing(canvas->getLocalToDevice())) {
411 return;
412 }
413
415 builder.uniform("lightPos") = fLight.computeWorldPos(fSphere);
416 builder.uniform("localToWorld") = localToWorld;
417 builder.uniform("localToWorldAdjInv") = normals(localToWorld);
418
419 builder.child("color_map") = fImgShader;
420 builder.child("normal_map") = fBmpShader;
421
423 paint.setColor(color);
424 paint.setShader(builder.makeShader());
425
426 canvas->drawRRect(fRR, paint);
427 }
static SkM44 normals(SkM44 m)
Definition: 3DSlide.cpp:78
static bool isFrontFacing(const SkM44 &m)
Definition: 3DSlide.cpp:123
LightOnSphere fLight
Definition: 3DSlide.cpp:250
VSphere fSphere
Definition: 3DSlide.cpp:252
SkM44 getLocalToDevice() const
Definition: SkCanvas.cpp:1633
void drawRRect(const SkRRect &rrect, const SkPaint &paint)
Definition: SkCanvas.cpp:1705
const Paint & paint
Definition: color_source.cc:38
DlColor color
SkV3 computeWorldPos(const VSphere &s) const
Definition: 3DSlide.cpp:155

◆ load()

void Bump3DSlide::load ( SkScalar  w,
SkScalar  h 
)
inlineoverridevirtual

Reimplemented from Slide.

Definition at line 366 of file 3DSlide.cpp.

366 {
367 fRR = SkRRect::MakeRectXY({20, 20, 380, 380}, 50, 50);
368 auto img = ToolUtils::GetResourceAsImage("images/brickwork-texture.jpg");
369 fImgShader = img->makeShader(SkSamplingOptions(), SkMatrix::Scale(2, 2));
370 img = ToolUtils::GetResourceAsImage("images/brickwork_normal-map.jpg");
371 fBmpShader = img->makeShader(SkSamplingOptions(), SkMatrix::Scale(2, 2));
372
373 const char code[] = R"(
374 uniform shader color_map;
375 uniform shader normal_map;
376
377 uniform float4x4 localToWorld;
378 uniform float4x4 localToWorldAdjInv;
379 uniform float3 lightPos;
380
381 float3 convert_normal_sample(half4 c) {
382 float3 n = 2 * c.rgb - 1;
383 n.y = -n.y;
384 return n;
385 }
386
387 half4 main(float2 p) {
388 float3 norm = convert_normal_sample(normal_map.eval(p));
389 float3 plane_norm = normalize(localToWorldAdjInv * norm.xyz0).xyz;
390
391 float3 plane_pos = (localToWorld * p.xy01).xyz;
392 float3 light_dir = normalize(lightPos - plane_pos);
393
394 float ambient = 0.2;
395 float dp = dot(plane_norm, light_dir);
396 float scale = min(ambient + max(dp, 0), 1);
397
398 return color_map.eval(p) * scale.xxx1;
399 }
400 )";
402 if (!effect) {
403 SkDebugf("runtime error %s\n", error.c_str());
404 }
405 fEffect = effect;
406 }
void SK_SPI SkDebugf(const char format[],...) SK_PRINTF_LIKE(1
static SkMatrix Scale(SkScalar sx, SkScalar sy)
Definition: SkMatrix.h:75
static SkRRect MakeRectXY(const SkRect &rect, SkScalar xRad, SkScalar yRad)
Definition: SkRRect.h:180
static Result MakeForShader(SkString sksl, const Options &)
const uint8_t uint32_t uint32_t GError ** error
sk_sp< SkImage > GetResourceAsImage(const char *resource)
Definition: DecodeUtils.h:25
SkSamplingOptions(SkFilterMode::kLinear))

The documentation for this class was generated from the following file: