2
0
mirror of https://github.com/raylib-cs/raylib-cs synced 2025-06-30 19:03:42 -04:00

Merge pull request #14 from mikaelssen/master

example update, missing lights still but progress is forwards
This commit is contained in:
2018-10-24 21:05:52 +01:00
committed by GitHub
13 changed files with 91376 additions and 261 deletions

1
.gitignore vendored
View File

@ -61,7 +61,6 @@ artifacts/
*_i.h *_i.h
*.ilk *.ilk
*.meta *.meta
*.obj
*.pch *.pch
*.pdb *.pdb
*.pgc *.pgc

View File

@ -4,270 +4,264 @@ using static Raylib.Model;
using static Raylib.CameraMode; using static Raylib.CameraMode;
using System; using System;
public enum LightType public enum LightType
{ {
LIGHT_DIRECTIONAL, LIGHT_DIRECTIONAL,
LIGHT_POINT LIGHT_POINT
}; };
//TODO: move the light system out into it's own class file, rlights.h original //TODO: move the light system out into it's own class file, rlights.h original
//also make it work properly //also make it work properly
public struct Light public struct Light
{ {
public bool enabled; public bool enabled;
public LightType type; public LightType type;
public Vector3 position; public Vector3 position;
public Vector3 target; public Vector3 target;
public Color color; public Color color;
public int enabledLoc; public int enabledLoc;
public int typeLoc; public int typeLoc;
public int posLoc; public int posLoc;
public int targetLoc; public int targetLoc;
public int colorLoc; public int colorLoc;
} }
public partial class models_material_pbr public partial class models_material_pbr
{ {
/*******************************************************************************************
*
* raylib [models] example - PBR material
*
* This example has been created using raylib 1.8 (www.raylib.com)
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
*
* Copyright (c) 2017 Ramon Santamaria (@raysan5)
*
********************************************************************************************/ /*******************************************************************************************
*
public const int CUBEMAP_SIZE = 512; * raylib [models] example - PBR material
public const int IRRADIANCE_SIZE = 32; *
public const int PREFILTERED_SIZE = 256; * This example has been created using raylib 1.8 (www.raylib.com)
public const int BRDF_SIZE = 512; * raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
*
// PBR material loading * Copyright (c) 2017 Ramon Santamaria (@raysan5)
//private static Material LoadMaterialPBR(Color albedo, float metalness, float roughness); *
********************************************************************************************/
public static int Main()
{ public const int CUBEMAP_SIZE = 512;
// Initialization public const int IRRADIANCE_SIZE = 32;
//-------------------------------------------------------------------------------------- public const int PREFILTERED_SIZE = 256;
int screenWidth = 800; public const int BRDF_SIZE = 512;
int screenHeight = 450; public const int MAX_LIGHTS = 4;
public static int lightsCount = 0;
float LIGHT_DISTANCE = 3.5f; public const float LIGHT_DISTANCE = 3.5f;
float LIGHT_HEIGHT = 1.0f; public const float LIGHT_HEIGHT = 1.0f;
SetConfigFlags(FLAG_MSAA_4X_HINT); // Enable Multi Sampling Anti Aliasing 4x (if available) // PBR material loading
InitWindow(screenWidth, screenHeight, "raylib [models] example - pbr material"); //private static Material LoadMaterialPBR(Color albedo, float metalness, float roughness);
// Define the camera to look into our 3d world public unsafe static int Main()
Camera3D camera = new Camera3D(new Vector3(4.0f, 4.0f, 4.0f), new Vector3(0.0f, 0.5f, 0.0f), new Vector3(0.0f, 1.0f, 0.0f), 45.0f, 0); {
// Initialization
// Load model and PBR material //--------------------------------------------------------------------------------------
Model model = LoadModel("resources/pbr/trooper.obj"); int screenWidth = 800;
MeshTangents(ref model.mesh); int screenHeight = 450;
model.material = LoadMaterialPBR(new Color(255, 255, 255, 255), 1.0f, 1.0f);
// Define lights attributes SetConfigFlags(FLAG_MSAA_4X_HINT); // Enable Multi Sampling Anti Aliasing 4x (if available)
// NOTE: Shader is passed to every light on creation to define shader bindings internally InitWindow(screenWidth, screenHeight, "raylib [models] example - pbr material");
Light[] lights = new Light[]
{ // Define the camera to look into our 3d world
CreateLight(LightType.LIGHT_POINT, new Vector3( LIGHT_DISTANCE, LIGHT_HEIGHT, 0.0f ), new Vector3( 0.0f, 0.0f, 0.0f ), new Color( 255, 0, 0, 255 ), model.material.shader), Camera3D camera = new Camera3D(new Vector3(4.0f, 4.0f, 4.0f), new Vector3(0.0f, 0.5f, 0.0f), new Vector3(0.0f, 1.0f, 0.0f), 45.0f, 0);
CreateLight(LightType.LIGHT_POINT, new Vector3( 0.0f, LIGHT_HEIGHT, LIGHT_DISTANCE ), new Vector3( 0.0f, 0.0f, 0.0f ), new Color( 0, 255, 0, 255 ), model.material.shader),
CreateLight(LightType.LIGHT_POINT, new Vector3( -LIGHT_DISTANCE, LIGHT_HEIGHT, 0.0f ), new Vector3( 0.0f, 0.0f, 0.0f ),new Color( 0, 0, 255, 255 ), model.material.shader), // Load model and PBR material
CreateLight(LightType.LIGHT_DIRECTIONAL, new Vector3(0.0f, LIGHT_HEIGHT * 2.0f, -LIGHT_DISTANCE ), new Vector3( 0.0f, 0.0f, 0.0f ), new Color(255, 0, 255, 255 ), model.material.shader) Model model = LoadModel("resources/pbr/trooper.obj");
}; MeshTangents(ref model.mesh);
model.material = LoadMaterialPBR(new Color(255, 255, 255, 255), 1.0f, 1.0f);
SetCameraMode(camera, (int)CameraMode.CAMERA_ORBITAL); // Set an orbital camera mode
// Define lights attributes
SetTargetFPS(60); // Set our game to run at 60 frames-per-second // NOTE: Shader is passed to every light on creation to define shader bindings internally
//-------------------------------------------------------------------------------------- Light[] lights = new Light[]
{
// Main game loop CreateLight(LightType.LIGHT_POINT, new Vector3( LIGHT_DISTANCE, LIGHT_HEIGHT, 0.0f ), new Vector3( 0.0f, 0.0f, 0.0f ), new Color( 255, 0, 0, 255 ), model.material.shader),
while (!WindowShouldClose()) // Detect window close button or ESC key CreateLight(LightType.LIGHT_POINT, new Vector3( 0.0f, LIGHT_HEIGHT, LIGHT_DISTANCE ), new Vector3( 0.0f, 0.0f, 0.0f ), new Color( 0, 255, 0, 255 ), model.material.shader),
{ CreateLight(LightType.LIGHT_POINT, new Vector3( -LIGHT_DISTANCE, LIGHT_HEIGHT, 0.0f ), new Vector3( 0.0f, 0.0f, 0.0f ),new Color( 0, 0, 255, 255 ), model.material.shader),
// Update CreateLight(LightType.LIGHT_DIRECTIONAL, new Vector3(0.0f, LIGHT_HEIGHT * 2.0f, -LIGHT_DISTANCE ), new Vector3( 0.0f, 0.0f, 0.0f ), new Color(255, 0, 255, 255 ), model.material.shader)
//---------------------------------------------------------------------------------- };
UpdateCamera(ref camera); // Update camera
SetCameraMode(camera, (int)CameraMode.CAMERA_ORBITAL); // Set an orbital camera mode
// Send to material PBR shader camera view position
float[] cameraPos = { camera.position.x, camera.position.y, camera.position.z }; SetTargetFPS(60); // Set our game to run at 60 frames-per-second
SetShaderValue(model.material.shader, 0, cameraPos, 3); //(int)model.material.shader.locs, cameraPos, 3); //--------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------
// Draw // Main game loop
//---------------------------------------------------------------------------------- while (!WindowShouldClose()) // Detect window close button or ESC key
BeginDrawing(); {
// Update
ClearBackground(RAYWHITE); //----------------------------------------------------------------------------------
UpdateCamera(ref camera); // Update camera
BeginMode3D(camera);
// Send to material PBR shader camera view position
DrawModel(model, Vector3Zero(), 1.0f, WHITE); float[] cameraPos = { camera.position.x, camera.position.y, camera.position.z };
SetShaderValue(model.material.shader, model.material.shader.locs[(int)ShaderLocationIndex.LOC_VECTOR_VIEW], cameraPos, 3);
DrawGrid(10, 1.0f);
//----------------------------------------------------------------------------------
EndMode3D(); // Draw
//----------------------------------------------------------------------------------
DrawFPS(10, 10); BeginDrawing();
EndDrawing(); ClearBackground(RAYWHITE);
//----------------------------------------------------------------------------------
} BeginMode3D(camera);
// De-Initialization DrawModel(model, Vector3Zero(), 1.0f, WHITE);
//--------------------------------------------------------------------------------------
UnloadModel(model); // Unload skybox model DrawGrid(10, 1.0f);
CloseWindow(); // Close window and OpenGL context EndMode3D();
//--------------------------------------------------------------------------------------
return 0; DrawFPS(10, 10);
}
EndDrawing();
public static Light CreateLight(LightType type, Vector3 pos, Vector3 targ, Color color, Shader shader) //----------------------------------------------------------------------------------
{ }
Light light = new Light() {
enabled = true, // De-Initialization
type = type, //--------------------------------------------------------------------------------------
position = pos, UnloadModel(model); // Unload skybox model
target = targ,
color = color, CloseWindow(); // Close window and OpenGL context
}; //--------------------------------------------------------------------------------------
return 0;
string enabledName = "lights[x].enabled\0"; }
string typeName = "lights[x].type\0";
string posName = "lights[x].position\0";
string targetName = "lights[x].target\0"; // Load PBR material (Supports: ALBEDO, NORMAL, METALNESS, ROUGHNESS, AO, EMMISIVE, HEIGHT maps)
string colorName = "lights[x].color\0"; // NOTE: PBR shader is loaded inside this function
unsafe public static Material LoadMaterialPBR(Color albedo, float metalness, float roughness)
light.enabledLoc = GetShaderLocation(shader, enabledName); {
light.typeLoc = GetShaderLocation(shader, typeName); Material mat = new Material(); // NOTE: All maps textures are set to { 0 )
light.posLoc = GetShaderLocation(shader, posName);
light.targetLoc = GetShaderLocation(shader, targetName); string PATH_PBR_VS = "resources/shaders/pbr.vs";
light.colorLoc = GetShaderLocation(shader, colorName); string PATH_PBR_FS = "resources/shaders/pbr.fs";
UpdateLightValues(shader, light); mat.shader = LoadShader(PATH_PBR_VS, PATH_PBR_FS);
return light; // Get required locations points for PBR material
} // NOTE: Those location names must be available and used in the shader code
public static void UpdateLightValues(Shader shader, Light light) mat.shader.locs[(int)ShaderLocationIndex.LOC_MAP_ALBEDO] = GetShaderLocation(mat.shader, "albedo.sampler");
{ mat.shader.locs[(int)ShaderLocationIndex.LOC_MAP_METALNESS] = GetShaderLocation(mat.shader, "metalness.sampler");
// Send to shader light enabled state and type mat.shader.locs[(int)ShaderLocationIndex.LOC_MAP_NORMAL] = GetShaderLocation(mat.shader, "normals.sampler");
SetShaderValuei(shader, light.enabledLoc, new int[] { Convert.ToInt32(light.enabled) }, 1); mat.shader.locs[(int)ShaderLocationIndex.LOC_MAP_ROUGHNESS] = GetShaderLocation(mat.shader, "roughness.sampler");
SetShaderValuei(shader, light.typeLoc, new int[] { Convert.ToInt32(light.type) }, 1); mat.shader.locs[(int)ShaderLocationIndex.LOC_MAP_OCCLUSION] = GetShaderLocation(mat.shader, "occlusion.sampler");
//mat.shader.locs[LOC_MAP_EMISSION] = GetShaderLocation(mat.shader, "emission.sampler");
// Send to shader light position values //mat.shader.locs[LOC_MAP_HEIGHT] = GetShaderLocation(mat.shader, "height.sampler");
float[] position = { light.position.x, light.position.y, light.position.z }; mat.shader.locs[(int)ShaderLocationIndex.LOC_MAP_IRRADIANCE] = GetShaderLocation(mat.shader, "irradianceMap");
SetShaderValue(shader, light.posLoc, position, 3); mat.shader.locs[(int)ShaderLocationIndex.LOC_MAP_PREFILTER] = GetShaderLocation(mat.shader, "prefilterMap");
mat.shader.locs[(int)ShaderLocationIndex.LOC_MAP_BRDF] = GetShaderLocation(mat.shader, "brdfLUT");
// Send to shader light target position values
float[] target = { light.target.x, light.target.y, light.target.z }; // Set view matrix location
SetShaderValue(shader, light.targetLoc, target, 3); mat.shader.locs[(int)ShaderLocationIndex.LOC_MATRIX_MODEL] = GetShaderLocation(mat.shader, "matModel");
mat.shader.locs[(int)ShaderLocationIndex.LOC_MATRIX_VIEW] = GetShaderLocation(mat.shader, "view");
// Send to shader light color values mat.shader.locs[(int)ShaderLocationIndex.LOC_VECTOR_VIEW] = GetShaderLocation(mat.shader, "viewPos");
float[] diff = { light.color.r / 255, light.color.g / 255, light.color.b / 255, light.color.a / 255 };
SetShaderValue(shader, light.colorLoc, diff, 4); // Set PBR standard maps
} mat.maps[(int)TexmapIndex.MAP_ALBEDO].texture = LoadTexture("resources/pbr/trooper_albedo.png");
mat.maps[(int)TexmapIndex.MAP_NORMAL].texture = LoadTexture("resources/pbr/trooper_normals.png");
// Load PBR material (Supports: ALBEDO, NORMAL, METALNESS, ROUGHNESS, AO, EMMISIVE, HEIGHT maps) mat.maps[(int)TexmapIndex.MAP_METALNESS].texture = LoadTexture("resources/pbr/trooper_metalness.png");
// NOTE: PBR shader is loaded inside this function mat.maps[(int)TexmapIndex.MAP_ROUGHNESS].texture = LoadTexture("resources/pbr/trooper_roughness.png");
unsafe public static Material LoadMaterialPBR(Color albedo, float metalness, float roughness) mat.maps[(int)TexmapIndex.MAP_OCCLUSION].texture = LoadTexture("resources/pbr/trooper_ao.png");
{
Material mat = new Material(); // NOTE: All maps textures are set to { 0 ) // Set environment maps
const string PATH_CUBEMAP_VS = "resources/shaders/cubemap.vs"; // Path to equirectangular to cubemap vertex shader
string PATH_PBR_VS = "resources/shaders/pbr.vs"; const string PATH_CUBEMAP_FS = "resources/shaders/cubemap.fs"; // Path to equirectangular to cubemap fragment shader
string PATH_PBR_FS = "resources/shaders/pbr.fs"; const string PATH_SKYBOX_VS = "resources/shaders/skybox.vs"; // Path to skybox vertex shader
const string PATH_IRRADIANCE_FS = "resources/shaders/irradiance.fs"; // Path to irradiance (GI) calculation fragment shader
mat.shader = LoadShader(PATH_PBR_VS, PATH_PBR_FS); const string PATH_PREFILTER_FS = "resources/shaders/prefilter.fs"; // Path to reflection prefilter calculation fragment shader
const string PATH_BRDF_VS = "resources/shaders/brdf.vs"; // Path to bidirectional reflectance distribution function vertex shader
// Get required locations points for PBR material const string PATH_BRDF_FS = "resources/shaders/brdf.fs"; // Path to bidirectional reflectance distribution function fragment shader
// NOTE: Those location names must be available and used in the shader code
Shader shdrCubemap = LoadShader(PATH_CUBEMAP_VS, PATH_CUBEMAP_FS);
mat.shader.locs[(int)ShaderLocationIndex.LOC_MAP_ALBEDO] = GetShaderLocation(mat.shader, "albedo.sampler"); Shader shdrIrradiance = LoadShader(PATH_SKYBOX_VS, PATH_IRRADIANCE_FS);
mat.shader.locs[(int)ShaderLocationIndex.LOC_MAP_METALNESS] = GetShaderLocation(mat.shader, "metalness.sampler"); Shader shdrPrefilter = LoadShader(PATH_SKYBOX_VS, PATH_PREFILTER_FS);
mat.shader.locs[(int)ShaderLocationIndex.LOC_MAP_NORMAL] = GetShaderLocation(mat.shader, "normals.sampler"); Shader shdrBRDF = LoadShader(PATH_BRDF_VS, PATH_BRDF_FS);
mat.shader.locs[(int)ShaderLocationIndex.LOC_MAP_ROUGHNESS] = GetShaderLocation(mat.shader, "roughness.sampler");
mat.shader.locs[(int)ShaderLocationIndex.LOC_MAP_OCCLUSION] = GetShaderLocation(mat.shader, "occlusion.sampler"); // Setup required shader locations
//mat.shader.locs[LOC_MAP_EMISSION] = GetShaderLocation(mat.shader, "emission.sampler"); SetShaderValuei(shdrCubemap, GetShaderLocation(shdrCubemap, "equirectangularMap"), new int[] { 0 }, 1);
//mat.shader.locs[LOC_MAP_HEIGHT] = GetShaderLocation(mat.shader, "height.sampler"); SetShaderValuei(shdrIrradiance, GetShaderLocation(shdrIrradiance, "environmentMap"), new int[] { 0 }, 1);
mat.shader.locs[(int)ShaderLocationIndex.LOC_MAP_IRRADIANCE] = GetShaderLocation(mat.shader, "irradianceMap"); SetShaderValuei(shdrPrefilter, GetShaderLocation(shdrPrefilter, "environmentMap"), new int[] { 0 }, 1);
mat.shader.locs[(int)ShaderLocationIndex.LOC_MAP_PREFILTER] = GetShaderLocation(mat.shader, "prefilterMap");
mat.shader.locs[(int)ShaderLocationIndex.LOC_MAP_BRDF] = GetShaderLocation(mat.shader, "brdfLUT"); Texture2D texHDR = LoadTexture("resources/dresden_square.hdr");
Texture2D cubemap = GenTextureCubemap(shdrCubemap, texHDR, CUBEMAP_SIZE);
// Set view matrix location mat.maps[(int)TexmapIndex.MAP_IRRADIANCE].texture = GenTextureIrradiance(shdrIrradiance, cubemap, IRRADIANCE_SIZE);
mat.shader.locs[(int)ShaderLocationIndex.LOC_MATRIX_MODEL] = GetShaderLocation(mat.shader, "matModel"); mat.maps[(int)TexmapIndex.MAP_PREFILTER].texture = GenTexturePrefilter(shdrPrefilter, cubemap, PREFILTERED_SIZE);
mat.shader.locs[(int)ShaderLocationIndex.LOC_MATRIX_VIEW] = GetShaderLocation(mat.shader, "view"); mat.maps[(int)TexmapIndex.MAP_BRDF].texture = GenTextureBRDF(shdrBRDF, cubemap, BRDF_SIZE);
mat.shader.locs[(int)ShaderLocationIndex.LOC_VECTOR_VIEW] = GetShaderLocation(mat.shader, "viewPos"); UnloadTexture(cubemap);
UnloadTexture(texHDR);
// Set PBR standard maps
mat.maps[(int)TexmapIndex.MAP_ALBEDO].texture = LoadTexture("resources/pbr/trooper_albedo.png"); // Unload already used shaders (to create specific textures)
mat.maps[(int)TexmapIndex.MAP_NORMAL].texture = LoadTexture("resources/pbr/trooper_normals.png"); UnloadShader(shdrCubemap);
mat.maps[(int)TexmapIndex.MAP_METALNESS].texture = LoadTexture("resources/pbr/trooper_metalness.png"); UnloadShader(shdrIrradiance);
mat.maps[(int)TexmapIndex.MAP_ROUGHNESS].texture = LoadTexture("resources/pbr/trooper_roughness.png"); UnloadShader(shdrPrefilter);
mat.maps[(int)TexmapIndex.MAP_OCCLUSION].texture = LoadTexture("resources/pbr/trooper_ao.png"); UnloadShader(shdrBRDF);
// Set environment maps // Set textures filtering for better quality
const string PATH_CUBEMAP_VS = "resources/shaders/cubemap.vs"; SetTextureFilter(mat.maps[(int)TexmapIndex.MAP_ALBEDO].texture, (int)TextureFilterMode.FILTER_BILINEAR);
const string PATH_CUBEMAP_FS = "resources/shaders/cubemap.fs"; SetTextureFilter(mat.maps[(int)TexmapIndex.MAP_NORMAL].texture, (int)TextureFilterMode.FILTER_BILINEAR);
const string PATH_SKYBOX_VS = "resources/shaders/skybox.vs"; SetTextureFilter(mat.maps[(int)TexmapIndex.MAP_METALNESS].texture, (int)TextureFilterMode.FILTER_BILINEAR);
const string PATH_IRRADIANCE_FS = "resources/shaders/irradiance.fs"; SetTextureFilter(mat.maps[(int)TexmapIndex.MAP_ROUGHNESS].texture, (int)TextureFilterMode.FILTER_BILINEAR);
const string PATH_PREFILTER_FS = "resources/shaders/prefilter.fs"; SetTextureFilter(mat.maps[(int)TexmapIndex.MAP_OCCLUSION].texture, (int)TextureFilterMode.FILTER_BILINEAR);
const string PATH_BRDF_VS = "resources/shaders/brdf.vs";
const string PATH_BRDF_FS = "resources/shaders/brdf.fs"; // Enable sample usage in shader for assigned textures
SetShaderValuei(mat.shader, GetShaderLocation(mat.shader, "albedo.useSampler"), new int[] { 1 }, 1);
Shader shdrCubemap = LoadShader(PATH_CUBEMAP_VS, PATH_CUBEMAP_FS); SetShaderValuei(mat.shader, GetShaderLocation(mat.shader, "normals.useSampler"), new int[] { 1 }, 1);
Shader shdrIrradiance = LoadShader(PATH_SKYBOX_VS, PATH_IRRADIANCE_FS); SetShaderValuei(mat.shader, GetShaderLocation(mat.shader, "metalness.useSampler"), new int[] { 1 }, 1);
Shader shdrPrefilter = LoadShader(PATH_SKYBOX_VS, PATH_PREFILTER_FS); SetShaderValuei(mat.shader, GetShaderLocation(mat.shader, "roughness.useSampler"), new int[] { 1 }, 1);
Shader shdrBRDF = LoadShader(PATH_BRDF_VS, PATH_BRDF_FS); SetShaderValuei(mat.shader, GetShaderLocation(mat.shader, "occlusion.useSampler"), new int[] { 1 }, 1);
// Setup required shader locations int renderModeLoc = GetShaderLocation(mat.shader, "renderMode");
SetShaderValuei(shdrCubemap, GetShaderLocation(shdrCubemap, "equirectangularMap"), new int[] { 0 }, 1); SetShaderValuei(mat.shader, renderModeLoc, new int[] { 0 }, 1);
SetShaderValuei(shdrIrradiance, GetShaderLocation(shdrIrradiance, "environmentMap"), new int[] { 0 }, 1);
SetShaderValuei(shdrPrefilter, GetShaderLocation(shdrPrefilter, "environmentMap"), new int[] { 0 }, 1); // Set up material properties color
mat.maps[(int)TexmapIndex.MAP_ALBEDO].color = albedo;
Texture2D texHDR = LoadTexture("resources/dresden_square.hdr"); mat.maps[(int)TexmapIndex.MAP_NORMAL].color = new Color(128, 128, 255, 255);
Texture2D cubemap = GenTextureCubemap(shdrCubemap, texHDR, CUBEMAP_SIZE); mat.maps[(int)TexmapIndex.MAP_METALNESS].value = metalness;
mat.maps[(int)TexmapIndex.MAP_IRRADIANCE].texture = GenTextureIrradiance(shdrIrradiance, cubemap, IRRADIANCE_SIZE); mat.maps[(int)TexmapIndex.MAP_ROUGHNESS].value = roughness;
mat.maps[(int)TexmapIndex.MAP_PREFILTER].texture = GenTexturePrefilter(shdrPrefilter, cubemap, PREFILTERED_SIZE); mat.maps[(int)TexmapIndex.MAP_OCCLUSION].value = 1.0f;
mat.maps[(int)TexmapIndex.MAP_BRDF].texture = GenTextureBRDF(shdrBRDF, cubemap, BRDF_SIZE); mat.maps[(int)TexmapIndex.MAP_EMISSION].value = 0.5f;
UnloadTexture(cubemap); mat.maps[(int)TexmapIndex.MAP_HEIGHT].value = 0.5f;
UnloadTexture(texHDR);
return mat;
// Unload already used shaders (to create specific textures) }
UnloadShader(shdrCubemap);
UnloadShader(shdrIrradiance); public static Light CreateLight(LightType type, Vector3 pos, Vector3 targ, Color color, Shader shader)
UnloadShader(shdrPrefilter); {
UnloadShader(shdrBRDF);
Light light = new Light();
// Set textures filtering for better quality
SetTextureFilter(mat.maps[(int)TexmapIndex.MAP_ALBEDO].texture, (int)TextureFilterMode.FILTER_BILINEAR); if (lightsCount < MAX_LIGHTS)
SetTextureFilter(mat.maps[(int)TexmapIndex.MAP_NORMAL].texture, (int)TextureFilterMode.FILTER_BILINEAR); {
SetTextureFilter(mat.maps[(int)TexmapIndex.MAP_METALNESS].texture, (int)TextureFilterMode.FILTER_BILINEAR); light.enabled = true;
SetTextureFilter(mat.maps[(int)TexmapIndex.MAP_ROUGHNESS].texture, (int)TextureFilterMode.FILTER_BILINEAR); light.type = type;
SetTextureFilter(mat.maps[(int)TexmapIndex.MAP_OCCLUSION].texture, (int)TextureFilterMode.FILTER_BILINEAR); light.position = pos;
light.target = targ;
// Enable sample usage in shader for assigned textures light.color = color;
SetShaderValuei(mat.shader, GetShaderLocation(mat.shader, "albedo.useSampler"), new int[] { 1 }, 1);
SetShaderValuei(mat.shader, GetShaderLocation(mat.shader, "normals.useSampler"), new int[] { 1 }, 1); string enabledName = $"lights[{lightsCount}].enabled\0";
SetShaderValuei(mat.shader, GetShaderLocation(mat.shader, "metalness.useSampler"), new int[] { 1 }, 1); string typeName = $"lights[{lightsCount}].type\0";
SetShaderValuei(mat.shader, GetShaderLocation(mat.shader, "roughness.useSampler"), new int[] { 1 }, 1); string posName = $"lights[{lightsCount}].position\0";
SetShaderValuei(mat.shader, GetShaderLocation(mat.shader, "occlusion.useSampler"), new int[] { 1 }, 1); string targetName = $"lights[{lightsCount}].target\0";
string colorName = $"lights[{lightsCount}].color\0";
int renderModeLoc = GetShaderLocation(mat.shader, "renderMode");
SetShaderValuei(mat.shader, renderModeLoc, new int[] { 0 }, 1); light.enabledLoc = GetShaderLocation(shader, enabledName);
light.typeLoc = GetShaderLocation(shader, typeName);
// Set up material properties color light.posLoc = GetShaderLocation(shader, posName);
mat.maps[(int)TexmapIndex.MAP_ALBEDO].color = albedo; light.targetLoc = GetShaderLocation(shader, targetName);
mat.maps[(int)TexmapIndex.MAP_NORMAL].color = new Color( 128, 128, 255, 255 ); light.colorLoc = GetShaderLocation(shader, colorName);
mat.maps[(int)TexmapIndex.MAP_METALNESS].value = metalness;
mat.maps[(int)TexmapIndex.MAP_ROUGHNESS].value = roughness; UpdateLightValues(shader, light);
mat.maps[(int)TexmapIndex.MAP_OCCLUSION].value = 1.0f; lightsCount++;
mat.maps[(int)TexmapIndex.MAP_EMISSION].value = 0.5f;
mat.maps[(int)TexmapIndex.MAP_HEIGHT].value = 0.5f;
return mat;
}
}
} }
return light; return light;

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff