# Specular

> The Blinn-Phong highlight in the lighting model: a row of spheres from matte to glossy, changing only shininess.

Example `specular`, running at https://nacatamalon.com/en/examples/specular. The whole catalogue: https://nacatamalon.com/llms/examples.md.

The Blinn-Phong highlight, part of the lighting model. A material carries a `specular` colour (black is off) and a `shininess` exponent; the renderer builds the half vector between the light and the camera and lays a glint over the diffuse Gouraud shading.

The row shares its base colour and light: only `shininess` rises from left to right, from a broad soft sheen to a small sharp glint.

## Code

`index.ts`:

```ts
import { createGame } from 'nacatamalon';

import { WIDTH, HEIGHT } from './settings';
import { Game } from './scenes/demo';

const game = createGame('#app', {
    width: WIDTH,
    height: HEIGHT,
    background: '#0a0a14',
});

// Declare Scenes
game({
    Game
});
```

`components/samples.ts`:

```ts
import { createMaterial, createMesh, createText, useLoadBitmapFont, useUpdate, useSphereGeometry } from 'nacatamalon';
import * as Settings from '../settings';

export const Samples = () => {
    const font = useLoadBitmapFont({
        json: '/example-assets/fonts/bitmaps/nacatamal-arcade/nacatamal-arcade.json',
        atlas: '/example-assets/fonts/bitmaps/nacatamal-arcade/nacatamal-arcade.png',
    });

    const geometry = useSphereGeometry();

    Settings.SHININESS.forEach((shininess, i) => {
        const material = createMaterial({
            name: 'shiny-' + shininess,
            shader: 'mesh3d',
            tint: '#6f7fa6',
            specular: '#ffffff',
            shininess,
        });

        const ball = createMesh({
            geometry,
            material,
            transform: {
                x: (i - 2) * 1.25
            }
        });

        useUpdate((delta) => {
            ball.transform.rotationY += delta * Settings.TURN_SPEED;
        });

        createText({
            text: String(shininess),
            font,
            tint: '#8fb7ff',
            transform: {
                x: 240 + (i - 2) * 71 - 8,
                y: 214,
                rotation: 0,
                scaleX: 1,
                scaleY: 1
            },
        });
    });

    createText({
        text: 'SHININESS',
        font,
        tint: '#5566aa',
        transform: {
            x: 196,
            y: 40,
            rotation: 0,
            scaleX: 1,
            scaleY: 1
        },
    });
};
```

`scenes/demo.ts`:

```ts
import { createScene, useCamera3d, useDirectionalLight, useSpawn } from 'nacatamalon';
import * as Settings from '../settings';

import { Samples } from '../components/samples';

export const Game = () => {
    useCamera3d(Settings.CAMERA);
    useDirectionalLight({
        color: '#ffffff',
        intensity: 1,
        transform: {
            rotationX: -0.5,
            rotationY: 0.4
        }
    });

    useSpawn(Samples)();

    return createScene();
};
```

`settings.ts`:

```ts
export const WIDTH = 480;
export const HEIGHT = 320;
import type { TCamera3dOptions } from 'nacatamalon';

export const CAMERA = {
    projection: 'perspective',
    fov: 50,
    transform: {
        z: 6
    }
} satisfies TCamera3dOptions;
export const SHININESS = [4, 16, 48, 128, 400];
export const TURN_SPEED = 0.4;
```
