- //PARTICLE DEPTH VERTEX SHADER
- #version 400
- in vec3 vertexPos;
- uniform mat4 projection;
- uniform mat4 mView;
- uniform vec2 screenSize;
- uniform vec3 lightPos;
- out vec3 pos;
- out float radius;
- void main() {
- vec4 viewPos = mView * vec4(vertexPos, 1.0);
- float dist = length(viewPos);
- gl_Position = projection * viewPos;
- //gl_PointSize = 6 * screenSize.y / (8.0 * gl_Position.z);
- gl_PointSize = 1.0 * (200.0 / dist);
- pos = viewPos.xyz;
- radius = gl_PointSize;
- }
- //PARTICLE DEPTH FRAGMENT SHADER
- #version 400
- in vec3 pos;
- in float radius;
- uniform mat4 mView;
- uniform mat4 projection;
- uniform vec2 screenSize;
- uniform vec3 lightPos;
- out float depth;
- float linearizeDepth(float depth) {
- float n = 0.01f;
- float f = 100f;
- return (2.0 * n) / (f + n - depth * (f - n));
- }
- void main() {
- //calculate normal
- vec3 normal;
- normal.xy = gl_PointCoord * 2.0 - 1.0;
- float r2 = dot(normal.xy, normal.xy);
- if (r2 > 1.0) {
- discard;
- }
- normal.z = sqrt(1.0 - r2);
- //calculate depth
- vec4 pixelPos = vec4(pos + normal * radius, 1.0);
- vec4 clipSpacePos = projection * pixelPos;
- depth = clipSpacePos.z / clipSpacePos.w * 0.5f + 0.5f;
- depth = linearizeDepth(depth);
- }
- //OUTPUT VERTEX SHADER
- #version 400
- in vec2 vertexPos;
- out vec2 pos;
- void main() {
- pos = 0.5f * vertexPos + 0.5f;
- gl_Position = vec4(vertexPos, 0.0f, 1.0f);
- }
- //OUTPUT FRAGMENT SHADER
- #version 400
- in vec2 coord;
- uniform sampler2D depthMap;
- uniform vec2 screenSize;
- uniform mat4 projection;
- out vec4 color;
- float linearizeDepth(float depth) {
- float n = 0.01f;
- float f = 100f;
- return (2.0 * n) / (f + n - depth * (f - n));
- }
- void main() {
- float curDepth = texture2D(depthMap, coord).x;
- //curDepth = linearizeDepth(curDepth);
- color = vec4(curDepth);
- }
SHARE
TWEET
Untitled
a guest
Dec 21st, 2014
135
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.

