aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/org/jdesktop/j3d/examples/gl2es2pipeline/dimple.vert
blob: ebbfdc95abe49f39091271f2319b2b9cc232bf71 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#version 120
//
// dimple.vert: Vertex shader for bump mapping dimples (bumps)
//
// author: John Kessenich
//
// Copyright (c) 2002: 3Dlabs, Inc.
//


// GL2ES2: Java3D built-in attributes, these are calculated and passsed in if declared here
attribute vec4 glVertex;
attribute vec3 glNormal;  
attribute vec4 glColor;  

// GL2ES2: Java3D built-in uniforms, these are calculated and passsed in if declared here
uniform mat4 glModelViewMatrix;
uniform mat4 glModelViewProjectionMatrix;
uniform mat3 glNormalMatrix;

uniform int ignoreVertexColors;

// GL2ES2: new output varyings, these replace gl_TexCoord[] and gl_FrontColor (along with A and D)
varying vec2 glTexCoord0;
varying vec4 C;

varying vec3 LightDir;
varying vec3 EyeDir;
varying vec3 Normal;

uniform vec3 LightPosition;
// uniform float Scale;
// vec3 LightPosition = vec3(0.0, 0.0, 5.0);
float Scale = 1.0;



void main(void) 
{
	// GL2ES2: swap built-in variable for Java3d built-in uniforms and attributes gl_* = gl* + declaration (at top)
	vec4 pos = glModelViewMatrix * glVertex;
	// GL2ES2: swap built-in variable for Java3d built-in uniforms and attributes gl_* = gl* + declaration (at top)
    gl_Position = glModelViewProjectionMatrix * glVertex;
    vec3 eyeDir = vec3(pos);
    // GL2ES2: swap built-in variable for Java3d built-in uniforms and attributes gl_* = gl* + declaration (at top)
    // GL2ES2: swap built-in varying for declared varying
	//gl_TexCoord[0] = gl_MultiTexCoord0;
    glTexCoord0 = glVertex.xy;
    // GL2ES2: swap built-in variable for Java3d built-in uniforms and attributes gl_* = gl* + declaration (at top)
    // GL2ES2: swap built-in varying for declared varying
    //gl_FrontColor = gl_Color;
    
	if( ignoreVertexColors != 0) 
		C = vec4(1,1,1,1); 
	else
		C = glColor;
	
    vec3 n = normalize(glNormalMatrix * glNormal);
    vec3 t = normalize(cross(vec3(1.141, 2.78, 3.14), n));
    vec3 b = cross(n, t);

    vec3 v;
    v.x = dot(LightPosition, t);
    v.y = dot(LightPosition, b);
    v.z = dot(LightPosition, n);
    LightDir = normalize(v);

    v.x = dot(eyeDir, t);
    v.y = dot(eyeDir, b);
    v.z = dot(eyeDir, n);
    EyeDir = normalize(v);
    
    
  
}