- Add
CustomShaderMaterial.clone()method - Update regex used to extract main function's body from user's shader code.
Rewritten from scratch, now with no dependencies, optimized performance and better type inference.
- Add
csm_Iridescence - Add
csm_Transmission - Add
csm_Thickness - Add
csm_UnlitFac- Mix factor between lit (
csm_DiffuseColor) and unlit (csm_FragColor) shading.
- Mix factor between lit (
- [BREAKING]: Removed official support for extending third-party materials and materials that already use
onBeforeCompile.- This is due to the complexity of the implementation and the lack of a good way to handle it.
- You can still extend materials, they may or may not work as expected.
-
[BREAKING]: Your shader code is now scoped!
- Now you will not have token redefinition errors within your shader when using tokens already used by Three. For example
mvPosition. - Please note that attributes, uniforms and varying cannot be scoped and will still cause errors if redefined. For example
vUv - Shader code should not be broken. However,
patchMapsmight be, depending on your implementation. Please open an issue and I may help you fix it.
- Now you will not have token redefinition errors within your shader when using tokens already used by Three. For example
-
[BREAKING]: Made generic type T required for vanilla
CustomShaderMaterial<T>class.- This facilitates better type inference for the base material props in vanilla contexts. React remains unchanged.
-
Add
csm_Clearcoat- Clearcoat factor
-
Add
csm_ClearcoatRoughness- Clearcoat roughness factor
-
Add
csm_ClearcoatNormal- Perturbation to the fragment normal used for clearcoat shading
-
Refactor out string manipulations using
glsl-tokenizer,glsl-token-functionsandglsl-token-stringmaking recompilation more performant and less error-prone.
- Fix for Three r0.150.2
- Add
csm_bump
- Now extend already extended materials
- Extend/chain CSM instances
- Extend any other material that uses
onBeforeCompileinternally
- Now prevent exact match function in
patchMapsby passing"*"as the search keyword.
- Fixed uniforms now injected with a ShaderMaterial as
baseMaterial
CSM will now infer options/prop types based on the base material
<CustomShaderMaterial
baseMaterial={MeshBasicMaterial}
transmission={0} // ❌ TypeError; transmission does not exist on MeshBasicMaterial
/>
<CustomShaderMaterial
baseMaterial={MeshPhysicalMaterial}
transmission={0} // ✅ Valid
/>Now override AO within your shader. Available in Physical and Standard material
csm_AO = 0.0; // PBR Ambient Occlusion- FIxed transmission with
MeshPhysicalMaterialas base - Restructure repo and examples
- Fix transmission for MeshPhysicalMaterial base
- 01ec3c5: Add csm_AO
- Improve types
- Restructure repo
csm_Roughness = 0.0; // PBR Roughness
csm_Metalness = 1.0; // PBR Metalness- Updated deps
- Fixed
.clone()(#20)
Vanilla:
const material = new Material();
new CustomShaderMaterial({ baseMaterial: material });React:
const material = useMemo(() => new Material(), [])
<CustomShaderMaterial baseMaterial={material} />Vanilla:
new CustomShaderMaterial({ patchMap: {...} })React:
<CustomShaderMaterial patchMap={{...}} />- Shaders are indentation-sensitive no more.
- Supports full set of standard GLSL syntax.
-
Swapped plain params for object-params
// Old const material = new CustomShaderMaterial( baseMaterial, fragmentShader, vertexShader, uniforms ); material.update(fragmentShader, vertexShader, uniforms); // New const material = new CustomShaderMaterial({ baseMaterial, fragmentShader, vertexShader, uniforms, cacheKey, }); material.update({ fragmentShader, vertexShader, uniforms, cacheKey });
-
Added smarter cache key
- Custom cache key is now a hash:
hash([fragmentShader, vertexShader, uniforms]) - Custom cache key function can be supplied with constructor or update function.
cacheKey : () => string
- Custom cache key is now a hash:
- Now supports
csm_Emissive- Override emissive color from fragment shader
- Updated types to include
PointsMaterial(#15)
- Move vanilla lib to
three-custom-shader-material/vanilla- `import CustomShaderMaterial from "three-custom-shader-material/vanilla"
- Rewritten from scratch
- Ported to
react-three-fiber
- Update deps.
- Added
gl_PointSizeoverride.
- Updated Readme
- Moved some
dependenciestodevDependencies
- Output variables
newPos,newNormalandnewColordepricated in favor ofcsm_Position,csm_Normalandcsm_DiffuseColor- This is a non-breaking change as the old ones still work for compatibility.
- Output variables from custom shader are now optional
csm_Position,csm_Normalandcsm_DiffuseColornow default to their orignal values (position,objectNormalandvColor) if not set in custom shader.
- Rewritten in TypeScript
- Minified to reduce filesize
- Added support for
MeshDepthMaterialandPointsMaterial.- These materials aren't well tested.
- Now supports all material types.
- Now you can set the diffuse color of the object as well.
- Added CDN-friendly version of the library -
build/three-csm.m.cdn.js.
- Renamed
build/three-csm.module.jstobuild/three-csm.m.js - Updated docs and readme.
- Added warnings for unsupported features.
- Fixes #3. Big thanks to Steve Trettel (@stevejtrettel)
- Fix for CVE-2021-23358
- Ability to include custom Fragment Shaders