-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of github.com:margelo/react-native-filament into …
…chore/docs
- Loading branch information
Showing
29 changed files
with
466 additions
and
643 deletions.
There are no files selected for viewing
File renamed without changes.
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,54 @@ | ||
material { | ||
name : Image, | ||
parameters : [ | ||
{ | ||
type : sampler2d, | ||
name : image | ||
}, | ||
{ | ||
type : mat3, | ||
name : transform, | ||
precision : high | ||
}, | ||
{ | ||
type : float3, | ||
name : backgroundColor | ||
}, | ||
{ | ||
type : int, | ||
name : showImage | ||
} | ||
], | ||
variables : [ | ||
imageUV | ||
], | ||
vertexDomain : device, | ||
depthWrite : false, | ||
shadingModel : unlit, | ||
variantFilter : [ skinning, shadowReceiver, vsm ], | ||
culling: none | ||
} | ||
|
||
vertex { | ||
void materialVertex(inout MaterialVertexInputs material) { | ||
material.imageUV.st = getPosition().st * 0.5 + 0.5; | ||
} | ||
} | ||
|
||
fragment { | ||
void material(inout MaterialInputs material) { | ||
prepareMaterial(material); | ||
|
||
vec4 bg = vec4(materialParams.backgroundColor, 1.0); | ||
highp vec2 uv = (materialParams.transform * vec3(saturate(variable_imageUV.st), 1.0)).st; | ||
if (materialParams.showImage == 0 || uv.s > 1.0 || uv.s < 0.0 || uv.t < 0.0 || uv.t > 1.0) { | ||
material.baseColor = bg; | ||
} else { | ||
uv.t = 1.0 - uv.t; | ||
vec4 color = max(texture(materialParams_image, uv.st), 0.0); | ||
color.rgb *= color.a; | ||
// Manual, pre-multiplied srcOver with opaque destination optimization | ||
material.baseColor.rgb = color.rgb + bg.rgb * (1.0 - color.a); | ||
} | ||
} | ||
} |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
19 changes: 19 additions & 0 deletions
19
package/example/Shared/assets/transparent_shadow_material.mat
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,19 @@ | ||
material { | ||
name : GroundShadow, | ||
blending : transparent, | ||
shadingModel : unlit, | ||
shadowMultiplier : true, | ||
parameters : [ | ||
{ | ||
type : float, | ||
name : strength | ||
} | ||
], | ||
} | ||
|
||
fragment { | ||
void material(inout MaterialInputs material) { | ||
prepareMaterial(material); | ||
material.baseColor = vec4(0.0, 0.0, 0.0, materialParams.strength); | ||
} | ||
} |
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
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,60 @@ | ||
import * as React from 'react' | ||
import { StyleSheet } from 'react-native' | ||
import { FilamentScene, FilamentView, Camera, Skybox, DefaultLight, RenderCallback, Model, ModelInstance } from 'react-native-filament' | ||
import DroneGlb from '~/assets/buster_drone.glb' | ||
import { useCallback } from 'react' | ||
import { useSharedValue } from 'react-native-worklets-core' | ||
import { Rotation } from '../../../src/react/TransformContext' | ||
|
||
function Renderer() { | ||
const rotation = useSharedValue<Rotation>({ | ||
angleInRadians: 0, | ||
axis: [0, 1, 0], | ||
}) | ||
|
||
const renderCallback: RenderCallback = useCallback(() => { | ||
'worklet' | ||
|
||
rotation.value.angleInRadians += 0.01 | ||
if (rotation.value.angleInRadians >= Math.PI * 2) { | ||
// reset / don't overflow | ||
rotation.value.angleInRadians = 0 | ||
} | ||
|
||
// need to make a new object ref so that the listener fires | ||
rotation.value = { | ||
angleInRadians: rotation.value.angleInRadians, | ||
axis: rotation.value.axis, | ||
} | ||
}, [rotation]) | ||
|
||
return ( | ||
<FilamentView style={styles.filamentView} enableTransparentRendering={false} renderCallback={renderCallback}> | ||
<Camera /> | ||
<DefaultLight /> | ||
<Skybox colorInHex="#88defb" /> | ||
|
||
<Model source={DroneGlb} transformToUnitCube scale={[3, 3, 3]}> | ||
{/* Note: we apply the rotation individually as the above transformations are multiplying, while the one for the rotation, shouldn't */} | ||
<ModelInstance index={0} rotate={rotation} multiplyWithCurrentTransform={false} /> | ||
</Model> | ||
</FilamentView> | ||
) | ||
} | ||
|
||
export function AnimatedRotateSharedValues() { | ||
return ( | ||
<FilamentScene> | ||
<Renderer /> | ||
</FilamentScene> | ||
) | ||
} | ||
|
||
const styles = StyleSheet.create({ | ||
container: { | ||
flex: 1, | ||
}, | ||
filamentView: { | ||
flex: 1, | ||
}, | ||
}) |
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
Oops, something went wrong.