File tree Expand file tree Collapse file tree 2 files changed +26
-1
lines changed Expand file tree Collapse file tree 2 files changed +26
-1
lines changed Original file line number Diff line number Diff line change 2323 < script >
2424 const fs = `
2525 uniform sampler2D u_texture0;
26+ uniform float noiseSpeed;
2627
2728 void main() {
2829 vec2 uv = gl_FragCoord.xy / u_resolution.xy;
29- float distortion = sin(uv.y * 50.0 + u_time * 5.0 ) * 0.01;
30+ float distortion = sin(uv.y * 50.0 + u_time * 10.0 * noiseSpeed ) * 0.01;
3031 vec4 texture = texture2D(u_texture0, vec2(
3132 uv.x + distortion * u_mouse.x / 100.,
3233 uv.y + distortion * u_mouse.y / 100.
3839 const App = ( ) => {
3940 const [ width , setWidth ] = React . useState ( 500 ) ;
4041 const [ imgSrc , setImgSrc ] = React . useState ( 'image.jpg' ) ;
42+ const [ noiseSpeed , setNoiseSpeed ] = React . useState ( 0.5 ) ;
4143
4244 return React . createElement ( React . Fragment , { } , [
4345 React . createElement (
4850 key : 'texture' ,
4951 src : imgSrc ,
5052 } ) ,
53+ React . createElement ( 'sd-uniform' , {
54+ key : 'uniform' ,
55+ name : 'noiseSpeed' ,
56+ x : noiseSpeed ,
57+ type : 'float' ,
58+ } ) ,
5159 React . createElement (
5260 'script' ,
5361 { key : 'main-fs' , type : 'x-shader/x-fragment' } ,
5765 ) ,
5866 React . createElement ( 'input' , {
5967 key : 'width-input' ,
68+ type : 'number' ,
69+ step : 1 ,
6070 onChange : e => setWidth ( parseInt ( e . currentTarget . value ) ) ,
6171 value : width ,
6272 } ) ,
8191 ) ,
8292 ]
8393 ) ,
94+ React . createElement ( 'input' , {
95+ key : 'uniform-input' ,
96+ type : 'number' ,
97+ step : 0.1 ,
98+ onChange : e =>
99+ setNoiseSpeed ( parseFloat ( e . currentTarget . value ) || 0 ) ,
100+ value : noiseSpeed ,
101+ } ) ,
84102 ] ) ;
85103 } ;
86104
Original file line number Diff line number Diff line change @@ -112,6 +112,13 @@ function Renderer() {
112112 }
113113
114114 function addUniform ( name , value , type ) {
115+ for ( let i = 0 ; i < ustate . length ; i ++ ) {
116+ if ( ustate [ i ] . name === name ) {
117+ ustate [ i ] . value = value ;
118+ ustate [ i ] . type = type ;
119+ return ;
120+ }
121+ }
115122 ustate . push ( {
116123 name,
117124 value,
You can’t perform that action at this time.
0 commit comments