Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Simple Diffuse lighting Shader
- // Fragment Shader
- #version 130
- // INTERPOLOWANE WEJŚCIE z VS (varying)
- smooth in vec4 vVaryingColor;
- // PARAMETRY OBIEKTU
- uniform vec4 Light0Ambient; // składowa ambient światła 0
- uniform vec4 Light0Diffuse; // składowa diffuse światła 0
- uniform vec4 Light0Specular; // składowa specular światła 0
- uniform vec4 MaterialAmbient; // składowa ambient materiału
- uniform vec4 MaterialDiffuse; // składowa diffuse materiału
- uniform vec4 MaterialSpecular; // składowa diffuse materiału
- in vec3 vVaryingNormal;
- in vec3 vVaryingLightDir;
- // WYJŚCIE
- out vec4 vFragColor; // kolor fragmentu
- void main( void )
- {
- vFragColor = vVaryingColor; // przepisanie interpolowanego koloru
- vec3 ambientColor = Light0Ambient.rgb * MaterialAmbient.rgb; // składowa ambient
- float diffuseIntensity = max( 0.0, dot( normalize( vVaryingNormal ), normalize( vVaryingLightDir ) ) ); // intensywność oświetlenia na podstawie prawa Lamberta
- vec3 diffuseColor = diffuseIntensity * Light0Diffuse.rgb * MaterialDiffuse.rgb; // kolor światła rozproszonego na obiekcie
- vFragColor.rgb = ambientColor + diffuseColor;
- vFragColor.a = MaterialDiffuse.a;
- vec3 vReflection = normalize( reflect( -vVaryingLightDir, vVaryingNormal ) );
- float specularIntensity = max( 0.0, dot( normalize( vVaryingNormal ), normalize ( vReflection ) ) );
- float fSpecular = pow(specularIntensity, 128.0);
- vec3 specularColor = fSpecular * Light0Specular.rgb * MaterialSpecular.rgb;
- if(diffuseIntensity > 0.0)
- vFragColor.rgb += specularColor;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement