//5 Adding ray falloff i amplitude proportionally with distance; // Attempting to figure out objects--boundary caluclations seem off for some rays. Verify. #include "raylib.h" #include #include #include using namespace std; Image obstacleData; #include "misc.h" #include "objectCtrl.h" #include "fermat.h" #include "rlgl.h" int main(void){ //Sim. parameters const int screenWidth = 1200; const int screenHeight = 800; const int buffer = 100; const Vector2 resolution = {screenWidth, screenHeight}; //Initialize App InitWindow(screenWidth, screenHeight, "Raycast Sim - Shader"); Image outputImage = GenImageColor(screenWidth, screenHeight, BLANK); Texture outputText = LoadTextureFromImage(outputImage); Color tempColor = WHITE; //rbc Compute Shader Setup char *rbcLogicCode = LoadFileText("./rbc.glsl"); unsigned int rbcLogicShader = rlCompileShader(rbcLogicCode, RL_COMPUTE_SHADER); unsigned int rbcLogicProgram = rlLoadComputeShaderProgram(rbcLogicShader); //rbc Render Shader Setup Shader rbcRenderShader = LoadShader(NULL, "rbc_render.glsl"); int resUniformLoc = GetShaderLocation(rbcRenderShader, "resolution"); //Load shader storage buffer object (SSBO); ID returned. unsigned int ssboA = rlLoadShaderBuffer(sizeof(float), NULL, RL_DYNAMIC_COPY); unsigned int ssboB = rlLoadShaderBuffer(sizeof(float), NULL, RL_DYNAMIC_COPY); Image whiteImage = GenImageColor(screenWidth, screenHeight, WHITE); Texture whiteTex = LoadTextureFromImage(whiteImage); UnloadImage(whiteImage); float temp, temp2; SetTargetFPS(60); while(!WindowShouldClose()){ //Run compute shader rlEnableShader(rbcLogicProgram); rlBindShaderBuffer(ssboA, 0); //rlComputeShaderDispatch(screenWidth, screenHeight, 1); rlComputeShaderDispatch(1, 1, 1); rlDisableShader(); //Run fragment shader rlBindShaderBuffer(ssboA, 0); rlBindShaderBuffer(ssboB, 1); SetShaderValue(rbcRenderShader, resUniformLoc, &resolution, SHADER_UNIFORM_VEC2); //Draw BeginDrawing(); ClearBackground(GRAY); BeginShaderMode(rbcRenderShader); DrawTexture(whiteTex, 0, 0, WHITE); EndShaderMode(); //Attempt to pull the constant from shader rlReadShaderBufferElements(ssboA, &temp, sizeof(float), 0); rlReadShaderBufferElements(ssboB, &temp2, sizeof(float), 0); printf("size: %ld, temp: %f, temp: %f\n", sizeof(float), temp, temp2); tempColor.r = (int) temp; DrawRectangleV({0, 0}, {10, 10}, tempColor); DrawFPS(10, 10); EndDrawing(); } //De-Initialization rlUnloadShaderBuffer(ssboA); rlUnloadShaderBuffer(ssboB); rlUnloadShaderProgram(rbcLogicProgram); UnloadTexture(outputText); UnloadShader(rbcRenderShader); CloseWindow(); return 0; }