Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
Gamenot committed Oct 31, 2023
1 parent 06b45c2 commit 49a3690
Show file tree
Hide file tree
Showing 10 changed files with 322 additions and 252 deletions.
28 changes: 0 additions & 28 deletions smarts/core/glsl/compound.frag

This file was deleted.

35 changes: 30 additions & 5 deletions smarts/core/glsl/occlusion.frag
Original file line number Diff line number Diff line change
@@ -1,9 +1,28 @@
#version 330 core
// Visibility check

// -----------------------------------------------
#define STEP_LENGTH 0.2
#define CENTER_COORD iResolution.xy * 0.5
//#define SHADERTOY

#ifdef SHADERTOY
float get_texture_max( vec2 uv ) {
return texture(iChannel0, uv).x;
}
#else
// Output color
out vec4 p3d_Color;

uniform vec2 iResolution;
uniform sampler2D iChannel0;
uniform sampler2D iChannel1;
uniform sampler2D iChannel2;

float get_texture_max( vec2 uv ) {
return texture(iChannel0, uv).x + texture(iChannel1, uv).x;
}
#endif

void mainImage( out vec4 fragColor, in vec2 fragCoord )
{
Expand All @@ -14,20 +33,20 @@ void mainImage( out vec4 fragColor, in vec2 fragCoord )
vec2 offset_norm = normalize(offset);
float offset_dist = length(offset);

if (texture(iChannel1, vec2(0.5)).x <= 0.0){
if (texture(iChannel2, vec2(0.5)).x <= 0.0){
fragColor = vec4(0.0, 0.0, 0.0, 1.0);
return;
}

float center_height = texture(iChannel0, vec2(0.5)).x * TOPOLOGY_SCALING_FACTOR + DEVICE_HEIGHT;
float target_height = texture(iChannel0, p).x * TOPOLOGY_SCALING_FACTOR;
float center_height = get_texture_max(vec2(0.5)) * TOPOLOGY_SCALING_FACTOR + DEVICE_HEIGHT;
float target_height = get_texture_max(p) * TOPOLOGY_SCALING_FACTOR;

float target_slope = (target_height - center_height) / offset_dist;

float total = STEP_LENGTH;
while (total < offset_dist - 0.01 ) {
vec2 intermediary_coord = (CENTER_COORD + offset_norm * total) * rec_res;
float intermediary_height = texture(iChannel0, intermediary_coord).x * TOPOLOGY_SCALING_FACTOR;
float intermediary_height = get_texture_max(intermediary_coord) * TOPOLOGY_SCALING_FACTOR;

if ( target_slope < ((intermediary_height - center_height) * TOPOLOGY_SCALING_FACTOR ) / total){
fragColor = vec4(0.0, 0.0, 0.0, 1.0);
Expand All @@ -40,4 +59,10 @@ void mainImage( out vec4 fragColor, in vec2 fragCoord )


fragColor = vec4(1.0,1.0,1.0,1.0);
}
}

#ifndef SHADERTOY
void main(){
mainImage( p3d_Color, gl_FragCoord.xy );
}
#endif
18 changes: 0 additions & 18 deletions smarts/core/glsl/red.comp

This file was deleted.

67 changes: 0 additions & 67 deletions smarts/core/glsl/simplex.comp

This file was deleted.

18 changes: 8 additions & 10 deletions smarts/core/glsl/simplex.frag
Original file line number Diff line number Diff line change
@@ -1,13 +1,4 @@
#version 330 core
#define DEVICE_HEIGHT 0.8
#define TOPOLOGY_SCALING_FACTOR 1.0
#define CENTER vec2(0.5)
//#define SHADERTOY
//#define SPOT_CHECK

#define DENSITY_U 1.6 * 0.1
#define DENSITY_V 1.2 * 0.1

// The MIT License
// Copyright © 2013 Inigo Quilez
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Expand All @@ -25,6 +16,13 @@


// -----------------------------------------------

//#define SHADERTOY

#define DENSITY_U 1.6 * 0.1
#define DENSITY_V 1.2 * 0.1


#ifndef SHADERTOY
vec2 hash( vec2 p ) // replace this by something better
{
Expand Down Expand Up @@ -66,8 +64,8 @@ out vec4 p3d_Color;
uniform vec2 iResolution;
uniform float iHeading;
uniform vec2 iTranslation;

#endif

void mainImage( out vec4 fragColor, in vec2 fragCoord )
{
vec2 uv = ( gl_FragCoord.xy - .5 * iResolution.xy ) / iResolution.y;
Expand Down
35 changes: 28 additions & 7 deletions smarts/core/glsl/surface_facing.frag
Original file line number Diff line number Diff line change
@@ -1,7 +1,25 @@
#version 330 core
// Surface direction check

// -----------------------------------------------

#ifdef SHADERTOY
float get_texture_max( vec2 uv ) {
return texture(iChannel0, uv).x;
}
#else
// Output color
out vec4 p3d_Color;

uniform vec2 iResolution;
uniform sampler2D iChannel0;
uniform sampler2D iChannel1;

float get_texture_max( vec2 uv ) {
return texture(iChannel0, uv).x + texture(iChannel1, uv).x;
}
#endif

float cross_magnitude(vec2 lp1, vec2 lp2, vec2 p1){
vec2 v1 = lp2 - lp1;
vec2 v2 = lp2 - p1;
Expand All @@ -21,23 +39,26 @@ void mainImage( out vec4 fragColor, in vec2 fragCoord )
vec2 direction = normalize(p - CENTER);
vec2 uv_offset_to_closer_p = direction * (interpolate_delta)*vec2(aspect,1.0);

float surface_end_height = texture(iChannel0, p).x * TOPOLOGY_SCALING_FACTOR;
float surface_end_height = get_texture_max(iChannel0, p) * TOPOLOGY_SCALING_FACTOR;

// inspect fragments near mouse

{
float surface_start_height = texture(iChannel0, p - uv_offset_to_closer_p).x * TOPOLOGY_SCALING_FACTOR;
float surface_start_height = get_texture_max(p - uv_offset_to_closer_p) * TOPOLOGY_SCALING_FACTOR;

float viewer_height = texture(iChannel0, CENTER).x * TOPOLOGY_SCALING_FACTOR + DEVICE_HEIGHT;
float viewer_height = get_texture_max(CENTER) * TOPOLOGY_SCALING_FACTOR + DEVICE_HEIGHT;
vec2 line_start = vec2(distance(p - uv_offset_to_closer_p, CENTER), surface_start_height);
vec2 line_end = vec2(distance(p, CENTER), surface_end_height);
vec2 viewer_loc = vec2(0, viewer_height);


float cross_mag = cross_magnitude(line_start, line_end, viewer_loc);
fragColor = vec4(vec3(-cross_mag), 1.0);
//if (cross_mag <= 0.0){
// fragColor = vec4(1.0);
//}
}
}
}

#ifndef SHADERTOY
void main(){
mainImage(p3d_Color, gl_FragCoord.xy);
}
#endif
36 changes: 35 additions & 1 deletion smarts/core/renderer_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import logging
from dataclasses import dataclass
from enum import IntEnum
from typing import Tuple
from typing import List, Tuple

import numpy as np

Expand All @@ -42,6 +42,12 @@ class DEBUG_MODE(IntEnum):
ERROR = 5


class RendererNotSetUpWarning(UserWarning):
"""This occurs if a renderer is used without being set up."""

pass


@dataclass
class OffscreenCamera:
"""A camera used for rendering images to a graphics buffer."""
Expand Down Expand Up @@ -90,6 +96,22 @@ def teardown(self):
raise NotImplementedError


@dataclass
class ShaderStepDependency:
"""Forwards the texture from a given camera to the"""

camera_id: str
script_variable_name: str


@dataclass
class ShaderStep(OffscreenCamera):
"""A camera used for rendering images using a shader and a fullscreen quad."""

shader_file: str
dependents: List[OffscreenCamera]


class RendererBase:
"""The base class for rendering
Expand Down Expand Up @@ -174,3 +196,15 @@ def build_offscreen_camera(
) -> str:
"""Generates a new off-screen camera."""
raise NotImplementedError

def build_shader_step(
self,
name: str,
fshader_path: str,
camera_dependencies: Tuple[ShaderStepDependency],
priority: int,
height: int,
width: int,
) -> str:
"""Generates a new shader camera."""
raise NotImplementedError
Loading

0 comments on commit 49a3690

Please sign in to comment.