Jump to content

Recommended Posts

Flow this topic if you don't Use Shader a lot.

i try made that because most of member prefer to don't Use shader 

 

we talk about this stuffs step by step :

  1.   What is Shader  
  2.   How It work in GPU : understanding
  3.   How can i use it 
  4.   How can start programming in shader
  5.   what information we access in shader
  6.   [ more question added in next ]

we try talk about one stuff per days 

 

Link to comment
Share on other sites

1.  What is Shader

two kind of shader we have "Material Shader" and "Post Process Shader"

Material Shader : 

 has 2 functions

  1. one for called per each vertex of mesh   : Vertex Shader
  2. and next one called per each pixel of mesh rendered in view-port  : Fragment Shader or Pixel Shader

PostProcess Shader : 

has 2 functions

 1. vertex shader in postprocess used for make a texture coordinate for fragment shader 

attribute vec2 v_coord;
uniform sampler2D fbo_texture;
varying vec2 f_texcoord;

void main(void) {
  gl_Position = vec4(v_coord, 0.0, 1.0);
  f_texcoord = (v_coord + 1.0) / 2.0;
}

 2.  called per each pixel of screen rendered in view-port (that can be called smaller than correct view-port :)  :  called scale parameter ) : Fragment Shader or Pixel Shader

any action in 3d engines need process shader for display final color per pixel of viewport

so any material we used or any effect we have one or few shader we have for do that for us 

 

 

Link to comment
Share on other sites

Hello again in Days 2:

i wanna talk more  about Material Shader 

so how it work is best question we have in first :

we need send information about mesh and textures for Shader 

we have 3 type of variable [attributes , uniforms , varying ]

*** all this stuff managed in babylonjs automatically you just need define what you want more 

 

Attributes

 #Per-vertex variables passed by the engine to the shader, like position, normal, etc (Mesh data in the graphic)

before shader we have geometry information  [ vertices , face , uv , uv2  ] this make mesh in 3d Engine 

all this attributes ( geometry information  )  is Local informaion about mesh and we haven't the global position and scale or rotation in this attributes

Uniforms :

 # User defined variables that are passed by the main program to the vertex and fragment shader, these variables are global for a given execution of a shader.

3d Engine can send other data like global Postion or anything else with Uniforms.

defult global information is : [view , world ,worldView , worldViewProjection , viewProjection ]  we talk more about this in advance mode

Varying

# Variables passed from the vertex shader to the fragment shader.

you can share some information between vertex shader and fragment shader you most define it in Varying 

** varying can help us to make more optimization too 

Link to comment
Share on other sites

in Iran Is Weekend :)  but in Day 3  and 4 we talk about variable Kind and usage 

i just write introduction about day 3 and 4  we continue in Saturday  :

when we need initialize a shader we need collect all uniforms and varyings

Witch uniform we need in Shader ?

What Varying we most Define ?

all variable types

bool ,float , vec? (vector 2,3,4) , mat? (matrix 2,3,4 ) , ivec? (2,3,4 ) , sampler?D (1,2,3) , samplerCube , sampler?DShadow (1,2)

vector components is : x y z w  ( size and position stuff  ) -   r g b a  ( color stuff) -  s t p q ( texture coordinate stuff)

sample of vector usage : 

1: uniform vec3 position;

2: vec2  a = position.xy

2: vec3  a = position.xyv;

* notic you can use like this too : 

.xxx .xxy .xyx .xyy .xzz .. etc

and in color you can use  

http://www.babylonjs.com/cyos/#Q6NMF

 
uniform sampler2D textureSampler;

vec4 map = texture2D( textureSampler , vec2(  uv.x , uv.y  ) );

map.rgb or map.rrr  

reference is : http://mew.cx/glsl_quickref.pdf

more  after Saturday :)   and sorry about late 

ask any question about before thanks

Link to comment
Share on other sites

hi  :  Days 3 

Witch uniform we need in Shader ?

witch we need in Vertex ?

      usually we don't change vertex shader and we most look at them like last chance for solution

     *** when we change vertex shader we miss real position and picking system and collision system

     *** when we change some vertex position you lost your correct normal we most be recalculate (just in safe normal not in flat normals)

     *** it is hard to control move vertex and make animated

     *** when you can make your animation or morph in vertex shader you do that on GPU side it is very optimized

     in vertex shader you don't work with array of position and you just have one and don't have access to other positions

    see this code it is explain what call your vertex shader in GPU : 

for (int i = 0; i < vertexCount; i++) {
  output = vertexShader(vertex[i]); 
}  

reference : https://processing.org/tutorials/pshader/

so your uniform send for all vertex and you cant custom that per vertex

http://babylonjs.com/cyos/#1LNKAZ

you can define your condition for change  in you shader 

http://babylonjs.com/cyos/#1LNKAZ#1 

if you cant find your special vertex by mathematical or condition you most define your uniform and send this special vertex for shader.

        

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...