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
|
#version 330 core
|
||||||
|
|
||||||
// Input
|
// Input
|
||||||
in vec2 TexCoord;
|
in vec4 LightColor;
|
||||||
|
|
||||||
// Output
|
// Output
|
||||||
out vec4 PixelColor;
|
out vec4 PixelColor;
|
||||||
|
|
||||||
// Uniforms
|
// Uniforms
|
||||||
uniform sampler2D Texture;
|
|
||||||
uniform vec4 TintColor;
|
uniform vec4 TintColor;
|
||||||
|
|
||||||
// Main
|
// Main
|
||||||
void 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
|
#version 330 core
|
||||||
|
|
||||||
// Input
|
// Input
|
||||||
layout(location = 0) in vec3 Position;
|
layout(location = 0) in vec3 RawPosition;
|
||||||
|
layout(location = 1) in vec3 RawNormal;
|
||||||
|
|
||||||
// Output
|
// Output
|
||||||
out vec2 TexCoord;
|
out vec4 LightColor;
|
||||||
|
|
||||||
// Uniforms
|
// Uniforms
|
||||||
layout(std140) uniform MVPBlock
|
layout(std140) uniform MVPBlock
|
||||||
|
@ -18,11 +18,12 @@ layout(std140) uniform MVPBlock
|
||||||
// Main
|
// Main
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
mat4 MVP = ModelMtx * ViewMtx * ProjMtx;
|
mat4 MVP = ModelMtx * ViewMtx * ProjMtx;
|
||||||
gl_Position = vec4(Position, 1) * MVP;
|
gl_Position = vec4(RawPosition, 1) * MVP;
|
||||||
|
|
||||||
// UV Generation
|
// Fake lighting; render one white skylight pointing straight down with an ambient 0.5
|
||||||
float avg = (Position.x + Position.z) / 2;
|
float LightDot = dot(RawNormal, vec3(0, 0, -1));
|
||||||
TexCoord.x = avg;
|
float Alpha = (-LightDot + 1.0) / 2;
|
||||||
TexCoord.y = Position.y + (avg / 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();
|
Init();
|
||||||
mpCollisionShader->SetCurrent();
|
mpCollisionShader->SetCurrent();
|
||||||
LoadCheckerboardTexture(0);
|
|
||||||
|
|
||||||
static GLuint TintColorLoc = mpCollisionShader->GetUniformLocation("TintColor");
|
static GLuint TintColorLoc = mpCollisionShader->GetUniformLocation("TintColor");
|
||||||
glUniform4f(TintColorLoc, TintColor.R, TintColor.G, TintColor.B, TintColor.A);
|
glUniform4f(TintColorLoc, TintColor.R, TintColor.G, TintColor.B, TintColor.A);
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
|
|
||||||
CCollisionMesh::CCollisionMesh()
|
CCollisionMesh::CCollisionMesh()
|
||||||
{
|
{
|
||||||
mVBO.SetVertexDesc(ePosition);
|
mVBO.SetVertexDesc(ePosition | eNormal);
|
||||||
mVertexCount = 0;
|
mVertexCount = 0;
|
||||||
mLineCount = 0;
|
mLineCount = 0;
|
||||||
mFaceCount = 0;
|
mFaceCount = 0;
|
||||||
|
@ -31,13 +31,10 @@ void CCollisionMesh::BufferGL()
|
||||||
mBuffered = false;
|
mBuffered = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add all the verts to our VBO, first...
|
// Add all the relevant indices to the IBO
|
||||||
mVBO.Reserve(mCollisionVertices.size());
|
mVBO.Reserve(mCollisionFaces.size() * 3);
|
||||||
for (u16 iVtx = 0; iVtx < mCollisionVertices.size(); iVtx++)
|
|
||||||
mVBO.AddVertex(CVertex(mCollisionVertices[iVtx].Pos));
|
|
||||||
|
|
||||||
// Then add all the relevant indices to the IBO
|
|
||||||
mIBO.Reserve(mCollisionFaces.size() * 3);
|
mIBO.Reserve(mCollisionFaces.size() * 3);
|
||||||
|
|
||||||
for (u32 iVtx = 0; iVtx < mCollisionFaces.size(); iVtx++)
|
for (u32 iVtx = 0; iVtx < mCollisionFaces.size(); iVtx++)
|
||||||
{
|
{
|
||||||
u16 Verts[3];
|
u16 Verts[3];
|
||||||
|
@ -56,14 +53,29 @@ void CCollisionMesh::BufferGL()
|
||||||
Verts[2] = pLineB->Vertices[1];
|
Verts[2] = pLineB->Vertices[1];
|
||||||
|
|
||||||
// Some faces have a property that indicates they need to be inverted
|
// Some faces have a property that indicates they need to be inverted
|
||||||
if (!pFace->Properties.Invert)
|
if (pFace->Properties.Invert)
|
||||||
mIBO.AddIndices(&Verts[0], 3);
|
|
||||||
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
mIBO.AddIndex(Verts[2]);
|
u16 V0 = Verts[0];
|
||||||
mIBO.AddIndex(Verts[1]);
|
Verts[0] = Verts[2];
|
||||||
mIBO.AddIndex(Verts[0]);
|
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));
|
CDrawUtil::UseCollisionShader(TintColor(rkViewInfo));
|
||||||
mpCollision->Draw();
|
mpCollision->Draw();
|
||||||
CDrawUtil::UseColorShader(CColor::skTransparentBlack);
|
|
||||||
mpCollision->DrawWireframe();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SRayIntersection CCollisionNode::RayNodeIntersectTest(const CRay& /*rkRay*/, u32 /*AssetID*/, const SViewInfo& /*rkViewInfo*/)
|
SRayIntersection CCollisionNode::RayNodeIntersectTest(const CRay& /*rkRay*/, u32 /*AssetID*/, const SViewInfo& /*rkViewInfo*/)
|
||||||
|
|
Loading…
Reference in New Issue