Skip to content

Commit

Permalink
SAMPLEDOF_XXXXX_SAMPLE_FNC(TEX, UV)
Browse files Browse the repository at this point in the history
  • Loading branch information
patriciogonzalezvivo committed Nov 25, 2022
1 parent 593bd13 commit 1efaad2
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 42 deletions.
4 changes: 2 additions & 2 deletions lighting/light/point.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ options:
#include "falloff.glsl"

#ifndef SURFACE_POSITION
#define SURFACE_POSITION vec3(0.0)
#define SURFACE_POSITION vec3(0.0, 0.0, 0.0)
#endif

#ifndef LIGHT_POSITION
#define LIGHT_POSITION vec3(0.0, 10.0, -50.0)
#endif

#ifndef LIGHT_COLOR
#define LIGHT_COLOR vec3(0.5)
#define LIGHT_COLOR vec3(0.5, 0.5, 0.5)
#endif

#ifndef LIGHT_INTENSITY
Expand Down
2 changes: 1 addition & 1 deletion lighting/light/point.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ options:
#include "falloff.hlsl"

#ifndef SURFACE_POSITION
#define SURFACE_POSITION v_position
#define SURFACE_POSITION float(0.0, 0.0, 0.0)
#endif

#ifndef LIGHT_POSITION
Expand Down
2 changes: 1 addition & 1 deletion lighting/light/spot.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ options:
#include "falloff.glsl"

#ifndef SURFACE_POSITION
#define SURFACE_POSITION v_position
#define SURFACE_POSITION vec3(0.0, 0.0, 0.0)
#endif

#ifndef LIGHT_POSITION
Expand Down
2 changes: 1 addition & 1 deletion lighting/light/spot.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ options:
#include "falloff.hlsl"

#ifndef SURFACE_POSITION
#define SURFACE_POSITION v_position
#define SURFACE_POSITION float3(0.0, 0.0, 0.0)
#endif

#ifndef LIGHT_POSITION
Expand Down
6 changes: 1 addition & 5 deletions lighting/material/new.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,7 @@ options:
*/

#ifndef SURFACE_POSITION
#if defined(GLSLVIEWER)
#define SURFACE_POSITION v_position
#else
#define SURFACE_POSITION vec3(0.0)
#endif
#define SURFACE_POSITION vec3(0.0, 0.0, 0.0)
#endif

#ifndef SHADOW_INIT
Expand Down
4 changes: 0 additions & 4 deletions lighting/material/new.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,8 @@ options:
*/

#ifndef SURFACE_POSITION
#if defined(GLSLVIEWER)
#define SURFACE_POSITION v_position
#else
#define SURFACE_POSITION float3(0.0, 0.0, 0.0)
#endif
#endif

#ifndef SHADOW_INIT
#if defined(LIGHT_SHADOWMAP) && defined(LIGHT_SHADOWMAP_SIZE) && defined(LIGHT_COORD)
Expand Down
28 changes: 14 additions & 14 deletions sample/dof.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ options:
- SAMPLEDOF_TYPE:
- SAMPLEDOF_BLUR_SIZE:
- SAMPLEDOF_RAD_SCALE:
- SAMPLEDOF_DEPTH_FNC(UV):
- SAMPLEDOF_COLOR_FNC(UV):
- SAMPLEDOF_DEPTH_SAMPLE_FNC(TEX, UV):
- SAMPLEDOF_COLOR_SAMPLE_FNC(TEX, UV):
- SAMPLEDOF_DEBUG
- RESOLUTION
*/
Expand All @@ -32,12 +32,12 @@ options:
#define GOLDEN_ANGLE 2.39996323
#endif

#ifndef SAMPLEDOF_DEPTH_FNC
#define SAMPLEDOF_DEPTH_FNC(UV) SAMPLER_FNC(texDepth,UV).r
#ifndef SAMPLEDOF_DEPTH_SAMPLE_FNC
#define SAMPLEDOF_DEPTH_SAMPLE_FNC(TEX, UV) SAMPLER_FNC(TEX,UV).r
#endif

#ifndef SAMPLEDOF_COLOR_FNC
#define SAMPLEDOF_COLOR_FNC(UV) SAMPLER_FNC(tex,UV).rgb
#ifndef SAMPLEDOF_COLOR_SAMPLE_FNC
#define SAMPLEDOF_COLOR_SAMPLE_FNC(TEX, UV) SAMPLER_FNC(TEX, UV).rgb
#endif

#ifndef SAMPLEDOF_TYPE
Expand All @@ -54,10 +54,10 @@ float getBlurSize(float depth,float focusPoint,float focusScale){
SAMPLEDOF_TYPE sampleDoF(sampler2D tex,sampler2D texDepth,vec2 texCoord,float focusPoint,float focusScale){
float pct=0.;

float centerDepth = SAMPLEDOF_DEPTH_FNC(texCoord);
float centerDepth = SAMPLEDOF_DEPTH_SAMPLE_FNC(texDepth, texCoord);
float centerSize = getBlurSize(centerDepth, focusPoint, focusScale);
vec2 pixelSize = 1.0/RESOLUTION.xy;
SAMPLEDOF_TYPE color = SAMPLEDOF_COLOR_FNC(texCoord);
SAMPLEDOF_TYPE color = SAMPLEDOF_COLOR_SAMPLE_FNC(tex, texCoord);

float total = 1.0;
float radius = SAMPLEDOF_RAD_SCALE;
Expand All @@ -66,12 +66,12 @@ SAMPLEDOF_TYPE sampleDoF(sampler2D tex,sampler2D texDepth,vec2 texCoord,float fo
break;

vec2 tc = texCoord + vec2(cos(angle), sin(angle)) * pixelSize * radius;
float sampleDepth = SAMPLEDOF_DEPTH_FNC(tc);
float sampleDepth = SAMPLEDOF_DEPTH_SAMPLE_FNC(texDepth, tc);
float sampleSize = getBlurSize(sampleDepth, focusPoint, focusScale);
if (sampleDepth > centerDepth)
sampleSize=clamp(sampleSize, 0.0, centerSize*2.0);
pct = smoothstep(radius-0.5, radius+0.5, sampleSize);
SAMPLEDOF_TYPE sampleColor = SAMPLEDOF_COLOR_FNC(tc);
SAMPLEDOF_TYPE sampleColor = SAMPLEDOF_COLOR_SAMPLE_FNC(tex, tc);
#ifdef SAMPLEDOF_DEBUG
sampleColor.rgb = heatmap(pct*0.5+(angle/SAMPLEDOF_BLUR_SIZE)*0.1);
#endif
Expand All @@ -88,21 +88,21 @@ SAMPLEDOF_TYPE sampleDoF(sampler2D tex, sampler2D texDepth, vec2 texCoord, float
float pct = 0.0;
float ang = 0.0;

float centerDepth = SAMPLEDOF_DEPTH_FNC(texCoord);
float centerDepth = SAMPLEDOF_DEPTH_SAMPLE_FNC(texDepth, texCoord);
float centerSize = getBlurSize(centerDepth, focusPoint, focusScale);
vec2 pixelSize = 1./RESOLUTION.xy;
SAMPLEDOF_TYPE color = SAMPLEDOF_COLOR_FNC(texCoord);
SAMPLEDOF_TYPE color = SAMPLEDOF_COLOR_SAMPLE_FNC(tex, texCoord);

float tot = 1.0;
float radius = SAMPLEDOF_RAD_SCALE;
for (ang = 0.0; radius < SAMPLEDOF_BLUR_SIZE; ang += GOLDEN_ANGLE) {
vec2 tc = texCoord + vec2(cos(ang), sin(ang)) * pixelSize * radius;
float sampleDepth = SAMPLEDOF_DEPTH_FNC(tc);
float sampleDepth = SAMPLEDOF_DEPTH_SAMPLE_FNC(texDepth, tc);
float sampleSize = getBlurSize(sampleDepth, focusPoint, focusScale);
if (sampleDepth > centerDepth)
sampleSize = clamp(sampleSize, 0.0, centerSize*2.0);
pct = smoothstep(radius-0.5, radius+0.5, sampleSize);
SAMPLEDOF_TYPE sampleColor = SAMPLEDOF_COLOR_FNC(tc);
SAMPLEDOF_TYPE sampleColor = SAMPLEDOF_COLOR_SAMPLE_FNC(tex, tc);
#ifdef SAMPLEDOF_DEBUG
sampleColor.rgb = heatmap(pct * 0.5 + (ang/SAMPLEDOF_BLUR_SIZE) * 0.1);
#endif
Expand Down
28 changes: 14 additions & 14 deletions sample/dof.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ options:
- SAMPLEDOF_TYPE:
- SAMPLEDOF_BLUR_SIZE:
- SAMPLEDOF_RAD_SCALE:
- SAMPLEDOF_DEPTH_FNC(UV):
- SAMPLEDOF_COLOR_FNC(UV):
- SAMPLEDOF_DEPTH_SAMPLE_FNC(TEX, UV):
- SAMPLEDOF_COLOR_SAMPLE_FNC(TEX, UV):
*/

#ifndef RESOLUTION
Expand All @@ -37,12 +37,12 @@ options:
#define GOLDEN_ANGLE 2.39996323
#endif

#ifndef SAMPLEDOF_DEPTH_FNC
#define SAMPLEDOF_DEPTH_FNC(UV) SAMPLER_FNC(texDepth,UV).r
#ifndef SAMPLEDOF_DEPTH_SAMPLE_FNC
#define SAMPLEDOF_DEPTH_SAMPLE_FNC(TEX, UV) SAMPLER_FNC(TEX,UV).r
#endif

#ifndef SAMPLEDOF_COLOR_FNC
#define SAMPLEDOF_COLOR_FNC(UV) SAMPLER_FNC(tex,UV).rgb
#ifndef SAMPLEDOF_COLOR_SAMPLE_FNC
#define SAMPLEDOF_COLOR_SAMPLE_FNC(TEX, UV) SAMPLER_FNC(TEx, UV).rgb
#endif

#ifndef SAMPLEDOF_TYPE
Expand All @@ -59,10 +59,10 @@ float getBlurSize(float depth,float focusPoint,float focusScale){
SAMPLEDOF_TYPE sampleDoF(sampler2D tex, sampler2D texDepth, float2 texCoord, float focusPoint, float focusScale){
float pct=0.;

float centerDepth = SAMPLEDOF_DEPTH_FNC(texCoord);
float centerDepth = SAMPLEDOF_DEPTH_SAMPLE_FNC(texDepth, texCoord);
float centerSize = getBlurSize(centerDepth, focusPoint, focusScale);
float2 pixelSize = 1.0/RESOLUTION.xy;
SAMPLEDOF_TYPE color = SAMPLEDOF_COLOR_FNC(texCoord);
SAMPLEDOF_TYPE color = SAMPLEDOF_COLOR_SAMPLE_FNC(tex, texCoord);

float total = 1.0;
float radius = SAMPLEDOF_RAD_SCALE;
Expand All @@ -71,12 +71,12 @@ SAMPLEDOF_TYPE sampleDoF(sampler2D tex, sampler2D texDepth, float2 texCoord, flo
break;

float2 tc = texCoord + float2(cos(angle), sin(angle)) * pixelSize * radius;
float sampleDepth = SAMPLEDOF_DEPTH_FNC(tc);
float sampleDepth = SAMPLEDOF_DEPTH_SAMPLE_FNC(texDepth, tc);
float sampleSize = getBlurSize(sampleDepth, focusPoint, focusScale);
if (sampleDepth > centerDepth)
sampleSize=clamp(sampleSize, 0.0, centerSize*2.0);
pct = smoothstep(radius-0.5, radius+0.5, sampleSize);
SAMPLEDOF_TYPE sampleColor = SAMPLEDOF_COLOR_FNC(tc);
SAMPLEDOF_TYPE sampleColor = SAMPLEDOF_COLOR_SAMPLE_FNC(tex, tc);
#ifdef SAMPLEDOF_DEBUG
sampleColor.rgb = heatmap(pct*0.5+(angle/SAMPLEDOF_BLUR_SIZE)*0.1);
#endif
Expand All @@ -93,21 +93,21 @@ SAMPLEDOF_TYPE sampleDoF(sampler2D tex, sampler2D texDepth, float2 texCoord, flo
float pct = 0.0;
float ang = 0.0;

float centerDepth = SAMPLEDOF_DEPTH_FNC(texCoord);
float centerDepth = SAMPLEDOF_DEPTH_SAMPLE_FNC(texDepth, texCoord);
float centerSize = getBlurSize(centerDepth, focusPoint, focusScale);
float2 pixelSize = 1./RESOLUTION.xy;
SAMPLEDOF_TYPE color = SAMPLEDOF_COLOR_FNC(texCoord);
SAMPLEDOF_TYPE color = SAMPLEDOF_COLOR_SAMPLE_FNC(tex, texCoord);

float tot = 1.0;
float radius = SAMPLEDOF_RAD_SCALE;
for (ang = 0.0; radius < SAMPLEDOF_BLUR_SIZE; ang += GOLDEN_ANGLE) {
float2 tc = texCoord + float2(cos(ang), sin(ang)) * pixelSize * radius;
float sampleDepth = SAMPLEDOF_DEPTH_FNC(tc);
float sampleDepth = SAMPLEDOF_DEPTH_SAMPLE_FNC(texDepth, tc);
float sampleSize = getBlurSize(sampleDepth, focusPoint, focusScale);
if (sampleDepth > centerDepth)
sampleSize = clamp(sampleSize, 0.0, centerSize*2.0);
pct = smoothstep(radius-0.5, radius+0.5, sampleSize);
SAMPLEDOF_TYPE sampleColor = SAMPLEDOF_COLOR_FNC(tc);
SAMPLEDOF_TYPE sampleColor = SAMPLEDOF_COLOR_SAMPLE_FNC(tex, tc);
#ifdef SAMPLEDOF_DEBUG
sampleColor.rgb = heatmap(pct * 0.5 + (ang/SAMPLEDOF_BLUR_SIZE) * 0.1);
#endif
Expand Down

0 comments on commit 1efaad2

Please sign in to comment.