npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

texgen-raub

v0.0.8

Published

Seamless procedural texture generator

Downloads

7

Readme

Texgen

This is a part of Node3D project.

NPM

Build Status

npm i -s texgen-raub

This works only with THREE.JS. Live DEMO.

Synopsis

Method THREE.generateTexture is added.

Args:

{
	resolution: number = 1024,
	uniforms   : Object = {},
	fragment   : string = 'void main() {gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);}',
	noconsole  : bool = true,
	nodebug    : bool = false,
	mipmaps    : bool = true,
	floating   : bool = false,
	anisotropy : number = renderer.capabilities.getMaxAnisotropy(),
}
  • resolution The size of the texture. Must be power of 2.
  • uniforms Passed directly into the THREE.Material.
  • fragment Fragment shader code for texture generation.
  • noconsole Supress three.js shader logs in console.
  • nodebug If threejs shader logs are omitted.
  • mipmaps If mipmaps are generated for the texture.
  • floating Generate floating-point texture (yay, heightmaps!).
  • anisotropy Anisotropy filtering level for the texture.

Returns:

{
	texture : ?THREE.Texture,
	buffer  : ?(Uint8Array|Float32Array),
	error   : ?string,
}
  • texture The resulting texture, if any.
  • buffer The raw texture data. The type depends on the passed floating flag.
  • error If an error has occured, it is passed here.

This is a procedural texture generator. You have to provide a piece of fragment-shader code with at least the main function present.

The output is not necesserily seamless. But it is easy to achieve.

Usage

const fragment = `
void main() {
	vec3 uv3 = getUv3(varUv);
	gl_FragColor = vec4(vec3(pow(noise(uv3 + 9.4) * 1.7, 10.0)), 1.0);
}
`;
const { texture } = THREE.generateTexture({ renderer, fragment });
material.map = texture;

The following image is produced. Here it is easy to see the seamless edges:

Example

More texture-like images are achieved with multiple layers of noise. See examples here. Also you can practice at the Live DEMO website. There you can also download your results as PNG.

GLSL API Details:

  • void main() {} Required procedure
  • vec4 gl_FragColor Output pixel color
  • vec2 varUv varying UV coords [0; 1]
  • vec3 getUv3(vec2) 3D seamless noise coords
  • sampler2D _grain convenience grain texture
  • float noise(vec3) coherent noise generator
  • float getSign(float) -1 for negative, +1 otherwise
  • M_PI = 3.141592653
  • M_2PI = 2.0 * M_PI
  • M_PI2 = 0.5 * M_PI