-

   rss_rss_hh_new

 - e-mail

 

 -

 LiveInternet.ru:
: 17.03.2011
:
:
: 51

:


[] GLSL

, 24 2017 . 12:32 +
image
[ .]

. , . , , . .

: , .

, .


, :


, . , , , . , .


JavaScript ThreeJS, . ( , .)

CodePen, GitHub ( ).


, .

, , . :


.

, : . , , :


CodePen.

100. , . , Next . Display Mode, , , .

, . :

//W =    
//H =  
//f =  /
//     newGrid,    ,      
for(var r=1; rcode>

. , f 1. 4, .

, :



( [1,1] ) . , f 0.1:

0.1 * (100+100+100+100-4*100) = 0.1 * (400-400) = 0

, !

(, 0):

0.1 * (100+100+0+0-4*0) = 0.1 * (200) = 20

, 20! . ( ) :



:

0.1 * (70+70+70+70-4*100) = 0.1 * (280 - 400) = -12

12! .

, , ( ), , . , ( ) .

, : , . , ? , !


, . , , ( ). , Javascript.


, HTML, CSS JS.

:

uniform vec2 res;
void main() {
    vec2 pixel = gl_FragCoord.xy / res.xy;
    gl_FragColor = vec4(0.0,0.0,0.0,1.0);
 }

res pixel . res uniform-. ( , .)

1:


, :

, .

. , ? , , . , . :

.

. ,

. , , . :

uniform vec2 res;
uniform sampler2D texture;
void main() {
    vec2 pixel = gl_FragCoord.xy / res.xy;

    gl_FragColor = texture2D( tex, pixel );//    
    gl_FragColor.r += 0.01;//    	
 }

, 0.01. , , . , , .

, ?


, , , , . :



uniform- , , , . , , .

- :



, , . , , . , , . .


. . , , - .

ThreeJS WebGLRenderTarget. . : . .

A B . :

  1. A , B.
  2. B .
  3. B , A.
  4. A .
  5. 1.

:

  1. A , B.
  2. B .
  3. A B ( A , B, ).
  4. 1.

. ThreeJS:


HTML.

- , . :

uniform vec2 res; //    
uniform sampler2D bufferTexture; //  
void main() {
    vec2 pixel = gl_FragCoord.xy / res.xy;
    gl_FragColor = texture2D( bufferTexture, pixel );
}

, (!):

gl_FragColor.r += 0.01;

, . , , .

: , gl_FragColor.r += pixel.x; , ? , , .

2:


, . .

//        
float dist = distance(gl_FragCoord.xy, res.xy/2.0);
if(dist < 15.0){ //    15 
	gl_FragColor.rgb = vec3(1.0);
}

, , . , .

//        
float dist = distance(gl_FragCoord.xy, res.xy/2.0);
if(dist < 15.0){ //    15 
	gl_FragColor.rgb += 0.01;
}

. , , . . :


, .

:

//    
uniform vec2 res; 
//  
uniform sampler2D bufferTexture; 
// x,y -  . z -  /
uniform vec3 smokeSource;

void main() {
    vec2 pixel = gl_FragCoord.xy / res.xy;
    gl_FragColor = texture2D( bufferTexture, pixel );

    //        
    float dist = distance(smokeSource.xy,gl_FragCoord.xy);
    //  ,    
    if(smokeSource.z > 0.0 && dist < 15.0){
    	gl_FragColor.rgb += smokeSource.z;
    }
}

: , ( ) . if? ( CodePen.)

, ( ).

3:


, ! , : , .

:

//  
float xPixel = 1.0/res.x; //   
float yPixel = 1.0/res.y;

vec4 rightColor = texture2D(bufferTexture,vec2(pixel.x+xPixel,pixel.y));
vec4 leftColor = texture2D(bufferTexture,vec2(pixel.x-xPixel,pixel.y));
vec4 upColor = texture2D(bufferTexture,vec2(pixel.x,pixel.y+yPixel));
vec4 downColor = texture2D(bufferTexture,vec2(pixel.x,pixel.y-yPixel));

//  
gl_FragColor.rgb += 
    14.0 * 0.016 * 
	(
		leftColor.rgb + 
		rightColor.rgb + 
		downColor.rgb + 
		upColor.rgb - 
		4.0 * gl_FragColor.rgb
	);

f . (0.016, 1/60, 60 fps), , 14, . :



-, !


, , ! ?

, ( ) . - , , 0, . , , - :

float factor = 14.0 * 0.016 * (leftColor.r + rightColor.r + downColor.r + upColor.r - 4.0 * gl_FragColor.r);
//      
float minimum = 0.003;
if (factor >= -minimum && factor < 0.0) factor = -minimum;

gl_FragColor.rgb += factor;

r rgb, , ( ).

, 0.003, . , . , :


4:


. , , , . , , , .

, , :

//  
float factor = 8.0 * 0.016 * 
    (
		leftColor.r + 
		rightColor.r + 
		downColor.r * 3.0 + 
		upColor.r - 
		6.0 * gl_FragColor.r
	);

:



, . .

, . ( 6.0 5.0 , ). , - , , .

. , , , , , . , .

, , , , . , , . diffuse_advanced().


, . , .

, 0:

//   
//       
 if(pixel.y <= yPixel){
 	downColor.rgb = vec3(0.0);
 }

, , . 0. ( , )


! ! .


() .

, , , . , , . .

! . , .


, : .

?


. , , , .

, . blur. , x, y.

, . . , .


. , . ( ).

, .
Original source: habrahabr.ru (comments, light).

https://habrahabr.ru/post/333718/

:  

: [1] []
 

:
: 

: ( )

:

  URL