09-24-2024, 10:01 AM
(This post was last modified: 09-24-2024, 10:05 AM by aadityap0901.)
From what I understood, we need to assign normal vectors for each 4 vertices of the face (I am using GL_QUADS btw) and not just the face.
This is what I did:
GL Code:
Take LV as the new index
Vertices are Vector3, TexCoords are Vector2, Normals are Vector3
(Take Visibility (Unsigned Byte) = -1
AssetsModelVertices(1 to 24), AssetsModelTexCoords(1 to 24) are the hardcoded vertices and texture coords for a cube
BlockFaces Array includes which Texture is used at each face
I am using Texture Atlas)
![[Image: 09242024152752.png]](https://i.ibb.co/ZTg093r/09242024152752.png)
Some blocks have a different light effect.
This is what I did:
GL Code:
Code: (Select All)
_glEnable _GL_LIGHTING
_glEnable _GL_LIGHT0
_glLightfv _GL_LIGHT0, _GL_AMBIENT, glVec4(SkyColorRed, SkyColorGreen, SkyColorBlue, 0)
_glLightfv _GL_LIGHT0, _GL_DIFFUSE, glVec4(SkyColorRed, SkyColorGreen, SkyColorBlue, 0)
_glLightfv _GL_LIGHT0, _GL_SPECULAR, glVec4(SkyColorRed, SkyColorGreen, SkyColorBlue, 0)
_glLightfv _GL_LIGHT0, _GL_POSITION, glVec4(Player_Position.X, Player_Position.Y, Player_Position.Z, 0)
_glLightfv _GL_LIGHT0, _GL_SPOT_DIRECTION, glVec4(0, 1, 0, 0)
_glLightfv _GL_LIGHT0, _GL_SPOT_EXPONENT, glVec4(1, 0, 0, 0)
_glEnable _GL_COLOR_MATERIAL
_glColorMaterial _GL_FRONT, _GL_DIFFUSE
_glEnable _GL_TEXTURE_2D
_glBindTexture _GL_TEXTURE_2D, TextureHandle
_glEnableClientState _GL_VERTEX_ARRAY
_glEnableClientState _GL_TEXTURE_COORD_ARRAY
_glEnableClientState _GL_NORMAL_ARRAY
For I = LBound(Chunks) - 1 To UBound(Chunks) - 1
If Chunks(I + 1).ShowCount = 0 Or Chunks(I + 1).isRenderDataLoaded = 0 Then _Continue
_glVertexPointer 3, _GL_SHORT, 0, _Offset(Vertices(I * ChunkSectionVerticesSize + 1))
_glTexCoordPointer 2, _GL_FLOAT, 0, _Offset(TexCoords(I * ChunkSectionVerticesSize + 1))
_glNormalPointer _GL_FLOAT, 0, _Offset(Normals(I * ChunkSectionNormalsSize + 1))
_glDrawArrays _GL_QUADS, 0, Chunks(I + 1).ShowCount
Next I
_glDisableClientState _GL_VERTEX_ARRAY
_glDisableClientState _GL_TEXTURE_COORD_ARRAY
_glDisableClientState _GL_NORMAL_ARRAY
_glDisable _GL_TEXTURE_2D
_glDisable _GL_COLOR_MATERIAL
_glDisable _GL_LIGHT0
_glDisable _GL_LIGHTING
Code for assigning Vertices, Texture Coords, NormalsTake LV as the new index
Vertices are Vector3, TexCoords are Vector2, Normals are Vector3
(Take Visibility (Unsigned Byte) = -1
AssetsModelVertices(1 to 24), AssetsModelTexCoords(1 to 24) are the hardcoded vertices and texture coords for a cube
BlockFaces Array includes which Texture is used at each face
I am using Texture Atlas)
Code: (Select All)
For I = 0 To 23
Face = _SHL(1, _SHR(I, 2))
If (Face And Visibility) = 0 Then _Continue
LV = LV + 1
Vertices(LV).X = AssetsModelVertices(I + 1).X + CX16 + X
Vertices(LV).Y = AssetsModelVertices(I + 1).Y + Y
Vertices(LV).Z = AssetsModelVertices(I + 1).Z + CZ16 + Z
TexCoords(LV).X = AssetsModelTexCoords(I + 1).X
TexCoords(LV).Y = (AssetsModelTexCoords(I + 1).Y + BlockFaces(Block, _SHR(I, 2) + 1) - 1) / TotalImages
Chunks(FoundI).Count = Chunks(FoundI).Count + 1
Select Case _SHR(I, 2)
Case 1: Normals(LV).X = 1: Normals(LV).Y = 0: Normals(LV).Z = 0
Case 2: Normals(LV).X = -1: Normals(LV).Y = 0: Normals(LV).Z = 0
Case 3: Normals(LV).X = 0: Normals(LV).Y = 1: Normals(LV).Z = 0
Case 4: Normals(LV).X = 0: Normals(LV).Y = -1: Normals(LV).Z = 0
Case 5: Normals(LV).X = 0: Normals(LV).Y = 0: Normals(LV).Z = 1
Case 6: Normals(LV).X = 0: Normals(LV).Y = 0: Normals(LV).Z = -1
End Select
Next I
It gave me this result:![[Image: 09242024152752.png]](https://i.ibb.co/ZTg093r/09242024152752.png)
Some blocks have a different light effect.

