-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
BREAKING CHANGE: package name ws changed from @react-shader-fiber/renderer to @react-shader/fiber
- Loading branch information
1 parent
99f4683
commit c98c343
Showing
5 changed files
with
66 additions
and
9 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,30 @@ | ||
import { FragmentShader } from "react-shader-fiber"; | ||
|
||
import { Input, Main, Output, Uniform } from "@react-shader-fiber/stdlib"; | ||
import ShaderProvider from "../providers/ShaderProvider.jsx"; | ||
|
||
const Shader = ({ time, coords, color, children }) => { | ||
return ( | ||
<FragmentShader> | ||
<Output type={"vec4"} id={"fragColor"} ref={color} /> | ||
|
||
<Input ref={coords} type={"vec2"} id={"vCoords"} /> | ||
|
||
<Uniform ref={time} id={"u_time"} type={"float"} /> | ||
|
||
<Main> | ||
<ShaderProvider | ||
value={{ | ||
time: time, | ||
color: color, | ||
coords: coords, | ||
}} | ||
> | ||
{children} | ||
</ShaderProvider> | ||
</Main> | ||
</FragmentShader> | ||
); | ||
}; | ||
|
||
export default Shader; |
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,27 @@ | ||
import { createContext, useContext } from "react"; | ||
|
||
const ShaderContext = createContext({ | ||
time: null, | ||
coords: null, | ||
color: null, | ||
}); | ||
|
||
const useTime = () => { | ||
return useContext(ShaderContext).time; | ||
}; | ||
|
||
const useCoords = () => { | ||
return useContext(ShaderContext).coords; | ||
}; | ||
|
||
const useColor = () => { | ||
return useContext(ShaderContext).color; | ||
}; | ||
|
||
const ShaderProvider = ({ value, children }) => { | ||
return ( | ||
<ShaderContext.Provider value={value}>{children}</ShaderContext.Provider> | ||
); | ||
}; | ||
|
||
export default ShaderProvider; |
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