adapt convention
This commit is contained in:
parent
4c1f38a89e
commit
006fd85728
|
|
@ -563,7 +563,7 @@ SHADERS = \
|
|||
shaders/shaders_multi_sample2d \
|
||||
shaders/shaders_write_depth \
|
||||
shaders/shaders_hybrid_render \
|
||||
shaders/shaders_deferred_shading
|
||||
shaders/shaders_deferred_render
|
||||
|
||||
AUDIO = \
|
||||
audio/audio_module_playing \
|
||||
|
|
|
|||
|
|
@ -469,7 +469,7 @@ SHADERS = \
|
|||
shaders/shaders_multi_sample2d \
|
||||
shaders/shaders_write_depth \
|
||||
shaders/shaders_hybrid_render \
|
||||
shaders/shaders_deferred_shading
|
||||
shaders/shaders_deferred_render
|
||||
|
||||
AUDIO = \
|
||||
audio/audio_module_playing \
|
||||
|
|
|
|||
|
|
@ -176,7 +176,7 @@ Examples using raylib shaders functionality, including shaders loading, paramete
|
|||
| 114 | [shaders_mesh_instancing](shaders/shaders_mesh_instancing.c) | <img src="shaders/shaders_mesh_instancing.png" alt="shaders_mesh_instancing" width="80"> | ⭐️⭐️⭐️⭐️ | 3.7 | **4.2** | [seanpringle](https://github.com/seanpringle) |
|
||||
| 115 | [shaders_multi_sample2d](shaders/shaders_multi_sample2d.c) | <img src="shaders/shaders_multi_sample2d.png" alt="shaders_multi_sample2d" width="80"> | ⭐️⭐️☆☆ | 3.5 | 3.5 | [Ray](https://github.com/raysan5) |
|
||||
| 116 | [shaders_spotlight](shaders/shaders_spotlight.c) | <img src="shaders/shaders_spotlight.png" alt="shaders_spotlight" width="80"> | ⭐️⭐️☆☆ | 2.5 | 3.7 | [Chris Camacho](https://github.com/codifies) |
|
||||
| 117 | [shaders_deferred_shading](shaders/shaders_deferred_shading.c) | <img src="shaders/shaders_deferred_shading.png" alt="shaders_deferred_shading" width="80"> | ⭐️⭐️⭐️⭐️ | 4.5 | 4.5 | [Justin Andreas Lacoste](https://github.com/27justin) |
|
||||
| 117 | [shaders_deferred_render](shaders/shaders_deferred_render.c) | <img src="shaders/shaders_deferred_render.png" alt="shaders_deferred_render" width="80"> | ⭐️⭐️⭐️⭐️ | 4.5 | 4.5 | [Justin Andreas Lacoste](https://github.com/27justin) |
|
||||
|
||||
### category: audio
|
||||
|
||||
|
|
|
|||
|
|
@ -9,11 +9,11 @@ uniform sampler2D gNormal;
|
|||
uniform sampler2D gAlbedoSpec;
|
||||
|
||||
struct Light {
|
||||
int enabled;
|
||||
int type; // Unused in this demo.
|
||||
vec3 position;
|
||||
vec3 target; // Unused in this demo.
|
||||
vec4 color;
|
||||
int enabled;
|
||||
int type; // Unused in this demo.
|
||||
vec3 position;
|
||||
vec3 target; // Unused in this demo.
|
||||
vec4 color;
|
||||
};
|
||||
|
||||
const int NR_LIGHTS = 4;
|
||||
|
|
@ -24,31 +24,32 @@ const float QUADRATIC = 0.032;
|
|||
const float LINEAR = 0.09;
|
||||
|
||||
void main() {
|
||||
vec3 fragPosition = texture(gPosition, texCoord).rgb;
|
||||
vec3 normal = texture(gNormal, texCoord).rgb;
|
||||
vec3 albedo = texture(gAlbedoSpec, texCoord).rgb;
|
||||
float specular = texture(gAlbedoSpec, texCoord).a;
|
||||
vec3 fragPosition = texture(gPosition, texCoord).rgb;
|
||||
vec3 normal = texture(gNormal, texCoord).rgb;
|
||||
vec3 albedo = texture(gAlbedoSpec, texCoord).rgb;
|
||||
float specular = texture(gAlbedoSpec, texCoord).a;
|
||||
|
||||
vec3 ambient = albedo * vec3(0.1f);
|
||||
vec3 viewDirection = normalize(viewPosition - fragPosition);
|
||||
vec3 ambient = albedo * vec3(0.1f);
|
||||
vec3 viewDirection = normalize(viewPosition - fragPosition);
|
||||
|
||||
for(int i = 0; i < NR_LIGHTS; ++i) {
|
||||
if(lights[i].enabled == 0) continue;
|
||||
vec3 lightDirection = lights[i].position - fragPosition;
|
||||
vec3 diffuse = max(dot(normal, lightDirection), 0.0) * albedo * lights[i].color.xyz;
|
||||
for(int i = 0; i < NR_LIGHTS; ++i)
|
||||
{
|
||||
if(lights[i].enabled == 0) continue;
|
||||
vec3 lightDirection = lights[i].position - fragPosition;
|
||||
vec3 diffuse = max(dot(normal, lightDirection), 0.0) * albedo * lights[i].color.xyz;
|
||||
|
||||
vec3 halfwayDirection = normalize(lightDirection + viewDirection);
|
||||
float spec = pow(max(dot(normal, halfwayDirection), 0.0), 32.0);
|
||||
vec3 specular = specular * spec * lights[i].color.xyz;
|
||||
vec3 halfwayDirection = normalize(lightDirection + viewDirection);
|
||||
float spec = pow(max(dot(normal, halfwayDirection), 0.0), 32.0);
|
||||
vec3 specular = specular * spec * lights[i].color.xyz;
|
||||
|
||||
// Attenuation
|
||||
float distance = length(lights[i].position - fragPosition);
|
||||
float attenuation = 1.0 / (1.0 + LINEAR * distance + QUADRATIC * distance * distance);
|
||||
diffuse *= attenuation;
|
||||
specular *= attenuation;
|
||||
ambient += diffuse + specular;
|
||||
}
|
||||
// Attenuation
|
||||
float distance = length(lights[i].position - fragPosition);
|
||||
float attenuation = 1.0 / (1.0 + LINEAR * distance + QUADRATIC * distance * distance);
|
||||
diffuse *= attenuation;
|
||||
specular *= attenuation;
|
||||
ambient += diffuse + specular;
|
||||
}
|
||||
|
||||
finalColor = vec4(ambient, 1.0);
|
||||
finalColor = vec4(ambient, 1.0);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -6,6 +6,6 @@ layout (location = 1) in vec2 vertexTexCoord;
|
|||
out vec2 texCoord;
|
||||
|
||||
void main() {
|
||||
gl_Position = vec4(vertexPosition, 1.0);
|
||||
texCoord = vertexTexCoord;
|
||||
gl_Position = vec4(vertexPosition, 1.0);
|
||||
texCoord = vertexTexCoord;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -48,8 +48,7 @@ int main(void) {
|
|||
const int screenWidth = 800;
|
||||
const int screenHeight = 450;
|
||||
|
||||
InitWindow(screenWidth, screenHeight, "raylib [shaders] example - deferred shading");
|
||||
|
||||
InitWindow(screenWidth, screenHeight, "raylib [shaders] example - deferred render");
|
||||
|
||||
Camera camera = { 0 };
|
||||
camera.position = (Vector3){ 5.0f, 4.0f, 5.0f }; // Camera position
|
||||
|
|
@ -70,12 +69,12 @@ int main(void) {
|
|||
"resources/shaders/glsl330/deferred_shading.fs");
|
||||
deferredShader.locs[SHADER_LOC_VECTOR_VIEW] = GetShaderLocation(deferredShader, "viewPosition");
|
||||
|
||||
|
||||
// Initialize the G-buffer
|
||||
GBuffer gBuffer = { 0 };
|
||||
gBuffer.framebuffer = rlLoadFramebuffer(screenWidth, screenHeight);
|
||||
|
||||
if(!gBuffer.framebuffer) {
|
||||
if(!gBuffer.framebuffer)
|
||||
{
|
||||
TraceLog(LOG_WARNING, "Failed to create framebuffer");
|
||||
exit(1);
|
||||
}
|
||||
|
|
@ -93,13 +92,11 @@ int main(void) {
|
|||
// Activate the draw buffers for our framebuffer
|
||||
rlActiveDrawBuffers(3);
|
||||
|
||||
|
||||
// Now we attach our textures to the framebuffer.
|
||||
rlFramebufferAttach(gBuffer.framebuffer, gBuffer.positionTexture, RL_ATTACHMENT_COLOR_CHANNEL0, RL_ATTACHMENT_TEXTURE2D, 0);
|
||||
rlFramebufferAttach(gBuffer.framebuffer, gBuffer.normalTexture, RL_ATTACHMENT_COLOR_CHANNEL1, RL_ATTACHMENT_TEXTURE2D, 0);
|
||||
rlFramebufferAttach(gBuffer.framebuffer, gBuffer.albedoSpecTexture, RL_ATTACHMENT_COLOR_CHANNEL2, RL_ATTACHMENT_TEXTURE2D, 0);
|
||||
|
||||
|
||||
// Finally we attach the depth buffer.
|
||||
gBuffer.depthRenderbuffer = rlLoadTextureDepth(screenWidth, screenHeight, true);
|
||||
rlFramebufferAttach(gBuffer.framebuffer, gBuffer.depthRenderbuffer, RL_ATTACHMENT_DEPTH, RL_ATTACHMENT_RENDERBUFFER, 0);
|
||||
|
|
@ -107,7 +104,8 @@ int main(void) {
|
|||
// Make sure our framebuffer is complete.
|
||||
// NOTE: rlFramebufferComplete() automatically unbinds the framebuffer, so we don't have
|
||||
// to rlDisableFramebuffer() here.
|
||||
if(rlFramebufferComplete(gBuffer.framebuffer) != true) {
|
||||
if(rlFramebufferComplete(gBuffer.framebuffer) != true)
|
||||
{
|
||||
TraceLog(LOG_WARNING, "Framebuffer is not complete");
|
||||
exit(1);
|
||||
}
|
||||
|
|
@ -139,7 +137,8 @@ int main(void) {
|
|||
const float CUBE_SCALE = 0.25;
|
||||
Vector3 cubePositions[MAX_CUBES];
|
||||
float cubeRotations[MAX_CUBES];
|
||||
for(int i = 0; i < MAX_CUBES; i++) {
|
||||
for(int i = 0; i < MAX_CUBES; i++)
|
||||
{
|
||||
cubePositions[i] = (Vector3) {
|
||||
.x = (float)(rand() % 10) - 5,
|
||||
.y = (float)(rand() % 5),
|
||||
|
|
@ -161,7 +160,8 @@ int main(void) {
|
|||
//---------------------------------------------------------------------------------------
|
||||
|
||||
// Main game loop
|
||||
while (!WindowShouldClose()) {
|
||||
while (!WindowShouldClose())
|
||||
{
|
||||
// Update
|
||||
//----------------------------------------------------------------------------------
|
||||
UpdateCamera(&camera, CAMERA_ORBITAL);
|
||||
|
|
@ -205,7 +205,8 @@ int main(void) {
|
|||
DrawModel(model, Vector3Zero(), 1.0f, WHITE);
|
||||
DrawModel(cube, (Vector3) { 0.0, 1.0f, 0.0 }, 1.0f, WHITE);
|
||||
|
||||
for(int i = 0; i < MAX_CUBES; i++) {
|
||||
for(int i = 0; i < MAX_CUBES; i++)
|
||||
{
|
||||
Vector3 position = cubePositions[i];
|
||||
|
||||
DrawModelEx(cube, position, (Vector3) { 1, 1, 1 }, cubeRotations[i], (Vector3) { CUBE_SCALE, CUBE_SCALE, CUBE_SCALE }, WHITE);
|
||||
|
|
@ -219,7 +220,8 @@ int main(void) {
|
|||
rlDisableFramebuffer();
|
||||
rlClearScreenBuffers(); // Clear color & depth buffer
|
||||
|
||||
switch(activeTexture) {
|
||||
switch(activeTexture)
|
||||
{
|
||||
case DEFERRED_SHADING:
|
||||
BeginMode3D(camera);
|
||||
rlDisableColorBlend();
|
||||
|
|
@ -252,7 +254,8 @@ int main(void) {
|
|||
// forward rendering
|
||||
BeginMode3D(camera);
|
||||
rlEnableShader(rlGetShaderIdDefault());
|
||||
for(int i = 0; i < MAX_LIGHTS; i++) {
|
||||
for(int i = 0; i < MAX_LIGHTS; i++)
|
||||
{
|
||||
if(lights[i].enabled) DrawSphereEx(lights[i].position, 0.2f, 8, 8, lights[i].color);
|
||||
else DrawSphereWires(lights[i].position, 0.2f, 8, 8, ColorAlpha(lights[i].color, 0.3f));
|
||||
}
|
||||
|
Before Width: | Height: | Size: 89 KiB After Width: | Height: | Size: 89 KiB |
Loading…
Reference in New Issue
Block a user