Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

proposal: allow nested function directly in main as the first definition #22

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

choltreppe
Copy link

@choltreppe choltreppe commented Jan 7, 2025

The idea is that this way you are able to use uniforms/in/out in functions other than main.
So something like:

proc testFrag*(
  circleCenter: Uniform[Vec2],
  circleRadius: float32,
  fragPosition: Vec3,
  finalColor: var Vec4,
) =

  proc distanceCircle(pos: Vec2): float32 =
    return length(circleCenter - pos) - circleRadius

  finalColor = vec4(0.0)
  if distanceCircle(fragPosition.xy) < 0:
    finalColor = vec4(1.0)

becomes:

#version 410
precision highp float;
// from testFrag

uniform vec2 circleCenter;
in float circleRadius;
in vec3 fragPosition;
out vec4 finalColor;

float distanceCircle(
  vec2 pos
) {
  float result;
  result = length(circleCenter - pos) - circleRadius;
  return result;
}

void main() {
  finalColor = vec4(0.0);
  if (distanceCircle(fragPosition.xy) < 0.0) {
    finalColor = vec4(1.0);
  }
}

ps: sorry for the fast new commit and PR rename, so there is also the array-uniforms commit

@choltreppe choltreppe changed the title support arrays in uniforms proposal: allow nested function directly in main as the first definition Jan 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant