forked from WonderlandEngine/components
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
video-texture/image-texture: Support more shaders
Signed-off-by: Squareys <squareys@googlemail.com>
- Loading branch information
Showing
3 changed files
with
73 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import {Material, Texture} from '@wonderlandengine/api'; | ||
|
||
/** | ||
* Set the diffuse/flat texture of known pipelines. | ||
* | ||
* @param mat Material to set the texture on | ||
* @param texture Texture to set | ||
* @param customTextureProperty Texture property to set or `'auto'` to automatically | ||
* detect the right texture property based on known pipeline. | ||
* @returns `true` if the property was set, `false` otherwise. | ||
*/ | ||
export function setFirstMaterialTexture( | ||
mat: Material, | ||
texture: Texture, | ||
customTextureProperty: string | ||
) { | ||
if (customTextureProperty !== 'auto') { | ||
// @ts-ignore | ||
mat[customTextureProperty] = texture; | ||
return true; | ||
} | ||
|
||
const shader = mat.shader; | ||
if (shader === 'Flat Opaque Textured') { | ||
// @ts-ignore | ||
mat.flatTexture = texture; | ||
return true; | ||
} else if ( | ||
shader === 'Phong Opaque Textured' || | ||
shader === 'Foliage' || | ||
shader === 'Phong Normalmapped' || | ||
shader === 'Phong Lightmapped' | ||
) { | ||
// @ts-ignore | ||
mat.diffuseTexture = texture; | ||
return true; | ||
} else if (shader === 'Particle') { | ||
// @ts-ignore | ||
mat.mainTexture = texture; | ||
return true; | ||
} else if (shader === 'DistanceFieldVector') { | ||
// @ts-ignore | ||
mat.vectorTexture = texture; | ||
return true; | ||
} else if (shader === 'Background' || shader === 'Sky') { | ||
// @ts-ignore | ||
mat.texture = texture; | ||
return true; | ||
} else if (shader === 'Physical Opaque Textured') { | ||
// @ts-ignore | ||
mat.albedoTexture = texture; | ||
return true; | ||
} | ||
return false; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters