mirror of
https://github.com/photonstorm/phaser
synced 2024-11-22 12:43:26 +00:00
Fixed shader for clip-space
This commit is contained in:
parent
b1a5ce7f55
commit
d3d0c71fe4
4 changed files with 25 additions and 18 deletions
|
@ -3,19 +3,20 @@ module.exports = [
|
|||
'',
|
||||
'precision mediump float;',
|
||||
'',
|
||||
'varying vec2 lightPosition;',
|
||||
'varying vec4 lightPosition;',
|
||||
'varying vec4 lightColor;',
|
||||
'varying float lightRadius;',
|
||||
'',
|
||||
'void main()',
|
||||
'{',
|
||||
' vec2 res = vec2(800.0, 600.0);',
|
||||
' vec2 center = vec2(lightPosition.x, res.y - lightPosition.y);',
|
||||
'',
|
||||
' vec2 center = vec2((lightPosition.x + 1.0) * (res.x / 2.0), (lightPosition.y + 1.0) * (res.y / 2.0));',
|
||||
'',
|
||||
' float distance = length(center.xy - gl_FragCoord.xy);',
|
||||
'',
|
||||
' // float intensity = 1.0 - min(distance, lightRadius) / lightRadius;',
|
||||
' float intensity = clamp(1.0 - distance * distance / (lightRadius * lightRadius), 0.0, 1.0);',
|
||||
' float intensity = 1.0 - min(distance, lightRadius) / lightRadius;',
|
||||
' // float intensity = clamp(1.0 - distance * distance / (lightRadius * lightRadius), 0.0, 1.0);',
|
||||
'',
|
||||
' vec4 color = vec4(intensity, intensity, intensity, 0.0) * vec4(lightColor.r, lightColor.g, lightColor.b, 1.0);',
|
||||
'',
|
||||
|
|
|
@ -12,17 +12,19 @@ module.exports = [
|
|||
'attribute vec4 inLightColor;',
|
||||
'attribute float inLightRadius;',
|
||||
'',
|
||||
'varying vec2 lightPosition;',
|
||||
'varying vec4 lightPosition;',
|
||||
'varying vec4 lightColor;',
|
||||
'varying float lightRadius;',
|
||||
'',
|
||||
'void main ()',
|
||||
'{',
|
||||
' lightRadius = inLightRadius;',
|
||||
' lightColor = inLightColor;',
|
||||
' lightPosition = inLightPosition;',
|
||||
' mat4 mvp = uProjectionMatrix * uViewMatrix * uModelMatrix;',
|
||||
'',
|
||||
' gl_Position = uProjectionMatrix * uViewMatrix * uModelMatrix * vec4(inPosition, 1.0, 1.0);',
|
||||
' lightColor = inLightColor;',
|
||||
' lightRadius = inLightRadius;',
|
||||
' lightPosition = mvp * vec4(inLightPosition, 1.0, 1.0);',
|
||||
'',
|
||||
' gl_Position = mvp * vec4(inPosition, 1.0, 1.0);',
|
||||
'}',
|
||||
''
|
||||
].join('\n');
|
||||
|
|
|
@ -2,19 +2,21 @@
|
|||
|
||||
precision mediump float;
|
||||
|
||||
varying vec2 lightPosition;
|
||||
varying vec4 lightPosition;
|
||||
varying vec4 lightColor;
|
||||
varying float lightRadius;
|
||||
|
||||
void main()
|
||||
{
|
||||
// Half these and pass as uniform
|
||||
vec2 res = vec2(800.0, 600.0);
|
||||
vec2 center = vec2(lightPosition.x, res.y - lightPosition.y);
|
||||
|
||||
vec2 center = vec2((lightPosition.x + 1.0) * (res.x / 2.0), (lightPosition.y + 1.0) * (res.y / 2.0));
|
||||
|
||||
float distance = length(center.xy - gl_FragCoord.xy);
|
||||
|
||||
// float intensity = 1.0 - min(distance, lightRadius) / lightRadius;
|
||||
float intensity = clamp(1.0 - distance * distance / (lightRadius * lightRadius), 0.0, 1.0);
|
||||
float intensity = 1.0 - min(distance, lightRadius) / lightRadius;
|
||||
// float intensity = clamp(1.0 - distance * distance / (lightRadius * lightRadius), 0.0, 1.0);
|
||||
|
||||
vec4 color = vec4(intensity, intensity, intensity, 0.0) * vec4(lightColor.r, lightColor.g, lightColor.b, 1.0);
|
||||
|
||||
|
|
|
@ -11,15 +11,17 @@ attribute vec2 inLightPosition;
|
|||
attribute vec4 inLightColor;
|
||||
attribute float inLightRadius;
|
||||
|
||||
varying vec2 lightPosition;
|
||||
varying vec4 lightPosition;
|
||||
varying vec4 lightColor;
|
||||
varying float lightRadius;
|
||||
|
||||
void main ()
|
||||
{
|
||||
lightRadius = inLightRadius;
|
||||
lightColor = inLightColor;
|
||||
lightPosition = inLightPosition;
|
||||
mat4 mvp = uProjectionMatrix * uViewMatrix * uModelMatrix;
|
||||
|
||||
gl_Position = uProjectionMatrix * uViewMatrix * uModelMatrix * vec4(inPosition, 1.0, 1.0);
|
||||
lightColor = inLightColor;
|
||||
lightRadius = inLightRadius;
|
||||
lightPosition = mvp * vec4(inLightPosition, 1.0, 1.0);
|
||||
|
||||
gl_Position = mvp * vec4(inPosition, 1.0, 1.0);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue