Rewrote collision shader to use generated normals with fake lighting instead of generated UV coords
This commit is contained in:
parent
b362a23e4b
commit
c0fb54888d
|
@ -1,17 +1,16 @@
|
|||
#version 330 core
|
||||
|
||||
// Input
|
||||
in vec2 TexCoord;
|
||||
in vec4 LightColor;
|
||||
|
||||
// Output
|
||||
out vec4 PixelColor;
|
||||
|
||||
// Uniforms
|
||||
uniform sampler2D Texture;
|
||||
uniform vec4 TintColor;
|
||||
|
||||
// Main
|
||||
void main()
|
||||
{
|
||||
PixelColor = vec4(texture(Texture, TexCoord).rgb, 0) * TintColor;
|
||||
PixelColor = LightColor * TintColor;
|
||||
}
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
// This shader will be obsoleted soon when the collision rendering is improved
|
||||
#version 330 core
|
||||
|
||||
// Input
|
||||
layout(location = 0) in vec3 Position;
|
||||
layout(location = 0) in vec3 RawPosition;
|
||||
layout(location = 1) in vec3 RawNormal;
|
||||
|
||||
// Output
|
||||
out vec2 TexCoord;
|
||||
out vec4 LightColor;
|
||||
|
||||
// Uniforms
|
||||
layout(std140) uniform MVPBlock
|
||||
|
@ -18,11 +18,12 @@ layout(std140) uniform MVPBlock
|
|||
// Main
|
||||
void main()
|
||||
{
|
||||
mat4 MVP = ModelMtx * ViewMtx * ProjMtx;
|
||||
gl_Position = vec4(Position, 1) * MVP;
|
||||
mat4 MVP = ModelMtx * ViewMtx * ProjMtx;
|
||||
gl_Position = vec4(RawPosition, 1) * MVP;
|
||||
|
||||
// UV Generation
|
||||
float avg = (Position.x + Position.z) / 2;
|
||||
TexCoord.x = avg;
|
||||
TexCoord.y = Position.y + (avg / 2);
|
||||
// Fake lighting; render one white skylight pointing straight down with an ambient 0.5
|
||||
float LightDot = dot(RawNormal, vec3(0, 0, -1));
|
||||
float Alpha = (-LightDot + 1.0) / 2;
|
||||
float LightAlpha = mix(0.5, 0.9, Alpha);
|
||||
LightColor = vec4(LightAlpha, LightAlpha, LightAlpha, 1.0);
|
||||
}
|
||||
|
|
|
@ -333,7 +333,6 @@ void CDrawUtil::UseCollisionShader(const CColor& TintColor /*= CColor::skWhite*/
|
|||
{
|
||||
Init();
|
||||
mpCollisionShader->SetCurrent();
|
||||
LoadCheckerboardTexture(0);
|
||||
|
||||
static GLuint TintColorLoc = mpCollisionShader->GetUniformLocation("TintColor");
|
||||
glUniform4f(TintColorLoc, TintColor.R, TintColor.G, TintColor.B, TintColor.A);
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
CCollisionMesh::CCollisionMesh()
|
||||
{
|
||||
mVBO.SetVertexDesc(ePosition);
|
||||
mVBO.SetVertexDesc(ePosition | eNormal);
|
||||
mVertexCount = 0;
|
||||
mLineCount = 0;
|
||||
mFaceCount = 0;
|
||||
|
@ -31,13 +31,10 @@ void CCollisionMesh::BufferGL()
|
|||
mBuffered = false;
|
||||
}
|
||||
|
||||
// Add all the verts to our VBO, first...
|
||||
mVBO.Reserve(mCollisionVertices.size());
|
||||
for (u16 iVtx = 0; iVtx < mCollisionVertices.size(); iVtx++)
|
||||
mVBO.AddVertex(CVertex(mCollisionVertices[iVtx].Pos));
|
||||
|
||||
// Then add all the relevant indices to the IBO
|
||||
// Add all the relevant indices to the IBO
|
||||
mVBO.Reserve(mCollisionFaces.size() * 3);
|
||||
mIBO.Reserve(mCollisionFaces.size() * 3);
|
||||
|
||||
for (u32 iVtx = 0; iVtx < mCollisionFaces.size(); iVtx++)
|
||||
{
|
||||
u16 Verts[3];
|
||||
|
@ -56,14 +53,29 @@ void CCollisionMesh::BufferGL()
|
|||
Verts[2] = pLineB->Vertices[1];
|
||||
|
||||
// Some faces have a property that indicates they need to be inverted
|
||||
if (!pFace->Properties.Invert)
|
||||
mIBO.AddIndices(&Verts[0], 3);
|
||||
|
||||
else
|
||||
if (pFace->Properties.Invert)
|
||||
{
|
||||
mIBO.AddIndex(Verts[2]);
|
||||
mIBO.AddIndex(Verts[1]);
|
||||
mIBO.AddIndex(Verts[0]);
|
||||
u16 V0 = Verts[0];
|
||||
Verts[0] = Verts[2];
|
||||
Verts[2] = V0;
|
||||
}
|
||||
|
||||
// Generate vertices - we don't share vertices between triangles in order to get the generated normals looking correct
|
||||
CCollisionVertex& rVert0 = mCollisionVertices[Verts[0]];
|
||||
CCollisionVertex& rVert1 = mCollisionVertices[Verts[1]];
|
||||
CCollisionVertex& rVert2 = mCollisionVertices[Verts[2]];
|
||||
|
||||
CVector3f V0toV1 = (rVert1.Pos - rVert0.Pos).Normalized();
|
||||
CVector3f V0toV2 = (rVert2.Pos - rVert0.Pos).Normalized();
|
||||
CVector3f FaceNormal = V0toV1.Cross(V0toV2).Normalized();
|
||||
|
||||
for (u32 iVtx = 0; iVtx < 3; iVtx++)
|
||||
{
|
||||
CVertex Vtx;
|
||||
Vtx.Position = mCollisionVertices[ Verts[iVtx] ].Pos;
|
||||
Vtx.Normal = FaceNormal;
|
||||
u16 Index = mVBO.AddVertex(Vtx);
|
||||
mIBO.AddIndex(Index);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -39,8 +39,6 @@ void CCollisionNode::Draw(FRenderOptions /*Options*/, int /*ComponentIndex*/, ER
|
|||
|
||||
CDrawUtil::UseCollisionShader(TintColor(rkViewInfo));
|
||||
mpCollision->Draw();
|
||||
CDrawUtil::UseColorShader(CColor::skTransparentBlack);
|
||||
mpCollision->DrawWireframe();
|
||||
}
|
||||
|
||||
SRayIntersection CCollisionNode::RayNodeIntersectTest(const CRay& /*rkRay*/, u32 /*AssetID*/, const SViewInfo& /*rkViewInfo*/)
|
||||
|
|
Loading…
Reference in New Issue