Clouds are affected by (underlying) lightmap

This commit is contained in:
2021-08-31 16:04:42 +01:00
parent 90111594c0
commit f58530cbb1
3 changed files with 108 additions and 11 deletions
+57
View File
@@ -0,0 +1,57 @@
#version 430 core
// an attempt to test whether a geometry surface occludes the camera from a
// light source
layout (triangles) in;
layout (triangle_strip, max_vertices = 4) out;
layout (std140, binding = 0) uniform TheMat { mat4 theMat; } ;
uniform vec3 lightPos;
uniform vec2 camPos;
void main()
{
vec3 p0 = gl_in[0].gl_Position.xyz ;
vec3 p1 = gl_in[1].gl_Position.xyz ;
vec3 p2 = gl_in[2].gl_Position.xyz ;
// first determine intersection point (if any)
vec3 u = p1 - p0 ;
vec3 v = p2 - p0 ;
vec3 n = cross (u,v) ;
vec3 dir = vec3 (camPos, 100) - lightPos ;
vec3 w0 = p0 - lightPos ;
float a = dot(n, w0) ;
float b = dot(n,dir) ;
if (abs(b) < 0.00001) {}
else {
float r = a / b ;
if (r < 0.0) {}
else {
vec3 ip = lightPos + r * dir ;
float uu, uv, vv, wu, wv, D;
uu = dot(u,u);
uv = dot(u,v);
vv = dot(v,v);
vec3 w = ip - p0;
wu = dot (w,u);
wv = dot (w,v);
D = uv * uv - uu * vv;
//get and test parametric coords
float s, t;
s = (uv * wv - vv * wu) / D;
if (s < 0.0 || s > 1.0) {}
else
{
t = (uv * wu - uu * wv) / D;
if (t < 0.0 || (s + t) > 1.0) {}
else
{
gl_Position = vec4(-1,-1,50,1); EmitVertex();
gl_Position = vec4(-1, 1,50,1); EmitVertex();
gl_Position = vec4( 1,-1,50,1); EmitVertex();
gl_Position = vec4( 1, 1,50,1); EmitVertex();
EndPrimitive();
}
}
}
}
}
+26
View File
@@ -0,0 +1,26 @@
module Dodge.Creature.ShadowBox
where
import Dodge.Data
import Polyhedra
import Geometry
import qualified Data.IntMap as IM
crToBox :: Creature -> [[Point3]]
crToBox cr = map (map f . polyToTris) $ boxXYZ 10 10 15
where
f = (+ V3 (x-5) (y-5) 1)
V2 x y = _crPos cr
youBox' :: World -> [[Point3]]
youBox' w = crToBox' $ _creatures w IM.! 0
youBox :: World -> [Point3]
youBox = concat . youBox'
crToBox' :: Creature -> [[Point3]]
crToBox' cr = map (map f . polyToTris) $ boxXYZ 20 20 15
where
f = (+ V3 (x-10) (y-10) 1)
V2 x y = _crPos cr
youSil :: World -> [Point3]
youSil = constructEdgesList . youBox'
+25 -11
View File
@@ -122,13 +122,6 @@ doDrawing pdata w = do
viewport $= (Position 0 0
, divideSize (w ^. config . shadow_resolution) $ Size (round $ fstV2 wins) (round $ sndV2 wins))
-- bindFramebuffer Framebuffer $= fst (_fboColor pdata)
-- clear [ColorBuffer]
-- depthMask $= Disabled
-- blendEquation $= FuncAdd
-- renderLayer 3 shadV layerCounts
-- renderLayer 4 shadV layerCounts
-- renderLayer 5 shadV layerCounts
--
-- depthMask $= Enabled
-- this is not ideal if the original is not divisible by 2
@@ -138,6 +131,27 @@ doDrawing pdata w = do
colorMask $= Color4 Enabled Enabled Enabled Enabled
clearColor $= Color4 0 0 0 0
bindFramebuffer Framebuffer $= fst (_fboColor pdata)
clearColor $= Color4 0 0 0 0
clear [ColorBuffer]
depthFunc $= Just Lequal
depthMask $= Disabled
blendFuncSeparate $= ((SrcAlpha,OneMinusSrcAlpha),(SrcAlpha,One))
--blendFunc $= (SrcAlpha,One)
renderLayer 2 shadV layerCounts
clearColor $= Color4 0 0 0 0
depthMask $= Enabled
depthMask $= Disabled
depthFunc $= Just Always
textureBinding Texture2D $= Just (snd $ _fboLighting pdata)
blend $= Enabled
--blendFunc $= (Zero, OneMinusSrcAlpha)
blendFuncSeparate $= ((Zero, OneMinusSrcColor),(Zero, One))
drawShader (_fullscreenShader pdata) 4
blendFunc $= (SrcAlpha, OneMinusSrcAlpha)
-- renderLayer 4 shadV layerCounts
-- renderLayer 5 shadV layerCounts
--blend $= Disabled
depthMask $= Disabled
depthFunc $= Just Always
@@ -152,7 +166,6 @@ doDrawing pdata w = do
drawShader (_fullscreenShader pdata) 4
blendFunc $= (SrcAlpha, OneMinusSrcAlpha)
--textureBinding Texture2D $= Just (snd $ _fboColor pdata)
--drawShader (_colorBlurShader pdata) 4
blendFunc $= (SrcAlpha, One)
textureBinding Texture2D $= Just (snd $ _fboFourth1 pdata)
@@ -161,10 +174,11 @@ doDrawing pdata w = do
-- textureBinding Texture2D $= Just (snd $ _fboBloom pdata)
-- drawShader (_fullscreenShader pdata) 4
depthFunc $= Just Lequal
--mapM_ (uncurry $ drawShaderLay 2) (vnums IM.! 2)
renderLayer 2 shadV layerCounts
textureBinding Texture2D $= Just (snd $ _fboColor pdata)
drawShader (_fullscreenShader pdata) 4
--renderLayer 2 shadV layerCounts
renderWindows pdata windowPoints
depthFunc $= Just Lequal
viewport $= (Position 0 0, Size (round $ fstV2 wins) (round $ sndV2 wins))
depthFunc $= Just Always