aboutsummaryrefslogtreecommitdiff
path: root/engine/src/core-data/Common
diff options
context:
space:
mode:
Diffstat (limited to 'engine/src/core-data/Common')
-rw-r--r--engine/src/core-data/Common/MatDefs/Light/Lighting.frag4
-rw-r--r--engine/src/core-data/Common/MatDefs/Misc/Particle.j3md26
-rw-r--r--engine/src/core-data/Common/MatDefs/Misc/SoftParticle.frag50
-rw-r--r--engine/src/core-data/Common/MatDefs/Misc/SoftParticle.vert53
4 files changed, 133 insertions, 0 deletions
diff --git a/engine/src/core-data/Common/MatDefs/Light/Lighting.frag b/engine/src/core-data/Common/MatDefs/Light/Lighting.frag
index 76f0e15..eb1c3fd 100644
--- a/engine/src/core-data/Common/MatDefs/Light/Lighting.frag
+++ b/engine/src/core-data/Common/MatDefs/Light/Lighting.frag
@@ -126,6 +126,10 @@ vec2 computeLighting(in vec3 wvNorm, in vec3 wvViewDir, in vec3 wvLightDir){
float att = vLightDir.w;
#endif
+ if (m_Shininess <= 1.0) {
+ specularFactor = 0.0; // should be one instruction on most cards ..
+ }
+
specularFactor *= diffuseFactor;
return vec2(diffuseFactor, specularFactor) * vec2(att);
diff --git a/engine/src/core-data/Common/MatDefs/Misc/Particle.j3md b/engine/src/core-data/Common/MatDefs/Misc/Particle.j3md
index e28d41a..73674f9 100644
--- a/engine/src/core-data/Common/MatDefs/Misc/Particle.j3md
+++ b/engine/src/core-data/Common/MatDefs/Misc/Particle.j3md
@@ -4,6 +4,10 @@ MaterialDef Point Sprite {
Texture2D Texture
Float Quadratic
Boolean PointSprite
+
+ //only used for soft particles
+ Texture2D DepthTexture
+ Float Softness
// Texture of the glowing parts of the material
Texture2D GlowMap
@@ -58,6 +62,28 @@ MaterialDef Point Sprite {
}
}
+ Technique SoftParticles{
+
+ VertexShader GLSL100 : Common/MatDefs/Misc/SoftParticle.vert
+ FragmentShader GLSL100 : Common/MatDefs/Misc/SoftParticle.frag
+
+ WorldParameters {
+ WorldViewProjectionMatrix
+ WorldViewMatrix
+ WorldMatrix
+ CameraPosition
+ }
+
+ RenderState {
+ Blend AlphaAdditive
+ DepthWrite Off
+ }
+
+ Defines {
+ USE_TEXTURE : Texture
+ }
+ }
+
Technique FixedFunc {
RenderState {
Blend AlphaAdditive
diff --git a/engine/src/core-data/Common/MatDefs/Misc/SoftParticle.frag b/engine/src/core-data/Common/MatDefs/Misc/SoftParticle.frag
new file mode 100644
index 0000000..d3108b5
--- /dev/null
+++ b/engine/src/core-data/Common/MatDefs/Misc/SoftParticle.frag
@@ -0,0 +1,50 @@
+uniform sampler2D m_DepthTexture;
+uniform float m_Softness; // Power used in the contrast function
+varying vec2 vPos; // Position of the pixel
+varying vec2 projPos;// z and w valus in projection space
+
+#ifdef USE_TEXTURE
+uniform sampler2D m_Texture;
+varying vec4 texCoord;
+#endif
+
+varying vec4 color;
+
+float Contrast(float d){
+ float val = clamp( 2.0*( (d > 0.5) ? 1.0-d : d ), 0.0, 1.0);
+ float a = 0.5 * pow(val, m_Softness);
+ return (d > 0.5) ? 1.0 - a : a;
+}
+
+float stdDiff(float d){
+ return clamp((d)*m_Softness,0.0,1.0);
+}
+
+
+void main(){
+ if (color.a <= 0.01)
+ discard;
+
+ vec4 c = vec4(1.0,1.0,1.0,1.0);//color;
+ #ifdef USE_TEXTURE
+ #ifdef POINT_SPRITE
+ vec2 uv = mix(texCoord.xy, texCoord.zw, gl_PointCoord.xy);
+ #else
+ vec2 uv = texCoord.xy;
+ #endif
+ c = texture2D(m_Texture, uv) * color;
+ #endif
+
+
+ float depthv = texture2D(m_DepthTexture, vPos).x*2.0-1.0; // Scene depth
+ depthv*=projPos.y;
+ float particleDepth = projPos.x;
+
+ float zdiff =depthv-particleDepth;
+ if(zdiff<=0.0){
+ discard;
+ }
+ // Computes alpha based on the particles distance to the rest of the scene
+ c.a = c.a * stdDiff(zdiff);// Contrast(zdiff);
+ gl_FragColor =c;
+} \ No newline at end of file
diff --git a/engine/src/core-data/Common/MatDefs/Misc/SoftParticle.vert b/engine/src/core-data/Common/MatDefs/Misc/SoftParticle.vert
new file mode 100644
index 0000000..4f0dfd5
--- /dev/null
+++ b/engine/src/core-data/Common/MatDefs/Misc/SoftParticle.vert
@@ -0,0 +1,53 @@
+uniform mat4 g_WorldViewProjectionMatrix;
+
+attribute vec3 inPosition;
+attribute vec4 inColor;
+attribute vec4 inTexCoord;
+
+varying vec4 color;
+// z and w values in projection space
+varying vec2 projPos;
+varying vec2 vPos; // Position of the pixel in clip space
+
+
+
+#ifdef USE_TEXTURE
+varying vec4 texCoord;
+#endif
+
+#ifdef POINT_SPRITE
+uniform mat4 g_WorldViewMatrix;
+uniform mat4 g_WorldMatrix;
+uniform vec3 g_CameraPosition;
+uniform float m_Quadratic;
+const float SIZE_MULTIPLIER = 4.0;
+attribute float inSize;
+#endif
+
+void main(){
+ vec4 pos = vec4(inPosition, 1.0);
+
+ gl_Position = g_WorldViewProjectionMatrix * pos;
+ color = inColor;
+
+ projPos = gl_Position.zw;
+ // projPos.x = 0.5 * (projPos.x) + 0.5;
+
+ // Transforms the vPosition data to the range [0,1]
+ vPos = (gl_Position.xy / gl_Position.w + 1.0) / 2.0;
+
+ #ifdef USE_TEXTURE
+ texCoord = inTexCoord;
+ #endif
+
+ #ifdef POINT_SPRITE
+ vec4 worldPos = g_WorldMatrix * pos;
+ float d = distance(g_CameraPosition.xyz, worldPos.xyz);
+ gl_PointSize = max(1.0, (inSize * SIZE_MULTIPLIER * m_Quadratic) / d);
+
+ //vec4 worldViewPos = g_WorldViewMatrix * pos;
+ //gl_PointSize = (inSize * SIZE_MULTIPLIER * m_Quadratic)*100.0 / worldViewPos.z;
+
+ color.a *= min(gl_PointSize, 1.0);
+ #endif
+} \ No newline at end of file