Jump to content

  • Log In with Google      Sign In   
  • Create Account

Turbochist

Member Since 26 Oct 2013
Offline Last Active Jun 14 2016 09:55 AM

Posts I've Made

In Topic: Directional lighting trouble.

08 June 2016 - 08:35 AM

I've solved it! Thanks all. This is becouse I have to multyply direction to the normalMatrix. Mistake is I mul direction to modelView.


In Topic: Directional lighting trouble.

08 June 2016 - 08:12 AM

attribute vec3 aVertexNormal;
attribute vec3 aVertexPosition;
attribute vec2 aTextureCoord;

uniform mat4 uPMatrix;
uniform mat4 uMVMatrix;
uniform mat3 uNMatrix;

varying vec2 vTextureCoord;
varying vec3 vTransformedNormal;
varying vec4 vPosition;

void main(void) {
        vTransformedNormal = uNMatrix * aVertexNormal;
        vTextureCoord = aTextureCoord;

        vPosition = uMVMatrix * vec4(aVertexPosition, 1.0);
        gl_Position = uPMatrix * vPosition;
}

And frag:

precision highp float;

varying vec2 vTextureCoord;
varying vec3 vTransformedNormal;
varying vec4 vPosition;
	
uniform vec4 uColor;
uniform sampler2D uSampler;
 
#define MAX_POINT_LIGHTS 1

uniform int pointLightsQuantity;
uniform vec4 pointLightsPositions[MAX_POINT_LIGHTS];
uniform vec3 pointLightsParamsv[MAX_POINT_LIGHTS * 3];
uniform float pointLightsParamsf[MAX_POINT_LIGHTS];

void main(void) {

    vec3 lightWeighting;
    vec3 lightDirection;
    vec3 normal;
    vec3 eyeDirection;
    vec3 reflectionDirection;
    float specularLightWeighting;
    float diffuseLightWeighting;


    lightDirection = normalize(pointLightsPositions[0].xyz);
    //float distance = length(dir);
    //float attenuation = 1.0/(1.0+0.1*distance+0.01*distance*distance);
    normal = normalize(vTransformedNormal);
    eyeDirection = normalize(-vPosition.xyz);
    reflectionDirection = reflect(-lightDirection, normal);	
    specularLightWeighting = pow(max(dot(reflectionDirection, eyeDirection), 0.0), pointLightsParamsf[0]);
    diffuseLightWeighting = max(dot(normal, lightDirection), 0.0);
    lightWeighting = pointLightsParamsv[0] + pointLightsParamsv[1] * diffuseLightWeighting + pointLightsParamsv[2] * specularLightWeighting;

    vec4 cc = texture2D( uSampler, vTextureCoord.st );
    gl_FragColor = vec4(lightWeighting, uColor.a) * cc * uColor;
}

uNMatrix is normal matrix.

I dont' know..where is a mistake?


In Topic: Directional lighting trouble.

07 June 2016 - 08:42 AM

Ok I dont translate direction, but how to direct the light to fragment now?


In Topic: Directional lighting trouble.

07 June 2016 - 05:06 AM

I made only direction that translate to model view, but nothing.


In Topic: O'Neil atmosphere mountains bug.

27 May 2016 - 01:09 AM

It is not a bug, it is becouse algorithm wwork with flat sphere. And I need to calculate scattering on the mountain.


PARTNERS