Changeset 12091 for data/branches/Shader_HS18/programs
- Timestamp:
- Nov 9, 2018, 1:06:05 PM (6 years ago)
- Location:
- data/branches/Shader_HS18/programs/Example
- Files:
-
- 187 added
- 23 edited
Legend:
- Unmodified
- Added
- Removed
-
data/branches/Shader_HS18/programs/Example/GLSL/DepthShadowmapNormalMapReceiverFp.glsl
r12083 r12091 31 31 vec4 shadowUV = oUv; 32 32 // point on shadowmap 33 shadowUV .xy = shadowUV.xy/ shadowUV.w;33 shadowUV = shadowUV / shadowUV.w; 34 34 float centerdepth = texture2D(shadowMap, shadowUV.xy).x; 35 35 -
data/branches/Shader_HS18/programs/Example/GLSL/DepthShadowmapReceiverFp.glsl
r12083 r12091 15 15 vec4 shadowUV = oUv; 16 16 // point on shadowmap 17 shadowUV .xy = shadowUV.xy/ shadowUV.w;17 shadowUV = shadowUV / shadowUV.w; 18 18 float centerdepth = texture2D(shadowMap, shadowUV.xy).x; 19 19 -
data/branches/Shader_HS18/programs/Example/GLSL/SwizzleGP.glsl
r12083 r12091 1 #version 120 2 #extension GL_EXT_geometry_shader4 : enable 1 #version 120 2 #extension GL_EXT_geometry_shader4 : enable 3 3 4 uniform vec4 origColo r;5 uniform vec4 cloneColo r;4 uniform vec4 origColour; 5 uniform vec4 cloneColour; 6 6 7 void main(void) 8 { 7 void main(void) 8 { 9 ///////////////////////////////////////////////////////////// 10 //This example has two parts 11 // step a) draw the primitive pushed down the pipeline 12 // there are gl_Vertices # of vertices 13 // put the vertex value into gl_Position 14 // use EmitVertex => 'create' a new vertex 15 // use EndPrimitive to signal that you are done creating a primitive! 16 // step b) create a new piece of geometry (I.E. WHY WE ARE USING A GEOMETRY SHADER!) 17 // I just do the same loop, but swizzle the x and y values 18 // result => the line we want to draw, and the same line, but along the other axis 9 19 10 //increment variable 11 int i; 20 //Pass-thru! 21 int i; 22 for (i = 0; i < gl_VerticesIn; i++) { 23 gl_Position = gl_PositionIn[i]; 24 gl_FrontColor = origColour; 25 EmitVertex(); 26 } 27 EndPrimitive(); 12 28 13 ///////////////////////////////////////////////////////////// 14 //This example has two parts 15 // step a) draw the primitive pushed down the pipeline 16 // there are gl_Vertices # of vertices 17 // put the vertex value into gl_Position 18 // use EmitVertex => 'create' a new vertex 19 // use EndPrimitive to signal that you are done creating a primitive! 20 // step b) create a new piece of geometry (I.E. WHY WE ARE USING A GEOMETRY SHADER!) 21 // I just do the same loop, but swizzle the x and y values 22 // result => the line we want to draw, and the same line, but along the other axis 23 24 //Pass-thru! 25 for(i=0; i< gl_VerticesIn; i++){ 26 gl_Position = gl_PositionIn[i]; 27 gl_FrontColor = origColor; 28 EmitVertex(); 29 } 30 EndPrimitive(); 31 //New piece of geometry! We just swizzle the x and y terms 32 for(i=0; i< gl_VerticesIn; i++){ 33 gl_Position = gl_PositionIn[i]; 34 gl_Position.xy = gl_Position.yx; 35 gl_FrontColor = cloneColor; 36 EmitVertex(); 37 } 38 EndPrimitive(); 39 29 //New piece of geometry! We just swizzle the x and y terms 30 for (i = 0; i < gl_VerticesIn; i++){ 31 gl_Position = gl_PositionIn[i]; 32 gl_Position.xy = gl_Position.yx; 33 gl_FrontColor = cloneColour; 34 EmitVertex(); 35 } 36 EndPrimitive(); 40 37 } -
data/branches/Shader_HS18/programs/Example/GLSL150/Blur0_vs.glsl
r12083 r12091 1 1 #version 150 2 2 3 in vec4 vertex; 4 // in vec2 uv0; 3 5 out vec2 texCoord[5]; 4 in vec4 vertex;5 6 6 uniform mat4 worldViewProj; 7 in vec2 uv0; 7 // uniform mat4 worldViewProj; 8 8 9 void main() 9 void main() 10 10 { 11 gl_Position = worldViewProj * vertex; 12 13 texCoord[0] = uv0; 14 15 const float size = 0.01; 16 texCoord[1] = texCoord[0] + vec2(1.0, 0.0)*size; 17 texCoord[2] = texCoord[0] + vec2(2.0, 0.0)*size; 18 texCoord[3] = texCoord[0] + vec2(-1.0, 0.0)*size; 19 texCoord[4] = texCoord[0] + vec2(-2.0, 0.0)*size; 11 // gl_Position = worldViewProj * vertex; 12 13 // texCoord[0] = uv0; 14 15 vec2 inPos = sign(vertex.xy); 16 gl_Position = vec4(inPos.xy, 0.0, 1.0); 17 18 texCoord[0] = (vec2(inPos.x, -inPos.y) + 1.0)/2.0; 19 20 const float size = 0.01; 21 texCoord[1] = texCoord[0] + vec2(1.0, 0.0) * size; 22 texCoord[2] = texCoord[0] + vec2(2.0, 0.0) * size; 23 texCoord[3] = texCoord[0] + vec2(-1.0, 0.0) * size; 24 texCoord[4] = texCoord[0] + vec2(-2.0, 0.0) * size; 20 25 } -
data/branches/Shader_HS18/programs/Example/GLSL150/Blur1_vs.glsl
r12083 r12091 1 1 #version 150 2 2 3 uniform mat4 worldViewProj; 3 in vec4 vertex; 4 // in vec2 uv0; 5 out vec2 texCoord[5]; 4 6 5 out vec2 texCoord[5]; 6 in vec4 vertex; 7 in vec2 uv0; 7 // uniform mat4 worldViewProj; 8 8 9 9 void main() 10 10 { 11 gl_Position = worldViewProj * vertex; 12 13 texCoord[0] = uv0; 14 15 const float size = 0.01; 16 texCoord[1] = texCoord[0] + vec2(0.0, 1.0)*size; 17 texCoord[2] = texCoord[0] + vec2(0.0, 2.0)*size; 18 texCoord[3] = texCoord[0] + vec2(0.0, -1.0)*size; 19 texCoord[4] = texCoord[0] + vec2(0.0, -2.0)*size; 11 // gl_Position = worldViewProj * vertex; 12 13 // texCoord[0] = uv0; 14 15 vec2 inPos = sign(vertex.xy); 16 gl_Position = vec4(inPos.xy, 0.0, 1.0); 17 18 texCoord[0] = (vec2(inPos.x, -inPos.y) + 1.0)/2.0; 19 20 const float size = 0.01; 21 texCoord[1] = texCoord[0] + vec2(0.0, 1.0) * size; 22 texCoord[2] = texCoord[0] + vec2(0.0, 2.0) * size; 23 texCoord[3] = texCoord[0] + vec2(0.0, -1.0) * size; 24 texCoord[4] = texCoord[0] + vec2(0.0, -2.0) * size; 20 25 } -
data/branches/Shader_HS18/programs/Example/GLSL150/Combine_fp.glsl
r12083 r12091 10 10 void main() 11 11 { 12 vec4 render = texture(RT, oUv0);13 vec4 sum = texture(Sum, oUv0);12 vec4 render = texture(RT, oUv0); 13 vec4 sum = texture(Sum, oUv0); 14 14 15 fragColour = mix(render, sum, blur);15 fragColour = mix(render, sum, blur); 16 16 } -
data/branches/Shader_HS18/programs/Example/GLSL150/DepthShadowObjectFp.glsl
r12083 r12091 1 1 #version 150 2 /* Copyright Torus Knot Software Ltd 2000-201 32 /* Copyright Torus Knot Software Ltd 2000-2014 3 3 4 4 Permission is hereby granted, free of charge, to any person obtaining a copy -
data/branches/Shader_HS18/programs/Example/GLSL150/DepthShadowObjectVp.glsl
r12083 r12091 1 1 #version 150 2 /* Copyright Torus Knot Software Ltd 2000-201 32 /* Copyright Torus Knot Software Ltd 2000-2014 3 3 4 4 Permission is hereby granted, free of charge, to any person obtaining a copy -
data/branches/Shader_HS18/programs/Example/GLSL150/HardwareMorphAnimationVp.glsl
r12083 r12091 6 6 in vec4 uv1; // pos2 7 7 8 out vec2 oUv;8 // out vec2 oUv; 9 9 out vec4 colour; 10 10 … … 16 16 { 17 17 // interpolate 18 vec4 interp = vec4(vertex.xyz + anim_t.x *(uv1.xyz - vertex.xyz), 1.0);18 vec4 interp = vec4(vertex.xyz + anim_t.x * (uv1.xyz - vertex.xyz), 1.0); 19 19 20 20 gl_Position = worldViewProj * interp; 21 oUv = uv0.xy;22 colour = vec4(1.0, 0.0,0.0,1.0);21 // oUv = uv0.xy; 22 colour = vec4(1.0, 0.0, 0.0, 1.0); 23 23 } -
data/branches/Shader_HS18/programs/Example/GLSL150/HardwareMorphAnimationWithNormalsVp.glsl
r12083 r12091 7 7 in vec4 uv2; // normal2 8 8 9 out vec2 oUv;10 9 out vec4 colour; 10 // out vec2 oUv; 11 11 12 12 uniform mat4 worldViewProj; … … 18 18 void main() 19 19 { 20 21 20 // interpolate position 21 vec4 posinterp = vec4(vertex.xyz + anim_t.x*(uv1.xyz - vertex.xyz), 1.0); 22 22 23 23 // nlerp normal 24 25 24 vec3 ninterp = normal + anim_t.x*(uv2.xyz - normal); 25 ninterp = normalize(ninterp); 26 26 27 28 27 gl_Position = worldViewProj * posinterp; 28 // oUv = uv0.xy; 29 29 30 31 30 vec3 lightDir = normalize( 31 objSpaceLightPos.xyz - (posinterp.xyz * objSpaceLightPos.w)); 32 32 33 34 35 33 // Colour it red to make it easy to identify 34 float lit = clamp(dot(lightDir, ninterp), 0.0, 1.0); 35 colour = vec4((ambient.rgb + vec3(lit,lit,lit)) * vec3(1.0,0.0,0.0), 1.0); 36 36 } -
data/branches/Shader_HS18/programs/Example/GLSL150/HardwarePoseAnimationVp.glsl
r12083 r12091 16 16 void main() 17 17 { 18 19 vec4 interp = vec4(vertex + anim_t.x*uv1.xyz + anim_t.y*uv2.xyz, 1.0);18 // interpolate 19 vec4 interp = vec4(vertex.xyz + anim_t.x * uv1.xyz + anim_t.y * uv2.xyz, 1.0); 20 20 21 22 23 colour = vec4(1.0,0.0,0.0,1.0);21 gl_Position = worldViewProj * interp; 22 oUv = uv0.xy; 23 colour = vec4(1.0, 0.0, 0.0, 1.0); 24 24 } 25 -
data/branches/Shader_HS18/programs/Example/GLSL150/HardwarePoseAnimationWithNormalsVp.glsl
r12083 r12091 9 9 in vec4 uv4; // pose2norm 10 10 11 out vec2 oUv;11 // out vec2 oUv; 12 12 out vec4 colour; 13 13 … … 20 20 void main() 21 21 { 22 23 vec4 posinterp = vec4(pos + anim_t.x*uv1.xyz + anim_t.y*uv3.xyz, 1.0);22 // interpolate position 23 vec4 posinterp = vec4(vertex.xyz + anim_t.x * uv1.xyz + anim_t.y * uv3.xyz, 1.0); 24 24 25 25 // nlerp normal 26 // nlerp normal 27 // First apply the pose normals (these are actual normals, not offsets) 28 vec3 ninterp = anim_t.x*uv2.xyz + anim_t.y*uv4.xyz; 26 // First apply the pose normals (these are actual normals, not offsets) 27 vec3 ninterp = anim_t.x * uv2.xyz + anim_t.y * uv4.xyz; 29 28 30 31 32 33 34 ninterp = ninterp + (normal * remainder);35 29 // Now add back any influence of the original normal 30 // This depends on what the cumulative weighting left the normal at, if it's lacking or cancelled out 31 //float remainder = 1.0 - min(anim_t.x + anim_t.y, 1.0); 32 float remainder = 1.0 - min(length(ninterp), 1.0); 33 ninterp = ninterp + (remainder * normal.xyz); 34 ninterp = normalize(ninterp); 36 35 37 gl_Position = worldViewProj * posinterp; 38 oUv = uv0.xy; 39 40 vec3 lightDir = normalize( 41 objSpaceLightPos.xyz - (posinterp.xyz * objSpaceLightPos.w)); 36 gl_Position = worldViewProj * posinterp; 37 // oUv = uv0.xy; 42 38 43 // Colour it red to make it easy to identify 44 float lit = clamp(dot(lightDir, ninterp), 0.0, 1.0); 45 colour = vec4((ambient.rgb + vec3(lit,lit,lit)) * vec3(1.0,0.0,0.0), 1.0); 39 vec3 lightDir = normalize( 40 objSpaceLightPos.xyz - (posinterp.xyz * objSpaceLightPos.w)); 41 42 // Colour it red to make it easy to identify 43 float lit = clamp(dot(lightDir, ninterp), 0.0, 1.0); 44 colour = vec4((ambient.rgb + vec3(lit, lit, lit)) * vec3(1.0, 0.0, 0.0), 1.0); 46 45 } -
data/branches/Shader_HS18/programs/Example/GLSL150/HeatBlurFp.glsl
r12083 r12091 9 9 void main() 10 10 { 11 int i;12 vec4 tmpOutColor;13 float diffuseGlowFactor;14 vec2 offsets[4];15 /*16 17 18 19 20 21 */22 /*23 24 25 26 27 28 */29 /*11 int i; 12 vec4 tmpOutColor; 13 float diffuseGlowFactor; 14 vec2 offsets[4]; 15 /* 16 // hazy blur 17 -1.8, -1.8, 18 -1.8, 1.8, 19 1.8, -1.8, 20 1.8, 1.8 21 */ 22 /* 23 // less-hazy blur 24 -1.0, 2.0, 25 -1.0, -1.0, 26 1.0, -1.0, 27 1.0, 1.0 28 */ 29 /* 30 30 -0.326212, -0.405805, 31 31 -0.840144, -0.073580, 32 32 -0.695914, 0.457137, 33 33 -0.203345, 0.620716 34 */34 */ 35 35 36 offsets[0] = vec2(-0.3, 0.4);37 offsets[1] = vec2(-0.3, -0.4);38 offsets[2] = vec2(0.3, -0.4);39 offsets[3] = vec2(0.3, 0.4);36 offsets[0] = vec2(-0.3, 0.4); 37 offsets[1] = vec2(-0.3, -0.4); 38 offsets[2] = vec2(0.3, -0.4); 39 offsets[3] = vec2(0.3, 0.4); 40 40 41 tmpOutColor = texture( Input, uv );// UV coords are in image space41 tmpOutColor = texture( Input, uv ); // UV coords are in image space 42 42 43 // calculate glow amount44 diffuseGlowFactor = 0.0113 * (2.0 - max( tmpOutColor.r, tmpOutColor.g ));43 // calculate glow amount 44 diffuseGlowFactor = 0.0113 * (2.0 - max( tmpOutColor.r, tmpOutColor.g )); 45 45 46 // basic blur filter47 for (i = 0; i < 4; i++) {48 tmpOutColor += texture( Input, uv + blurAmount.x * diffuseGlowFactor * offsets[i] );49 }46 // basic blur filter 47 for (i = 0; i < 4; i++) { 48 tmpOutColor += texture( Input, uv + blurAmount.x * diffuseGlowFactor * offsets[i] ); 49 } 50 50 51 tmpOutColor *= 0.25;51 tmpOutColor *= 0.25; 52 52 53 // TIPS (old-skool strikes again!)54 // Pay attention here! If you use the "out float4 outColor" directly55 // in your steps while creating the output color (like you remove56 // the "tmpOutColor" var and just use the "outColor" directly)57 // your pixel-color output IS CHANGING EACH TIME YOU DO AN ASSIGNMENT TOO!58 // A temporary variable, instead, acts like a per-pixel double buffer, and59 // best of all, lead to better performance.60 fragColour = tmpOutColor;53 // TIPS (old-skool strikes again!) 54 // Pay attention here! If you use the "out float4 outColor" directly 55 // in your steps while creating the output color (like you remove 56 // the "tmpOutColor" var and just use the "outColor" directly) 57 // your pixel-color output IS CHANGING EACH TIME YOU DO AN ASSIGNMENT TOO! 58 // A temporary variable, instead, acts like a per-pixel double buffer, and 59 // best of all, lead to better performance. 60 fragColour = tmpOutColor; 61 61 } -
data/branches/Shader_HS18/programs/Example/GLSL150/LightToHeatFp.glsl
r12083 r12091 9 9 uniform sampler2D HeatLookup; 10 10 11 in vec4 diffuse;11 // in vec4 diffuse; 12 12 in vec2 uv; 13 13 out vec4 fragColour; … … 15 15 void main() 16 16 { 17 float depth, heat, interference;17 float depth, heat, interference; 18 18 19 // Output constant color:20 depth = texture( Input, uv ).x;21 depth *= (depth * depth_modulator).x;19 // Output constant color: 20 depth = texture( Input, uv ).x; 21 depth *= (depth * depth_modulator).x; 22 22 23 heat = (depth * heatBiasScale.y);23 heat = (depth * heatBiasScale.y); 24 24 25 //if (depth > 0)26 {27 28 29 30 31 }25 // if (depth > 0) 26 { 27 interference = -0.5 + texture( NoiseMap, uv + vec2( random_fractions.x, random_fractions.y ) ).x; 28 interference *= interference; 29 interference *= 1.0 - heat; 30 heat += interference;//+ heatBiasScale.x; 31 } 32 32 33 // Clamp UVs34 heat = max( 0.005, min( 0.995, heat ) );35 fragColour = texture( HeatLookup, vec2( heat, 0.0 ) );33 // Clamp UVs 34 heat = max( 0.005, min( 0.995, heat ) ); 35 fragColour = texture( HeatLookup, vec2( heat, 0.0 ) ); 36 36 } -
data/branches/Shader_HS18/programs/Example/GLSL150/OldTV.glsl
r12083 r12091 20 20 void main() 21 21 { 22 // Define a frame shape23 float f = (1 - pos.x * pos.x) * (1 - pos.y * pos.y);24 float frame = clamp(frameSharpness * (pow(f, frameShape) - frameLimit), 0.0, 1.0);22 // Define a frame shape 23 float f = (1 - pos.x * pos.x) * (1 - pos.y * pos.y); 24 float frame = clamp(frameSharpness * (pow(f, frameShape) - frameLimit), 0.0, 1.0); 25 25 26 // Interference ... just a texture filled with rand()27 float rand = texture(Rand, vec3(1.5 * pos.x, 1.5 * pos.y, time_0_X)).x - 0.2;26 // Interference ... just a texture filled with rand() 27 float rand = texture(Rand, vec3(1.5 * pos.x, 1.5 * pos.y, time_0_X)).x - 0.2; 28 28 29 // Some signed noise for the distortion effect30 float noisy = texture(Noise, vec3(0, 0.5 * pos.y, 0.1 * time_0_X)).x - 0.5;29 // Some signed noise for the distortion effect 30 float noisy = texture(Noise, vec3(0, 0.5 * pos.y, 0.1 * time_0_X)).x - 0.5; 31 31 32 // Repeat a 1 - x^2 (0 < x < 1) curve and roll it with sinus.33 float dst = fract(pos.y * distortionFreq + distortionRoll * sin_time_0_X);34 dst *= (1 - dst);35 // Make sure distortion is highest in the center of the image36 dst /= 1 + distortionScale * abs(pos.y);32 // Repeat a 1 - x^2 (0 < x < 1) curve and roll it with sinus. 33 float dst = fract(pos.y * distortionFreq + distortionRoll * sin_time_0_X); 34 dst *= (1 - dst); 35 // Make sure distortion is highest in the center of the image 36 dst /= 1 + distortionScale * abs(pos.y); 37 37 38 // ... and finally distort39 vec2 inUv = oUv0;40 inUv.x += distortionScale * noisy * dst;41 vec4 image = texture(Image, inUv);38 // ... and finally distort 39 vec2 inUv = oUv0; 40 inUv.x += distortionScale * noisy * dst; 41 vec4 image = texture(Image, inUv); 42 42 43 // Combine frame, distorted image and interference44 fragColour = frame * (interference * rand + image);43 // Combine frame, distorted image and interference 44 fragColour = frame * (interference * rand + image); 45 45 } 46 -
data/branches/Shader_HS18/programs/Example/GLSL150/ParticleGS_DisplayGS.glsl
r12083 r12091 2 2 3 3 in block { 4 vec3pos;5 vec4 color;6 floatradius;7 } Colo redFirework[];4 vec3 pos; 5 vec4 colour; 6 float radius; 7 } ColouredFirework[]; 8 8 9 9 out block { 10 vec4pos;11 vec4 color;12 vec2texcoord;10 vec4 pos; 11 vec4 colour; 12 vec2 texcoord; 13 13 } Firework; 14 14 … … 22 22 void main() 23 23 { 24 24 vec3 g_positions[4] = vec3[4](vec3(-1, 1, 0), vec3(-1, -1, 0), vec3(1, 1, 0), vec3(1, -1, 0)); 25 25 vec2 g_texcoords[4] = vec2[4](vec2(0, 1), vec2(1, 1), vec2(0, 0), vec2(1, 0)); 26 26 … … 28 28 // Emit two new triangles 29 29 // 30 for (int i=0; i<4; i++)30 for (int i = 0; i < 4; i++) 31 31 { 32 vec3 position = -g_positions[i] * ColoredFirework[0].radius;33 position = mat3(inverseView) * position + Colo redFirework[0].pos;32 vec3 position = -g_positions[i] * ColouredFirework[0].radius; 33 position = mat3(inverseView) * position + ColouredFirework[0].pos; 34 34 gl_Position = worldViewProj * vec4(position, 1.0); 35 35 36 36 Firework.pos = gl_Position; 37 Firework.colo r = ColoredFirework[0].color;37 Firework.colour = ColouredFirework[0].colour; 38 38 Firework.texcoord = g_texcoords[i]; 39 39 EmitVertex(); -
data/branches/Shader_HS18/programs/Example/GLSL150/ParticleGS_DisplayVS.glsl
r12083 r12091 4 4 // Explanation of different particle types 5 5 // 6 #define PT_LAUNCHER 0 //Firework Launcher - launches a PT_SHELL every so many seconds 7 #define PT_SHELL 1 //Unexploded shell - flies from the origin and explodes into many PT_EMBERXs 8 #define PT_EMBER1 2 //basic particle - after it's emitted from the shell, it dies 9 #define PT_EMBER2 3 //after it's emitted, it explodes again into many PT_EMBER1s 10 #define PT_EMBER3 4 //just a differently colored ember1 6 // Firework Launcher - launches a PT_SHELL every so many seconds. 7 #define PT_LAUNCHER 0 8 // Unexploded shell - flies from the origin and explodes into many PT_EMBERX's. 9 #define PT_SHELL 1 10 // Basic particle - after it's emitted from the shell, it dies. 11 #define PT_EMBER1 2 12 // After it's emitted, it explodes again into many PT_EMBER1's. 13 #define PT_EMBER2 3 14 // Just a differently colored ember1. 15 #define PT_EMBER3 4 11 16 #define P_SHELLLIFE 3.0 12 17 #define P_EMBER1LIFE 2.5 … … 14 19 #define P_EMBER3LIFE 2.0 15 20 16 in vec4 position; 17 uniform float inTimer; 18 uniform float inType; 19 uniform vec3 inVelocity; 21 in vec3 position; 22 // timer 23 in float uv0; 24 // type 25 in float uv1; 26 // velocity 27 in vec3 uv2; 20 28 21 29 out block { 22 vec3pos;23 vec4 color;24 floatradius;25 } Colo redFirework;30 vec3 pos; 31 vec4 colour; 32 float radius; 33 } ColouredFirework; 26 34 27 35 uniform mat4 worldViewProj; … … 30 38 void main() 31 39 { 40 float inTimer = uv0; 41 float inType = uv1; 42 32 43 // 33 44 // Pass the point through 34 45 // 35 Colo redFirework.pos = position.xyz; //Multiply by world matrix?36 Colo redFirework.radius = 1.5;46 ColouredFirework.pos = position; // Multiply by world matrix? 47 ColouredFirework.radius = 1.5; 37 48 38 49 // 39 // calculate the colo r50 // calculate the colour 40 51 // 41 if ( inType == PT_LAUNCHER)52 if (inType == PT_LAUNCHER) 42 53 { 43 ColoredFirework.color = vec4(1,0.1,0.1,1); 44 ColoredFirework.radius = 1.0; 54 // red 55 ColouredFirework.colour = vec4(1, 0.1, 0.1, 1); 56 ColouredFirework.radius = 1.0; 45 57 } 46 else if ( inType == PT_SHELL)58 else if (inType == PT_SHELL) 47 59 { 48 ColoredFirework.color = vec4(0.1,1,1,1); 49 ColoredFirework.radius = 1.0; 60 // cyan 61 ColouredFirework.colour = vec4(0.1, 1, 1, 1); 62 ColouredFirework.radius = 1.0; 50 63 } 51 else if ( inType == PT_EMBER1)64 else if (inType == PT_EMBER1) 52 65 { 53 ColoredFirework.color = vec4(1,1,0.1,1); 54 ColoredFirework.color *= (inTimer / P_EMBER1LIFE ); 66 // yellow 67 ColouredFirework.colour = vec4(1, 1, 0.1, 1); 68 ColouredFirework.colour *= (inTimer / P_EMBER1LIFE); 55 69 } 56 else if ( inType == PT_EMBER2)70 else if (inType == PT_EMBER2) 57 71 { 58 ColoredFirework.color = vec4(1,0.1,1,1); 72 // fuschia 73 ColouredFirework.colour = vec4(1, 0.1, 1, 1); 59 74 } 60 else if ( inType == PT_EMBER3)75 else if (inType == PT_EMBER3) 61 76 { 62 ColoredFirework.color = vec4(1,0.1,0.1,1); 63 ColoredFirework.color *= (inTimer / P_EMBER3LIFE ); 77 // red 78 ColouredFirework.colour = vec4(1, 0.1, 0.1, 1); 79 ColouredFirework.colour *= (inTimer / P_EMBER3LIFE); 64 80 } 65 81 } -
data/branches/Shader_HS18/programs/Example/GLSL150/ParticleGS_GenerateGS.glsl
r12083 r12091 2 2 3 3 // 4 // Explanation of different particle types 5 // 6 #define PT_LAUNCHER 0 //Firework Launcher - launches a PT_SHELL every so many seconds 7 #define PT_SHELL 1 //Unexploded shell - flies from the origin and explodes into many PT_EMBERXs 8 #define PT_EMBER1 2 //basic particle - after it's emitted from the shell, it dies 9 #define PT_EMBER2 3 //after it's emitted, it explodes again into many PT_EMBER1s 10 #define PT_EMBER3 4 //just a differently colored ember1 4 // Explanation of different particle types. 5 // 6 // Firework Launcher - launches a PT_SHELL every so many seconds. 7 #define PT_LAUNCHER 0 8 // Unexploded shell - flies from the origin and explodes into many PT_EMBERX's. 9 #define PT_SHELL 1 10 // Basic particle - after it's emitted from the shell, it dies. 11 #define PT_EMBER1 2 12 // After it's emitted, it explodes again into many PT_EMBER1's. 13 #define PT_EMBER2 3 14 // Just a different colored ember1. 15 #define PT_EMBER3 4 11 16 #define P_SHELLLIFE 3.0 12 17 #define P_EMBER1LIFE 2.5 … … 14 19 #define P_EMBER3LIFE 2.0 15 20 16 // These two were originally shader params, but they caused runtime errors21 // These two were originally shader params, but they caused runtime errors. 17 22 #define NUM_EMBER_1S 30 18 23 #define NUM_EMBER_2S 15 19 24 #define NUM_EMBER_3S 10 20 // This one was originally a variant, but this also causes runtime errors25 // This one was originally a variant, but also causes runtime errors. 21 26 //#define MAX_EMBER_2S 15.0 22 27 28 layout(points) in; 29 layout(points, max_vertices = 60) out; 30 23 31 in block { 24 vec4Pos;25 floatTimer;26 float 27 vec3Vel;32 vec3 Pos; 33 float Timer; 34 float Type; 35 vec3 Vel; 28 36 } FireworkData[]; 29 37 30 layout(points) in; 31 layout(points, max_vertices = 1) out; 32 33 uniform sampler1D randomTex; 38 // out vec3 outputPos; 39 // out float outputTimer; 40 // out float outputType; 41 // out vec3 outputVel; 42 43 // out vec3 gl_Position; 44 out vec3 oPos; 45 out float oUv0; // Timer 46 out float oUv1; // Type 47 out vec3 oUv2; // Velocity 48 49 uniform sampler1D randomTexture; 34 50 uniform vec3 frameGravity; 35 51 uniform float globalTime; 36 52 uniform float elapsedTime; 37 53 uniform float secondsPerFirework; 38 out vec4 colour; 54 39 55 // 40 56 // Generic particle motion handler 41 57 // 42 43 58 void GSGenericHandler( vec3 Pos, vec3 Vel, float Timer, float Type, 44 float elapsedTime, 45 vec3 frameGravity) 46 { 47 gl_Position.xyz = Pos + (Vel * elapsedTime); 59 float elapsedTime, 60 vec3 frameGravity) 61 { 48 62 Vel += frameGravity; 49 63 Timer -= elapsedTime; 50 if (Pos.y > -100) 51 { 52 EmitVertex();//Pos : POSITION, Vel : TEXCOORD2, Timer : TEXCOORD0, Type : TEXCOORD1); 53 } 64 65 if (Pos.y > -100) 66 { 67 oPos = Pos + (Vel * elapsedTime); 68 oUv0 = Timer; 69 oUv1 = Type; 70 oUv2 = Vel; 71 EmitVertex(); 72 } 54 73 } 55 74 … … 66 85 // Launcher type particle handler 67 86 // 68 void GSLauncherHandler( vec3 Pos, vec3 Vel, float Timer, float Type, 69 float elapsedTime, 70 float globalTime, 71 72 73 { 74 if (Timer <= 0)75 { 76 vec3 vRandom = normalize( RandomDir( Type, globalTime, randomTex));77 //Give it more of an up bias 78 vRandom = normalize(vRandom + vec3(0, 2.5,0));79 80 //time to emit a new SHELL 81 gl_Position.xyz = Pos + Vel*elapsedTime;82 vec3 outputVel = Vel + vRandom*35.0;83 float outputTimer = P_SHELLLIFE + vRandom.y*0.5;84 float outputType= PT_SHELL;85 EmitVertex(); //(outputPos : POSITION, outputVel : TEXCOORD2, outputTimer : TEXCOORD0, outputType : TEXCOORD1);86 87 // reset our timer88 Timer = secondsPerFirework + vRandom.x *0.4;87 void GSLauncherHandler( vec3 Pos, vec3 Vel, float Timer, float Type, 88 float elapsedTime, 89 float globalTime, 90 sampler1D randomTex, 91 float secondsPerFirework) 92 { 93 if (Timer <= 0) 94 { 95 vec3 vRandom = normalize(RandomDir(Type, globalTime, randomTex)); 96 // Give it more of an up bias. 97 vRandom = normalize(vRandom + vec3(0, 2.5, 0)); 98 99 // Time to emit a new SHELL. 100 oPos = Pos + Vel * elapsedTime; 101 oUv2 = Vel + vRandom * 35.0; 102 oUv0 = P_SHELLLIFE + vRandom.y * 0.5; 103 oUv1 = PT_SHELL; 104 EmitVertex(); 105 106 // Reset our timer. 107 Timer = secondsPerFirework + vRandom.x * 0.4; 89 108 } 90 109 else … … 92 111 Timer -= elapsedTime; 93 112 } 94 95 //emit ourselves to keep us alive 96 EmitVertex();//( Pos : POSITION, Vel : TEXCOORD2, Timer : TEXCOORD0, Type : TEXCOORD1); 113 114 // Emit ourselves to keep us alive. 115 oPos = Pos; 116 oUv2 = Vel; 117 oUv0 = Timer; 118 oUv1 = Type; 119 EmitVertex(); 97 120 } 98 121 99 122 // 100 123 // Shell type particle handler 101 // 124 // 102 125 void GSShellHandler( vec3 Pos, vec3 Vel, float Timer, float Type, 103 float elapsedTime, 104 float globalTime, 105 sampler1D randomTex, 106 vec3 frameGravity) 107 { 108 if(Timer <= 0) 109 { 110 vec3 outputPos; 111 vec3 outputVel; 112 float outputTimer; 113 float outputType; 114 126 float elapsedTime, 127 float globalTime, 128 sampler1D randomTex, 129 vec3 frameGravity) 130 { 131 if (Timer <= 0) 132 { 115 133 vec3 vRandom = vec3(0,0,0); 116 117 // time to emit a series of new Ember1s118 for (int i=0; i<NUM_EMBER_1S; i++)134 135 // Time to emit a series of new Ember1s. 136 for (int i = 0; i < NUM_EMBER_1S; i++) 119 137 { 120 vRandom = normalize( RandomDir( Type+i, globalTime, randomTex ) ); 121 gl_Position.xyz = Pos + Vel*elapsedTime; 122 outputVel = Vel + vRandom*15.0; 123 outputTimer = P_EMBER1LIFE; 124 outputType = PT_EMBER1; 125 EmitVertex();//(outputPos : POSITION, outputTimer : TEXCOORD0, outputType : TEXCOORD1, outputVel : TEXCOORD2); 126 } 127 128 //find out how many Ember2s to emit 129 //Not doing this because it causes a runtime error 130 //int numEmber2s = abs(vRandom.x)*MAX_EMBER_2S; 131 for(int i=0; i<NUM_EMBER_2S; i++) 132 { 133 vRandom = normalize( RandomDir( Type, globalTime, randomTex) ); 134 gl_Position.xyz = Pos + Vel*elapsedTime; 135 outputVel = Vel + vRandom*10.0; 136 outputTimer = P_EMBER2LIFE + 0.4*vRandom.x; 137 outputType = PT_EMBER2; 138 EmitVertex();//(outputPos : POSITION, outputVel : TEXCOORD2, outputTimer : TEXCOORD0, outputType : TEXCOORD1); 139 } 140 141 } 142 else 143 { 144 GSGenericHandler(Pos, Vel, Timer, Type, elapsedTime, frameGravity ); 145 } 146 } 147 148 // 149 // Ember1 and Ember3 type particle handler 150 // 151 void GSEmber1Handler( vec3 Pos, vec3 Vel, float Timer, float Type, 152 float elapsedTime, 153 vec3 frameGravity) 154 { 155 if(Timer > 0) 156 { 157 GSGenericHandler(Pos, Vel, Timer, Type, elapsedTime, frameGravity ); 158 } 159 } 160 161 // 162 // Ember2 type particle handler 163 // 164 void GSEmber2Handler( vec3 Pos, vec3 Vel, float Timer, float Type, 165 float elapsedTime, 166 float globalTime, 167 sampler1D randomTex, 168 vec3 frameGravity) 169 { 170 if(Timer <= 0) 171 { 172 vec3 outputPos; 173 vec3 outputVel; 174 float outputTimer; 175 float outputType; 176 177 //time to emit a series of new Ember3s 178 for(int i=0; i<NUM_EMBER_3S; i++) 179 { 180 gl_Position.xyz = Pos + Vel*elapsedTime; 181 outputVel = Vel + normalize( RandomDir( Type + i, globalTime, randomTex ) )*10.0; 182 outputTimer = P_EMBER3LIFE; 183 outputType = PT_EMBER3; 138 vRandom = normalize(RandomDir(Type + i, globalTime, randomTex)); 139 oPos = Pos + Vel * elapsedTime; 140 oUv2 = Vel + vRandom * 15.0; 141 oUv0 = P_EMBER1LIFE; 142 oUv1 = PT_EMBER1; 184 143 EmitVertex(); 185 144 } 145 146 // Find out how many Ember2s to emit. 147 // Not doing this because it causes a runtime error. 148 //int numEmber2s = abs(vRandom.x)*MAX_EMBER_2S; 149 for (int i = 0; i < NUM_EMBER_2S; i++) 150 { 151 vRandom = normalize(RandomDir(Type, globalTime, randomTex)); 152 oPos = Pos + Vel * elapsedTime; 153 oUv2 = Vel + vRandom * 10.0; 154 oUv0 = P_EMBER2LIFE + 0.4 * vRandom.x; 155 oUv1 = PT_EMBER2; 156 EmitVertex(); 157 } 158 186 159 } 187 160 else 188 161 { 189 GSGenericHandler(Pos, Vel, Timer, Type, elapsedTime, frameGravity ); 162 GSGenericHandler(Pos, Vel, Timer, Type, elapsedTime, frameGravity); 163 } 164 } 165 166 // 167 // Ember1 and Ember3 type particle handler. 168 // 169 void GSEmber1Handler( vec3 Pos, vec3 Vel, float Timer, float Type, 170 float elapsedTime, 171 vec3 frameGravity) 172 { 173 if (Timer > 0) 174 { 175 GSGenericHandler(Pos, Vel, Timer, Type, elapsedTime, frameGravity); 176 } 177 } 178 179 // 180 // Ember2 type particle handler. 181 // 182 void GSEmber2Handler( vec3 Pos, vec3 Vel, float Timer, float Type, 183 float elapsedTime, 184 float globalTime, 185 sampler1D randomTex, 186 vec3 frameGravity) 187 { 188 if (Timer <= 0) 189 { 190 // Time to emit a series of new Ember3's. 191 for (int i = 0; i < NUM_EMBER_3S; i++) 192 { 193 oPos = Pos + Vel * elapsedTime; 194 oUv2 = Vel + normalize(RandomDir(Type + i, globalTime, randomTex)) * 10.0; 195 oUv0 = P_EMBER3LIFE; 196 oUv1 = PT_EMBER3; 197 EmitVertex(); 198 } 199 } 200 else 201 { 202 GSGenericHandler(Pos, Vel, Timer, Type, elapsedTime, frameGravity); 190 203 } 191 204 } … … 193 206 void main() 194 207 { 195 if( FireworkData[0].Type == PT_LAUNCHER ) 196 GSLauncherHandler( FireworkData[0].Pos.xyz, FireworkData[0].Vel, FireworkData[0].Timer, FireworkData[0].Type, 197 elapsedTime, globalTime, randomTex, secondsPerFirework); 198 else if ( FireworkData[0].Type == PT_SHELL ) 199 GSShellHandler( FireworkData[0].Pos.xyz, FireworkData[0].Vel, FireworkData[0].Timer, FireworkData[0].Type, 200 elapsedTime, globalTime, randomTex, frameGravity); 201 else if ( FireworkData[0].Type == PT_EMBER1 || 202 FireworkData[0].Type == PT_EMBER3 ) 203 GSEmber1Handler( FireworkData[0].Pos.xyz, FireworkData[0].Vel, FireworkData[0].Timer, FireworkData[0].Type, 204 elapsedTime, frameGravity); 205 else if( FireworkData[0].Type == PT_EMBER2 ) 206 GSEmber2Handler( FireworkData[0].Pos.xyz, FireworkData[0].Vel, FireworkData[0].Timer, FireworkData[0].Type, 207 elapsedTime, globalTime, randomTex, frameGravity); 208 colour = vec4(1.0,1.0,0.0,1.0); 209 EndPrimitive(); 210 } 208 if (FireworkData[0].Type == PT_LAUNCHER) 209 GSLauncherHandler(FireworkData[0].Pos.xyz, FireworkData[0].Vel, FireworkData[0].Timer, FireworkData[0].Type, 210 elapsedTime, globalTime, randomTexture, secondsPerFirework); 211 else if (FireworkData[0].Type == PT_SHELL) 212 GSShellHandler(FireworkData[0].Pos.xyz, FireworkData[0].Vel, FireworkData[0].Timer, FireworkData[0].Type, 213 elapsedTime, globalTime, randomTexture, frameGravity); 214 else if (FireworkData[0].Type == PT_EMBER1 || 215 FireworkData[0].Type == PT_EMBER3) 216 GSEmber1Handler(FireworkData[0].Pos.xyz, FireworkData[0].Vel, FireworkData[0].Timer, FireworkData[0].Type, 217 elapsedTime, frameGravity); 218 else if (FireworkData[0].Type == PT_EMBER2) 219 GSEmber2Handler(FireworkData[0].Pos.xyz, FireworkData[0].Vel, FireworkData[0].Timer, FireworkData[0].Type, 220 elapsedTime, globalTime, randomTexture, frameGravity); 221 EndPrimitive(); 222 223 // // gl_Position.xyz = FireworkData[0].Pos;// + FireworkData[0].Vel * elapsedTime; 224 // // gl_Position.w = 1; 225 // gl_Position = FireworkData[0].Pos + 1;// + FireworkData[0].Vel * elapsedTime; 226 // // gl_Position = Pos[0];// + FireworkData[0].Vel * elapsedTime; 227 // //gl_Position = vec4(10, 10, 10, 1); 228 // // oUv0 = P_SHELLLIFE + 0.5; 229 // oUv0 = FireworkData[0].Timer; 230 // // oUv0 = Timer[0]; 231 // oUv1 = FireworkData[0].Type; 232 // // oUv1 = Type[0]; 233 // oUv2 = FireworkData[0].Vel; 234 // // oUv2 = Vel[0]; 235 // //oUv2 = vec3(4, 5, 35.0); 236 // EmitVertex(); 237 // EndPrimitive(); 238 // // // gl_Position = vec4(10, 20, 30, 1); 239 // gl_Position = vec3(10, 20, 30); 240 // oUv0 = P_EMBER3LIFE; 241 // oUv1 = PT_SHELL; 242 // oUv2 = vec3(40, 50, 60); 243 // EmitVertex(); 244 // EndPrimitive(); 245 } -
data/branches/Shader_HS18/programs/Example/GLSL150/ParticleGS_GenerateVS.glsl
r12083 r12091 1 1 #version 150 2 2 3 in vec4 vertex; 4 uniform float inTimer; 5 uniform float inType; 6 uniform vec3 inVelocity; 3 in vec3 vertex; 4 in float uv0; // Timer 5 in float uv1; // Type 6 in vec3 uv2; // Velocity 7 // in float inTimer; 8 // in float inType; 9 // in vec3 inVelocity; 10 7 11 8 12 out block { 9 vec4Pos;10 floatTimer;11 float 12 vec3Vel;13 vec3 Pos; 14 float Timer; 15 float Type; 16 vec3 Vel; 13 17 } FireworkData; 18 19 // out vec3 Pos; 20 // out float Timer; 21 // out float Type; 22 // out vec3 Vel; 14 23 15 24 //The vertex shader that prepares the fireworks for display 16 25 void main() 17 26 { 18 FireworkData.Pos = vertex; 19 FireworkData.Timer = inTimer; 20 FireworkData.Type = inType; 21 FireworkData.Vel = inVelocity; 27 FireworkData.Pos = vertex; 28 FireworkData.Timer = uv0; 29 FireworkData.Type = uv1; 30 FireworkData.Vel = uv2; 31 // Pos = vertex; 32 // Timer = uv0; 33 // Type = uv1; 34 // Vel = uv2; 35 36 // FireworkData.Pos = vertex; 37 // FireworkData.Timer = 1; 38 // FireworkData.Type = 8; 39 // FireworkData.Vel = vec3(3, 3, 3); 22 40 } -
data/branches/Shader_HS18/programs/Example/GLSL150/PosterizeFP.glsl
r12083 r12091 7 7 void main() 8 8 { 9 10 9 float nColors = 8.0; 10 float gamma = 0.6; 11 11 12 13 14 15 16 17 18 tc = pow(tc, vec3(1.0/gamma));19 12 vec4 texCol = vec4(texture(RT, oUv0)); 13 vec3 tc = texCol.xyz; 14 tc = pow(tc, vec3(gamma)); 15 tc = tc * nColors; 16 tc = floor(tc); 17 tc = tc / nColors; 18 tc = pow(tc, vec3(1.0 / gamma)); 19 fragColour = vec4(tc, texCol.w); 20 20 } -
data/branches/Shader_HS18/programs/Example/GLSL150/StdQuad_vp.glsl
r12083 r12091 2 2 3 3 in vec4 vertex; 4 in vec2 uv0;4 // in vec2 uv0; 5 5 uniform mat4 worldViewProj; 6 6 7 7 out vec2 oUv0; 8 8 9 void main() 9 void main() 10 10 { 11 gl_Position = worldViewProj * vertex; 12 13 oUv0 = uv0; 11 gl_Position = worldViewProj * vertex; 12 13 // oUv0 = uv0; 14 15 vec2 inPos = sign(vertex.xy); 16 17 oUv0 = (vec2(inPos.x, -inPos.y) + 1.0) * 0.5; 14 18 } 15 -
data/branches/Shader_HS18/programs/Example/GLSL150/SwizzleGP.glsl
r12083 r12091 1 1 #version 150 2 2 3 #extension GL_EXT_geometry_shader4 : enable 3 uniform vec4 origColour; 4 uniform vec4 cloneColour; 4 5 5 uniform vec4 origColor; 6 uniform vec4 cloneColor; 6 out vec4 colour; 7 7 8 void main(void) 9 { 8 layout(triangles) in; 9 layout(line_strip, max_vertices = 6) out; 10 10 11 //increment variable 12 int i; 11 void main() 12 { 13 // Pass-through! 14 for (int i = 0; i < gl_in.length(); i++){ 15 gl_Position = gl_in[i].gl_Position; 16 colour = origColour; 17 EmitVertex(); 18 } 19 EndPrimitive(); 13 20 14 ///////////////////////////////////////////////////////////// 15 //This example has two parts 16 // step a) draw the primitive pushed down the pipeline 17 // there are gl_Vertices # of vertices 18 // put the vertex value into gl_Position 19 // use EmitVertex => 'create' a new vertex 20 // use EndPrimitive to signal that you are done creating a primitive! 21 // step b) create a new piece of geometry (I.E. WHY WE ARE USING A GEOMETRY SHADER!) 22 // I just do the same loop, but swizzle the x and y values 23 // result => the line we want to draw, and the same line, but along the other axis 24 25 //Pass-thru! 26 for(i=0; i< gl_VerticesIn; i++){ 27 gl_Position = gl_PositionIn[i]; 28 gl_FrontColor = origColor; 29 EmitVertex(); 30 } 31 EndPrimitive(); 32 //New piece of geometry! We just swizzle the x and y terms 33 for(i=0; i< gl_VerticesIn; i++){ 34 gl_Position = gl_PositionIn[i]; 35 gl_Position.xy = gl_Position.yx; 36 gl_FrontColor = cloneColor; 37 EmitVertex(); 38 } 39 EndPrimitive(); 40 21 // New piece of geometry! We just swizzle the x and y terms. 22 for (int i = 0; i < gl_in.length(); i++){ 23 gl_Position = gl_in[i].gl_Position; 24 gl_Position.xy = gl_Position.yx; 25 colour = cloneColour; 26 EmitVertex(); 27 } 28 EndPrimitive(); 41 29 } -
data/branches/Shader_HS18/programs/Example/GLSL150/mrttestfp_scene.glsl
r12083 r12091 1 #version 1 501 #version 130 2 2 3 3 // Need to enable the draw buffers extension
Note: See TracChangeset
for help on using the changeset viewer.