forked from richa-batra/ParticleRobotSimulations
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshaders.cpp
87 lines (74 loc) · 2.57 KB
/
shaders.cpp
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
76
77
78
79
80
81
82
83
84
85
86
87
/*
* Copyright 1993-2015 NVIDIA Corporation. All rights reserved.
*
* Please refer to the NVIDIA end user license agreement (EULA) associated
* with this source code for terms and conditions that govern your use of
* this software. Any use, reproduction, disclosure, or distribution of
* this software and related documentation outside the terms of the EULA
* is strictly prohibited.
*
*/
#define STRINGIFY(A) #A
// BChange
// vertex shader
// const char *vertexShader = STRINGIFY(
// uniform float pointRadius; // point size in world space
// uniform float pointScale; // scale to calculate size in pixels
// uniform float densityScale;
// uniform float densityOffset;
// void main()
// {
// // calculate window-space point size
// vec3 posEye = vec3(gl_ModelViewMatrix * vec4(gl_Vertex.xyz, 1.0));
// float dist = length(posEye);
// gl_PointSize = pointRadius * (pointScale / dist);
// gl_TexCoord[0] = gl_MultiTexCoord0;
// gl_Position = gl_ModelViewProjectionMatrix * vec4(gl_Vertex.xyz, 1.0);
// gl_FrontColor = gl_Color;
// }
// );
// vertex shader
const char *vertexShader = STRINGIFY(
attribute vec2 pos;
attribute vec4 color;
attribute float rad;
uniform float pointScale; // scale to calculate size in pixels
uniform float densityScale;
uniform float densityOffset;
void main()
{
// calculate window-space point size
float x = -pos.x;
float y = 0;
float z = pos.y;
if (z > 1000.0f) {
y = rad;
z = z - 2000.0f;
}
vec3 posEye = vec3(gl_ModelViewMatrix * vec4(0, y, z, 1.0));
float dist = length(posEye);
gl_PointSize = rad * (pointScale / dist);
gl_TexCoord[0] = gl_MultiTexCoord0;
gl_Position = gl_ModelViewProjectionMatrix * vec4(x, y, z, 1.0);
gl_FrontColor = color;
}
);
// EChange
// pixel shader for rendering points as shaded spheres
const char *spherePixelShader = STRINGIFY(
uniform vec3 lightDir;
void main()
{
// const vec3 lightDir = vec3(0.577, 0.577, 0.577);
// calculate normal from texture coordinates
vec3 N;
N.xy = gl_TexCoord[0].xy*vec2(2.0, -2.0) + vec2(-1.0, 1.0);
float mag = dot(N.xy, N.xy);
if (mag > 1.0) discard; // kill pixels outside circle
N.z = sqrt(1.0-mag);
// calculate lighting
float diffuse = max(0.0, dot(lightDir, N));
gl_FragColor = gl_Color * diffuse;
gl_FragColor = gl_Color;
}
);