REVIEWED: Ligthmap example
This commit is contained in:
parent
abcbd9817e
commit
5573f0f1c7
4 changed files with 81 additions and 72 deletions
|
@ -1,4 +1,5 @@
|
|||
#version 330
|
||||
|
||||
// Input vertex attributes (from vertex shader)
|
||||
in vec2 fragTexCoord;
|
||||
in vec2 fragTexCoord2;
|
||||
|
@ -12,9 +13,11 @@ uniform sampler2D texture1;
|
|||
// Output fragment color
|
||||
out vec4 finalColor;
|
||||
|
||||
void main() {
|
||||
void main()
|
||||
{
|
||||
// Texel color fetching from texture sampler
|
||||
vec4 texelColor = texture( texture0, fragTexCoord );
|
||||
vec4 texelColor2 = texture( texture1, fragTexCoord2 );
|
||||
vec4 texelColor = texture(texture0, fragTexCoord);
|
||||
vec4 texelColor2 = texture(texture1, fragTexCoord2);
|
||||
|
||||
finalColor = texelColor * texelColor2;
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#version 330
|
||||
|
||||
// Input vertex attributes
|
||||
in vec3 vertexPosition;
|
||||
in vec2 vertexTexCoord;
|
||||
|
@ -15,13 +16,14 @@ out vec2 fragTexCoord;
|
|||
out vec2 fragTexCoord2;
|
||||
out vec4 fragColor;
|
||||
|
||||
void main() {
|
||||
void main()
|
||||
{
|
||||
// Send vertex attributes to fragment shader
|
||||
fragPosition = vec3( matModel * vec4( vertexPosition, 1.0 ) );
|
||||
fragPosition = vec3(matModel*vec4(vertexPosition, 1.0));
|
||||
fragTexCoord = vertexTexCoord;
|
||||
fragTexCoord2 = vertexTexCoord2;
|
||||
fragColor = vertexColor;
|
||||
|
||||
// Calculate final vertex position
|
||||
gl_Position = mvp * vec4( vertexPosition, 1.0 );
|
||||
gl_Position = mvp*vec4(vertexPosition, 1.0);
|
||||
}
|
||||
|
|
|
@ -46,8 +46,8 @@ int main(void)
|
|||
|
||||
// Define the camera to look into our 3d world
|
||||
Camera camera = { 0 };
|
||||
camera.position = (Vector3){ 2.0f, 4.0f, 6.0f }; // Camera position
|
||||
camera.target = (Vector3){ 0.0f, 0.5f, 0.0f }; // Camera looking at point
|
||||
camera.position = (Vector3){ 4.0f, 6.0f, 8.0f }; // Camera position
|
||||
camera.target = (Vector3){ 0.0f, 0.0f, 0.0f }; // Camera looking at point
|
||||
camera.up = (Vector3){ 0.0f, 1.0f, 0.0f }; // Camera up vector (rotation towards target)
|
||||
camera.fovy = 45.0f; // Camera field-of-view Y
|
||||
camera.projection = CAMERA_PERSPECTIVE; // Camera projection type
|
||||
|
@ -55,7 +55,7 @@ int main(void)
|
|||
Mesh mesh = GenMeshPlane((float)MAP_SIZE, (float)MAP_SIZE, 1, 1);
|
||||
|
||||
// GenMeshPlane doesn't generate texcoords2 so we will upload them separately
|
||||
mesh.texcoords2 = (float *)RL_MALLOC(mesh.vertexCount * 2 * sizeof(float));
|
||||
mesh.texcoords2 = (float *)RL_MALLOC(mesh.vertexCount*2*sizeof(float));
|
||||
|
||||
// X // Y
|
||||
mesh.texcoords2[0] = 0.0f; mesh.texcoords2[1] = 0.0f;
|
||||
|
@ -66,6 +66,7 @@ int main(void)
|
|||
// Load a new texcoords2 attributes buffer
|
||||
mesh.vboId[SHADER_LOC_VERTEX_TEXCOORD02] = rlLoadVertexBuffer(mesh.texcoords2, mesh.vertexCount*2*sizeof(float), false);
|
||||
rlEnableVertexArray(mesh.vaoId);
|
||||
|
||||
// Index 5 is for texcoords2
|
||||
rlSetVertexAttribute(5, 2, RL_FLOAT, 0, 0, 0);
|
||||
rlEnableVertexAttribute(5);
|
||||
|
@ -146,12 +147,15 @@ int main(void)
|
|||
|
||||
DrawTexturePro(
|
||||
lightmap.texture,
|
||||
(Rectangle){ 0, 0, MAP_SIZE, MAP_SIZE },
|
||||
(Rectangle){ 0, 36, MAP_SIZE * 4, MAP_SIZE * 4 },
|
||||
(Rectangle){ 0, 0, -MAP_SIZE, -MAP_SIZE },
|
||||
(Rectangle){ GetRenderWidth() - MAP_SIZE*8 - 10, 10, MAP_SIZE*8, MAP_SIZE*8 },
|
||||
(Vector2){ 0.0, 0.0 },
|
||||
0.0,
|
||||
WHITE
|
||||
);
|
||||
WHITE);
|
||||
|
||||
DrawText("lightmap", GetRenderWidth() - 66, 16 + MAP_SIZE*8, 10, GRAY);
|
||||
DrawText("10x10 pixels", GetRenderWidth() - 76, 30 + MAP_SIZE*8, 10, GRAY);
|
||||
|
||||
EndDrawing();
|
||||
//----------------------------------------------------------------------------------
|
||||
}
|
||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 224 KiB After Width: | Height: | Size: 205 KiB |
Loading…
Add table
Add a link
Reference in a new issue