Finally fixed the shader.
This commit is contained in:
@@ -13,7 +13,6 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifdef GL_ES
|
#ifdef GL_ES
|
||||||
precision mediump float;
|
precision mediump float;
|
||||||
#endif
|
#endif
|
||||||
@@ -33,27 +32,29 @@ varying vec3 v_normal;
|
|||||||
// Fragment shaded diffuse color.
|
// Fragment shaded diffuse color.
|
||||||
varying vec4 v_diffuse;
|
varying vec4 v_diffuse;
|
||||||
|
|
||||||
// Vector from the fragment to the light source.
|
|
||||||
varying vec3 v_lightVector;
|
|
||||||
|
|
||||||
// Vector from the fragment to the camera.
|
// Vector from the fragment to the camera.
|
||||||
varying vec3 v_eyeVector;
|
varying vec3 v_eyeVector;
|
||||||
|
|
||||||
// The light vector reflected around the fragment normal.
|
// The light vector reflected around the fragment normal.
|
||||||
varying vec3 v_reflectedVector;
|
varying vec3 v_reflectedVector;
|
||||||
|
|
||||||
|
// The clamped dot product between the normal and the light vector.
|
||||||
|
varying float v_nDotL;
|
||||||
|
|
||||||
void main(){
|
void main(){
|
||||||
// Normalize the input varyings.
|
// Normalize the input varyings.
|
||||||
vec3 normal = normalize(v_normal);
|
vec3 normal = normalize(v_normal);
|
||||||
vec3 lightVector = normalize(v_lightVector);
|
vec3 eyeVector = normalize(v_eyeVector);
|
||||||
vec3 eyeVector = normalize(v_eyeVector);
|
|
||||||
vec3 reflectedVector = normalize(v_reflectedVector);
|
vec3 reflectedVector = normalize(v_reflectedVector);
|
||||||
|
|
||||||
// Specular Term:
|
// Specular Term.
|
||||||
vec4 specular = u_specular * pow(max(dot(reflectedVector, eyeVector), 0.0), u_shiny);
|
vec4 specular = vec4(0.0, 0.0, 0.0, 1.0);
|
||||||
|
if(v_nDotL > 0.0){
|
||||||
|
specular = u_specular * pow(max(dot(reflectedVector, eyeVector), 0.0), u_shiny);
|
||||||
|
}
|
||||||
|
|
||||||
// Aggregate light color.
|
// Aggregate light color.
|
||||||
vec4 finalColor = clamp(vec4(u_ambient.rgb + v_diffuse.rgb + specular.rgb, 1.0), 0.0, 1.0);
|
vec4 finalColor = clamp(vec4(/*u_ambient.rgb*/ + v_diffuse.rgb + specular.rgb, 1.0), 0.0, 1.0);
|
||||||
|
|
||||||
// Final color.
|
// Final color.
|
||||||
gl_FragColor = finalColor;
|
gl_FragColor = finalColor;
|
||||||
|
@@ -13,13 +13,15 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// Model-view matrix.
|
// Model-view matrix.
|
||||||
uniform mat4 u_projTrans;
|
uniform mat4 u_projTrans;
|
||||||
|
|
||||||
// The world space geometric transformation to apply to this vertex.
|
// The world space geometric transformation to apply to this vertex.
|
||||||
uniform mat4 u_geomTrans;
|
uniform mat4 u_geomTrans;
|
||||||
|
|
||||||
|
// The inverse transpose of the geometric transformation matrix.
|
||||||
|
uniform mat4 u_normalMatrix;
|
||||||
|
|
||||||
// Light source position
|
// Light source position
|
||||||
uniform vec3 u_lightPos;
|
uniform vec3 u_lightPos;
|
||||||
|
|
||||||
@@ -41,30 +43,32 @@ attribute vec4 a_normal;
|
|||||||
// Fragment normal.
|
// Fragment normal.
|
||||||
varying vec3 v_normal;
|
varying vec3 v_normal;
|
||||||
|
|
||||||
// Diffuse shaded color to pass to the fragment shader.
|
// Diffuse shaded color.
|
||||||
varying vec4 v_diffuse;
|
varying vec4 v_diffuse;
|
||||||
|
|
||||||
// The vector from the vertex to the light source.
|
|
||||||
varying vec3 v_lightVector;
|
|
||||||
|
|
||||||
// The vector from the vertex to the camera.
|
// The vector from the vertex to the camera.
|
||||||
varying vec3 v_eyeVector;
|
varying vec3 v_eyeVector;
|
||||||
|
|
||||||
// The light vector reflected around the vertex normal.
|
// The light vector reflected around the vertex normal.
|
||||||
varying vec3 v_reflectedVector;
|
varying vec3 v_reflectedVector;
|
||||||
|
|
||||||
|
// The clamped dot product between the normal and the light vector.
|
||||||
|
varying float v_nDotL;
|
||||||
|
|
||||||
void main(){
|
void main(){
|
||||||
// Apply the geometric transformation to the original position of the vertex.
|
|
||||||
vec4 transformedPosition = u_geomTrans * a_position;
|
vec4 transformedPosition = u_geomTrans * a_position;
|
||||||
|
vec3 lightVector = normalize(u_lightPos.xyz);
|
||||||
|
vec3 invLightVector = normalize(-u_lightPos.xyz);
|
||||||
|
|
||||||
// Set the varyings.
|
// Set the varyings.
|
||||||
v_normal = normalize(a_normal.xyz);
|
v_normal = normalize(vec4(u_normalMatrix * a_normal).xyz);
|
||||||
v_lightVector = normalize(transformedPosition.xyz - u_lightPos.xyz);
|
v_eyeVector = normalize(u_cameraPos.xyz - transformedPosition.xyz);
|
||||||
v_eyeVector = normalize(u_cameraPos.xyz - transformedPosition.xyz);
|
v_reflectedVector = normalize(reflect(-lightVector, v_normal));
|
||||||
v_reflectedVector = normalize(reflect(-v_lightVector, a_normal.xyz));
|
|
||||||
|
|
||||||
// Diffuse Term.
|
// Diffuse Term.
|
||||||
v_diffuse = u_lightDiffuse * u_materialDiffuse * max(dot(a_normal.xyz, v_lightVector), 0.0);
|
float invNDotL = max(dot(v_normal.xyz, invLightVector), 0.0);
|
||||||
|
v_nDotL = max(dot(v_normal.xyz, lightVector), 0.0);
|
||||||
|
v_diffuse = (u_lightDiffuse * u_materialDiffuse * v_nDotL) + (vec4(0.1, 0.1, 0.2, 1.0) * u_materialDiffuse * invNDotL);
|
||||||
|
|
||||||
gl_Position = u_projTrans * transformedPosition;
|
gl_Position = u_projTrans * transformedPosition;
|
||||||
}
|
}
|
||||||
|
@@ -24,7 +24,7 @@ import org.opencv.android.Utils;
|
|||||||
import org.opencv.core.Mat;
|
import org.opencv.core.Mat;
|
||||||
import org.opencv.imgproc.Imgproc;
|
import org.opencv.imgproc.Imgproc;
|
||||||
|
|
||||||
import ve.ucv.ciens.ccg.nxtar.interfaces.AndroidFunctionalityWrapper;
|
import ve.ucv.ciens.ccg.nxtar.interfaces.ActionResolver;
|
||||||
import ve.ucv.ciens.ccg.nxtar.interfaces.ImageProcessor;
|
import ve.ucv.ciens.ccg.nxtar.interfaces.ImageProcessor;
|
||||||
import ve.ucv.ciens.ccg.nxtar.utils.ProjectConstants;
|
import ve.ucv.ciens.ccg.nxtar.utils.ProjectConstants;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
@@ -51,7 +51,7 @@ import com.badlogic.gdx.math.Vector3;
|
|||||||
* <p>Provides operating system services to the LibGDX platform
|
* <p>Provides operating system services to the LibGDX platform
|
||||||
* independant code, and handles OpenCV initialization and api calls.</p>
|
* independant code, and handles OpenCV initialization and api calls.</p>
|
||||||
*/
|
*/
|
||||||
public class MainActivity extends AndroidApplication implements AndroidFunctionalityWrapper, ImageProcessor{
|
public class MainActivity extends AndroidApplication implements ActionResolver, ImageProcessor{
|
||||||
/**
|
/**
|
||||||
* Tag used for logging.
|
* Tag used for logging.
|
||||||
*/
|
*/
|
||||||
|
Reference in New Issue
Block a user