summaryrefslogtreecommitdiffstats
path: root/src/demos/hdr/shaders
diff options
context:
space:
mode:
authorKenneth Russel <[email protected]>2005-05-27 19:45:51 +0000
committerKenneth Russel <[email protected]>2005-05-27 19:45:51 +0000
commit9d209d3b6ae12604e666d7b655bd1f19e70ee48b (patch)
tree5eb780835a316cbb62a9718a2757a3d51c31adb5 /src/demos/hdr/shaders
parent02acfb8e24959f43cada34366598236a51b782bb (diff)
Added Java/JOGL port of NVidia HDR demo.
git-svn-id: file:///usr/local/projects/SUN/JOGL/git-svn/../svn-server-sync/jogl-demos/trunk@80 3298f667-5e0e-4b4a-8ed4-a3559d26a5f4
Diffstat (limited to 'src/demos/hdr/shaders')
-rwxr-xr-xsrc/demos/hdr/shaders/arbfp1/object.arbfp141
-rwxr-xr-xsrc/demos/hdr/shaders/arbfp1/object_hilo.arbfp145
-rwxr-xr-xsrc/demos/hdr/shaders/arbfp1/object_vp.arbvp142
-rwxr-xr-xsrc/demos/hdr/shaders/arbfp1/recompile.txt7
-rwxr-xr-xsrc/demos/hdr/shaders/arbfp1/shrink.arbfp134
-rwxr-xr-xsrc/demos/hdr/shaders/arbfp1/skybox.arbfp122
-rwxr-xr-xsrc/demos/hdr/shaders/arbfp1/skybox_hilo.arbfp127
-rwxr-xr-xsrc/demos/hdr/shaders/arbfp1/tonemap.arbfp164
-rwxr-xr-xsrc/demos/hdr/shaders/cg/hdr.cg130
-rwxr-xr-xsrc/demos/hdr/shaders/cg/object.cg30
-rwxr-xr-xsrc/demos/hdr/shaders/cg/object_hilo.cg31
-rwxr-xr-xsrc/demos/hdr/shaders/cg/object_vp.cg43
-rwxr-xr-xsrc/demos/hdr/shaders/cg/shrink.cg17
-rwxr-xr-xsrc/demos/hdr/shaders/cg/skybox.cg8
-rwxr-xr-xsrc/demos/hdr/shaders/cg/skybox_hilo.cg9
-rwxr-xr-xsrc/demos/hdr/shaders/cg/tonemap.cg37
16 files changed, 587 insertions, 0 deletions
diff --git a/src/demos/hdr/shaders/arbfp1/object.arbfp1 b/src/demos/hdr/shaders/arbfp1/object.arbfp1
new file mode 100755
index 0000000..30ee986
--- /dev/null
+++ b/src/demos/hdr/shaders/arbfp1/object.arbfp1
@@ -0,0 +1,41 @@
+!!ARBfp1.0
+# cgc version 1.3.0001, build date Aug 4 2004 10:01:10
+# command line args: -profile arbfp1
+# source file: ../cg/object.cg
+# source file: ../cg/hdr.cg
+#vendor NVIDIA Corporation
+#version 1.0.02
+#profile arbfp1
+#program main
+#semantic main.envMap : TEXUNIT0
+#var float4 In.HPosition : : : 0 : 0
+#var float4 In.P : : : 0 : 0
+#var float3 In.N : $vin.TEX1 : TEX1 : 0 : 1
+#var float3 In.I : $vin.TEX2 : TEX2 : 0 : 1
+#var samplerCUBE envMap : TEXUNIT0 : texunit 0 : 1 : 1
+#var half4 main : $vout.COL : COL : -1 : 1
+#const c[0] = 2 1 0 5
+#const c[1] = 0.9799805 0.02000427
+PARAM c[2] = { { 2, 1, 0, 5 },
+ { 0.97998047, 0.020004272 } };
+TEMP R0;
+TEMP R1;
+DP3 R0.y, fragment.texcoord[2], fragment.texcoord[2];
+RSQ R0.w, R0.y;
+DP3 R0.x, fragment.texcoord[1], fragment.texcoord[1];
+RSQ R0.x, R0.x;
+MUL R1.xyz, R0.w, fragment.texcoord[2];
+MUL R0.xyz, R0.x, fragment.texcoord[1];
+DP3 R0.w, -R1, R0;
+ADD R0.w, -R0, c[0].y;
+DP3 R1.w, R0, R1;
+MAX R0.w, R0, c[0].z;
+MUL R0.xyz, R0, R1.w;
+POW R0.w, R0.w, c[0].w;
+MAD R0.xyz, -R0, c[0].x, R1;
+MAD R0.w, R0, c[1].x, c[1].y;
+TEX R0.xyz, R0, texture[0], CUBE;
+MUL result.color.xyz, R0, R0.w;
+MOV result.color.w, c[0].y;
+END
+# 17 instructions, 2 R-regs
diff --git a/src/demos/hdr/shaders/arbfp1/object_hilo.arbfp1 b/src/demos/hdr/shaders/arbfp1/object_hilo.arbfp1
new file mode 100755
index 0000000..c6d5b55
--- /dev/null
+++ b/src/demos/hdr/shaders/arbfp1/object_hilo.arbfp1
@@ -0,0 +1,45 @@
+!!ARBfp1.0
+# cgc version 1.3.0001, build date Aug 4 2004 10:01:10
+# command line args: -profile arbfp1
+# source file: ../cg/object_hilo.cg
+# source file: ../cg/hdr.cg
+#vendor NVIDIA Corporation
+#version 1.0.02
+#profile arbfp1
+#program main
+#semantic main.envMap_rg : TEXUNIT0
+#semantic main.envMap_b : TEXUNIT1
+#var float4 In.HPosition : : : 0 : 0
+#var float4 In.P : : : 0 : 0
+#var float3 In.N : $vin.TEX1 : TEX1 : 0 : 1
+#var float3 In.I : $vin.TEX2 : TEX2 : 0 : 1
+#var samplerCUBE envMap_rg : TEXUNIT0 : texunit 0 : 1 : 1
+#var samplerCUBE envMap_b : TEXUNIT1 : texunit 1 : 2 : 1
+#var half4 main : $vout.COL : COL : -1 : 1
+#const c[0] = 2 1 0 5
+#const c[1] = 0.9799805 0.02000427
+PARAM c[2] = { { 2, 1, 0, 5 },
+ { 0.97998047, 0.020004272 } };
+TEMP R0;
+TEMP R1;
+DP3 R0.y, fragment.texcoord[2], fragment.texcoord[2];
+RSQ R0.y, R0.y;
+DP3 R0.x, fragment.texcoord[1], fragment.texcoord[1];
+MUL R1.xyz, R0.y, fragment.texcoord[2];
+RSQ R0.x, R0.x;
+MUL R0.xyz, R0.x, fragment.texcoord[1];
+DP3 R0.w, -R1, R0;
+DP3 R1.w, R0, R1;
+MUL R0.xyz, R0, R1.w;
+MAD R1.xyz, -R0, c[0].x, R1;
+ADD R0.w, -R0, c[0].y;
+MAX R0.y, R0.w, c[0].z;
+TEX R0.x, R1, texture[1], CUBE;
+POW R0.y, R0.y, c[0].w;
+MOV R0.z, R0.x;
+MAD R0.w, R0.y, c[1].x, c[1].y;
+TEX R0.xy, R1, texture[0], CUBE;
+MUL result.color.xyz, R0, R0.w;
+MOV result.color.w, c[0].y;
+END
+# 19 instructions, 2 R-regs
diff --git a/src/demos/hdr/shaders/arbfp1/object_vp.arbvp1 b/src/demos/hdr/shaders/arbfp1/object_vp.arbvp1
new file mode 100755
index 0000000..1f2a6fa
--- /dev/null
+++ b/src/demos/hdr/shaders/arbfp1/object_vp.arbvp1
@@ -0,0 +1,42 @@
+!!ARBvp1.0
+# cgc version 1.3.0001, build date Aug 4 2004 10:01:10
+# command line args: -profile arbvp1
+# source file: ../cg/object_vp.cg
+# source file: ../cg/hdr.cg
+#vendor NVIDIA Corporation
+#version 1.0.02
+#profile arbvp1
+#program main
+#semantic main.modelViewProj
+#semantic main.model
+#semantic main.eyePos
+#var float4 In.Position : $vin.POSITION : POSITION : 0 : 1
+#var float4 In.Normal : $vin.NORMAL : NORMAL : 0 : 1
+#var float4x4 modelViewProj : : c[0], 4 : 1 : 1
+#var float4x4 model : : c[4], 4 : 2 : 1
+#var float3 eyePos : : c[8] : 3 : 1
+#var float4 main.HPosition : $vout.HPOS : HPOS : -1 : 1
+#var float4 main.P : $vout.TEX0 : TEX0 : -1 : 1
+#var float3 main.N : $vout.TEX1 : TEX1 : -1 : 1
+#var float3 main.I : $vout.TEX2 : TEX2 : -1 : 1
+PARAM c[9] = { program.local[0..8] };
+TEMP R0;
+TEMP R1;
+DP4 result.position.w, vertex.position, c[3];
+DP4 result.position.z, vertex.position, c[2];
+DP4 result.position.y, vertex.position, c[1];
+DP4 result.position.x, vertex.position, c[0];
+DP4 R0.w, vertex.position, c[7];
+DP4 R0.z, vertex.position, c[6];
+DP4 R0.y, vertex.position, c[5];
+DP3 R1.z, vertex.normal, c[6];
+DP3 R1.y, vertex.normal, c[5];
+DP3 R1.x, vertex.normal, c[4];
+DP4 R0.x, vertex.position, c[4];
+DP3 R1.w, R1, R1;
+ADD result.texcoord[2].xyz, R0, -c[8];
+RSQ R1.w, R1.w;
+MOV result.texcoord[0], R0;
+MUL result.texcoord[1].xyz, R1.w, R1;
+END
+# 16 instructions, 2 R-regs
diff --git a/src/demos/hdr/shaders/arbfp1/recompile.txt b/src/demos/hdr/shaders/arbfp1/recompile.txt
new file mode 100755
index 0000000..48469f3
--- /dev/null
+++ b/src/demos/hdr/shaders/arbfp1/recompile.txt
@@ -0,0 +1,7 @@
+cgc -profile arbfp1 -o object.arbfp1 ../cg/object.cg
+cgc -profile arbfp1 -o object_hilo.arbfp1 ../cg/object_hilo.cg
+cgc -profile arbvp1 -o object_vp.arbvp1 ../cg/object_vp.cg
+cgc -profile arbfp1 -o shrink.arbfp1 ../cg/shrink.cg
+cgc -profile arbfp1 -o skybox.arbfp1 ../cg/skybox.cg
+cgc -profile arbfp1 -o skybox_hilo.arbfp1 ../cg/skybox_hilo.cg
+cgc -profile arbfp1 -o tonemap.arbfp1 ../cg/tonemap.cg
diff --git a/src/demos/hdr/shaders/arbfp1/shrink.arbfp1 b/src/demos/hdr/shaders/arbfp1/shrink.arbfp1
new file mode 100755
index 0000000..ddf7a4b
--- /dev/null
+++ b/src/demos/hdr/shaders/arbfp1/shrink.arbfp1
@@ -0,0 +1,34 @@
+!!ARBfp1.0
+# cgc version 1.3.0001, build date Aug 4 2004 10:01:10
+# command line args: -profile arbfp1
+# source file: ../cg/shrink.cg
+# source file: ../cg/hdr.cg
+#vendor NVIDIA Corporation
+#version 1.0.02
+#profile arbfp1
+#program main
+#semantic main.sceneTex : TEXUNIT0
+#var float4 In.wpos : : : 0 : 0
+#var float3 In.tex0 : $vin.TEX0 : TEX0 : 0 : 1
+#var float3 In.tex1 : : : 0 : 0
+#var float4 In.col0 : : : 0 : 0
+#var samplerRECT sceneTex : TEXUNIT0 : texunit 0 : 1 : 1
+#var half4 main : $vout.COL : COL : -1 : 1
+#const c[0] = 1 0 0.25
+PARAM c[1] = { { 1, 0, 0.25 } };
+TEMP R0;
+TEMP R1;
+TEMP R2;
+ADD R0.xy, fragment.texcoord[0], c[0];
+TEX R1, R0, texture[0], RECT;
+TEX R0, fragment.texcoord[0], texture[0], RECT;
+ADD R2, R0, R1;
+ADD R0.xy, fragment.texcoord[0], c[0].yxzw;
+ADD R1.xy, fragment.texcoord[0], c[0].x;
+TEX R0, R0, texture[0], RECT;
+TEX R1, R1, texture[0], RECT;
+ADD R0, R2, R0;
+ADD R0, R0, R1;
+MUL result.color, R0, c[0].z;
+END
+# 11 instructions, 3 R-regs
diff --git a/src/demos/hdr/shaders/arbfp1/skybox.arbfp1 b/src/demos/hdr/shaders/arbfp1/skybox.arbfp1
new file mode 100755
index 0000000..8d3d9db
--- /dev/null
+++ b/src/demos/hdr/shaders/arbfp1/skybox.arbfp1
@@ -0,0 +1,22 @@
+!!ARBfp1.0
+# cgc version 1.3.0001, build date Aug 4 2004 10:01:10
+# command line args: -profile arbfp1
+# source file: ../cg/skybox.cg
+# source file: ../cg/hdr.cg
+#vendor NVIDIA Corporation
+#version 1.0.02
+#profile arbfp1
+#program main
+#semantic main.envMap : TEXUNIT0
+#var float4 In.wpos : : : 0 : 0
+#var float3 In.tex0 : $vin.TEX0 : TEX0 : 0 : 1
+#var float3 In.tex1 : : : 0 : 0
+#var float4 In.col0 : : : 0 : 0
+#var samplerCUBE envMap : TEXUNIT0 : texunit 0 : 1 : 1
+#var half4 main : $vout.COL : COL : -1 : 1
+#const c[0] = 1
+PARAM c[1] = { { 1 } };
+TEX result.color.xyz, fragment.texcoord[0], texture[0], CUBE;
+MOV result.color.w, c[0].x;
+END
+# 2 instructions, 0 R-regs
diff --git a/src/demos/hdr/shaders/arbfp1/skybox_hilo.arbfp1 b/src/demos/hdr/shaders/arbfp1/skybox_hilo.arbfp1
new file mode 100755
index 0000000..fe0d910
--- /dev/null
+++ b/src/demos/hdr/shaders/arbfp1/skybox_hilo.arbfp1
@@ -0,0 +1,27 @@
+!!ARBfp1.0
+# cgc version 1.3.0001, build date Aug 4 2004 10:01:10
+# command line args: -profile arbfp1
+# source file: ../cg/skybox_hilo.cg
+# source file: ../cg/hdr.cg
+#vendor NVIDIA Corporation
+#version 1.0.02
+#profile arbfp1
+#program main
+#semantic main.envMap_rg : TEXUNIT0
+#semantic main.envMap_b : TEXUNIT1
+#var float4 In.wpos : : : 0 : 0
+#var float3 In.tex0 : $vin.TEX0 : TEX0 : 0 : 1
+#var float3 In.tex1 : : : 0 : 0
+#var float4 In.col0 : : : 0 : 0
+#var samplerCUBE envMap_rg : TEXUNIT0 : texunit 0 : 1 : 1
+#var samplerCUBE envMap_b : TEXUNIT1 : texunit 1 : 2 : 1
+#var half4 main : $vout.COL : COL : -1 : 1
+#const c[0] = 1
+PARAM c[1] = { { 1 } };
+TEMP R0;
+TEX R0.x, fragment.texcoord[0], texture[1], CUBE;
+TEX result.color.xy, fragment.texcoord[0], texture[0], CUBE;
+MOV result.color.z, R0.x;
+MOV result.color.w, c[0].x;
+END
+# 4 instructions, 1 R-regs
diff --git a/src/demos/hdr/shaders/arbfp1/tonemap.arbfp1 b/src/demos/hdr/shaders/arbfp1/tonemap.arbfp1
new file mode 100755
index 0000000..0dd5a5a
--- /dev/null
+++ b/src/demos/hdr/shaders/arbfp1/tonemap.arbfp1
@@ -0,0 +1,64 @@
+!!ARBfp1.0
+# cgc version 1.3.0001, build date Aug 4 2004 10:01:10
+# command line args: -profile arbfp1
+# source file: ../cg/tonemap.cg
+# source file: ../cg/hdr.cg
+#vendor NVIDIA Corporation
+#version 1.0.02
+#profile arbfp1
+#program main
+#semantic main.sceneTex : TEXUNIT0
+#semantic main.blurTex : TEXUNIT1
+#semantic main.gammaTex : TEXUNIT2
+#semantic main.vignetteTex : TEXUNIT3
+#semantic main.blurAmount
+#semantic main.windowSize
+#semantic main.exposure
+#var float4 In.wpos : : : 0 : 0
+#var float3 In.tex0 : $vin.TEX0 : TEX0 : 0 : 1
+#var float3 In.tex1 : $vin.TEX1 : TEX1 : 0 : 1
+#var float4 In.col0 : : : 0 : 0
+#var samplerRECT sceneTex : TEXUNIT0 : texunit 0 : 1 : 1
+#var samplerRECT blurTex : TEXUNIT1 : texunit 1 : 2 : 1
+#var sampler1D gammaTex : TEXUNIT2 : texunit 2 : 3 : 1
+#var samplerRECT vignetteTex : TEXUNIT3 : texunit 3 : 4 : 1
+#var float blurAmount : : c[1] : 5 : 1
+#var float4 windowSize : : : 6 : 0
+#var float exposure : : c[2] : 7 : 1
+#var half4 main : $vout.COL : COL : -1 : 1
+#const c[0] = 1 0
+PARAM c[3] = { { 1, 0 },
+ program.local[1..2] };
+TEMP R0;
+TEMP R1;
+TEMP R2;
+TEMP R3;
+TEMP R4;
+ADD R0.xy, fragment.texcoord[1], c[0].yxzw;
+ADD R1.xy, fragment.texcoord[1], c[0].x;
+TEX R1.xyz, R1, texture[1], RECT;
+TEX R0.xyz, R0, texture[1], RECT;
+ADD R3.xyz, R1, -R0;
+FRC R4.xy, fragment.texcoord[1];
+ADD R1.xy, fragment.texcoord[1], c[0];
+TEX R2.xyz, fragment.texcoord[1], texture[1], RECT;
+TEX R1.xyz, R1, texture[1], RECT;
+ADD R1.xyz, R1, -R2;
+MAD R1.xyz, R4.x, R1, R2;
+MAD R0.xyz, R4.x, R3, R0;
+ADD R2.xyz, R0, -R1;
+TEX R0.xyz, fragment.texcoord[0], texture[0], RECT;
+MAD R1.xyz, R4.y, R2, R1;
+ADD R1.xyz, R1, -R0;
+MAD R1.xyz, R1, c[1].x, R0;
+MUL R1.xyz, R1, c[2].x;
+TEX R0.xyz, fragment.texcoord[0], texture[3], RECT;
+MUL R0.xyz, R1, R0;
+TEX result.color.x, R0, texture[2], 1D;
+TEX R0.x, R0.y, texture[2], 1D;
+TEX R1.x, R0.z, texture[2], 1D;
+MOV result.color.y, R0.x;
+MOV result.color.z, R1.x;
+MOV result.color.w, c[0].x;
+END
+# 26 instructions, 5 R-regs
diff --git a/src/demos/hdr/shaders/cg/hdr.cg b/src/demos/hdr/shaders/cg/hdr.cg
new file mode 100755
index 0000000..3a0cafd
--- /dev/null
+++ b/src/demos/hdr/shaders/cg/hdr.cg
@@ -0,0 +1,130 @@
+/*
+ Cg functions to decode and filter textures in Radiance (RGBE) high dynamic range format
+ sgg 2/15/02
+
+ http://www.graphics.cornell.edu/~bjw/rgbe.html
+*/
+
+#if 0
+typedef float4 vec4;
+typedef float3 vec3;
+typedef float2 vec2;
+typedef float real;
+#define texRECT f4texRECT
+#define texCUBE f4texCUBE
+#else
+typedef half4 vec4;
+typedef half3 vec3;
+typedef half2 vec2;
+typedef half real;
+#define texRECT h4texRECT
+#define texCUBE h4texCUBE
+#endif
+
+struct fragin
+{
+ float4 wpos : WPOS;
+ float3 tex0 : TEXCOORD0;
+ float3 tex1 : TEXCOORD1;
+ float4 col0 : COLOR0;
+};
+
+// Lookup in RGBE-encoded rectangle texture
+vec3 texRECT_RGBE(uniform samplerRECT tex, float2 t)
+{
+ vec4 rgbe = texRECT(tex, t);
+ real e = (rgbe[3] * 255) - 128;
+ return rgbe.xyz * exp2(e);
+}
+
+// Lookup in RGBE-encoded cube map texture
+vec3 texCUBE_RGBE(uniform samplerCUBE tex, float3 t)
+{
+ vec4 rgbe = texCUBE(tex, t);
+ real e = (rgbe[3] * 255) - 128;
+ return rgbe.xyz * exp2(e);
+}
+
+// Lookup in RGBE-encoded rectangle texture with filtering
+vec3 texRECT_RGBE_Bilinear(uniform samplerRECT tex, half2 t)
+{
+ float2 f = frac(t);
+ vec3 t0 = texRECT_RGBE(tex, t);
+ vec3 t1 = texRECT_RGBE(tex, t + half2(1,0) );
+ vec3 t2 = lerp(t0, t1, f[0]);
+ t0 = texRECT_RGBE(tex, t + half2(0,1) );
+ t1 = texRECT_RGBE(tex, t + half2(1,1) );
+ t0 = lerp(t0, t1, f[0]);
+ t0 = lerp(t2, t0, f[1]);
+ return t0;
+}
+
+// Lookup in cubemap encoded as two HILO cube maps
+vec3 texCUBE_hilo(uniform samplerCUBE rg_tex : TEXUNIT0, uniform samplerCUBE b_tex : TEXUNIT1, float3 t)
+{
+ vec3 c;
+ c.xy = texCUBE(rg_tex, t).xy;
+ c.z = texCUBE(b_tex, t).x;
+// c = c * c;
+ return c;
+}
+
+// Lookup in rectangle texture encoded as two HILO cube maps
+vec3 texRECT_hilo(uniform samplerRECT rg_tex : TEXUNIT0, uniform samplerRECT b_tex : TEXUNIT1, float2 t)
+{
+ vec3 c;
+ c.xy = texRECT(rg_tex, t).xy;
+ c.z = texRECT(b_tex, t).x;
+ return c;
+}
+
+// bilinear lookup in float texture
+vec4 texRECT_bilinear(uniform samplerRECT tex, half2 t)
+{
+ float2 f = frac(t);
+ vec4 t0 = texRECT(tex, t);
+ vec4 t1 = texRECT(tex, t + half2(1,0) );
+ vec4 t2 = lerp(t0, t1, f[0]);
+ t0 = texRECT(tex, t + half2(0,1) );
+ t1 = texRECT(tex, t + half2(1,1) );
+ t0 = lerp(t0, t1, f[0]);
+ t0 = lerp(t2, t0, f[1]);
+ return t0;
+}
+
+// applying vignetting based on window coordinates
+void vignette(inout float3 c, float4 wpos, const float2 win_bias, const float2 win_scale)
+{
+ // convert window coord to [-1, 1] range
+ wpos.xy = (wpos.xy - win_bias) * win_scale;
+ // calculate distance from origin
+ float r = length(wpos.xy);
+ r = 1.0 - smoothstep(0.8, 1.5, r);
+ c = c * r;
+}
+
+// refraction function from Renderman spec
+// I = incident direction, N = normal, eta = relative index of refraction
+half3 my_refract(half3 I, half3 N, half eta)
+{
+ half IdotN = dot(I,N);
+ half k = 1 - eta*eta*(1 - IdotN*IdotN);
+
+ return eta*I - (eta*IdotN + sqrt(k))*N;
+}
+
+// fresnel approximation
+half my_fresnel(half3 I, half3 N, half power, half scale, half bias)
+{
+ return bias + (pow(max(0.0, 1.0 - dot(I, N)), power) * scale);
+}
+
+// transform a direction vector by a 4x4 matrix
+float3 transform_dir(float4x4 m, float3 v)
+{
+ float3 o;
+ o.x = dot(v, m._11_12_13);
+ o.y = dot(v, m._21_22_23);
+ o.z = dot(v, m._31_32_33);
+ return o;
+}
diff --git a/src/demos/hdr/shaders/cg/object.cg b/src/demos/hdr/shaders/cg/object.cg
new file mode 100755
index 0000000..a242bc6
--- /dev/null
+++ b/src/demos/hdr/shaders/cg/object.cg
@@ -0,0 +1,30 @@
+// object shader
+
+#include "hdr.cg"
+
+struct v2f
+{
+ float4 HPosition : POSITION;
+ float4 P : TEXCOORD0; // position
+ float3 N : TEXCOORD1; // normal
+ float3 I : TEXCOORD2; // incident vector
+};
+
+half4 main(v2f In,
+ uniform samplerCUBE envMap : TEXUNIT0) : COLOR
+{
+ half3 I = normalize(half3(In.I));
+ half3 N = normalize(half3(In.N));
+
+ half3 R = reflect(I, N);
+// half3 T = refract(I, N, 0.9);
+ half fresnel = my_fresnel(-I, N, 5.0, 0.98, 0.02);
+
+ half3 Creflect = texCUBE(envMap, R).rgb; // lookup reflection in HDR cube map
+// half3 Crefract = texCUBE(envMap, T).rgb; // refraction
+
+// half3 Cout = lerp(Crefract, Creflect, fresnel);
+// return half4(Cout, fresnel*0.5 + 0.5);
+
+ return half4(Creflect * fresnel, 1.0);
+}
diff --git a/src/demos/hdr/shaders/cg/object_hilo.cg b/src/demos/hdr/shaders/cg/object_hilo.cg
new file mode 100755
index 0000000..88a3348
--- /dev/null
+++ b/src/demos/hdr/shaders/cg/object_hilo.cg
@@ -0,0 +1,31 @@
+// object shader
+
+#include "hdr.cg"
+
+struct v2f
+{
+ float4 HPosition : POSITION;
+ float4 P : TEXCOORD0; // position
+ float3 N : TEXCOORD1; // normal
+ float3 I : TEXCOORD2; // incident vector
+};
+
+half4 main(v2f In,
+ uniform samplerCUBE envMap_rg : TEXUNIT0,
+ uniform samplerCUBE envMap_b : TEXUNIT1) : COLOR
+{
+ half3 I = normalize(half3(In.I));
+ half3 N = normalize(half3(In.N));
+
+ half3 R = reflect(I, N);
+// half3 T = refract(I, N, 0.9);
+ half fresnel = my_fresnel(-I, N, 5.0, 0.98, 0.02);
+
+ half3 Creflect = texCUBE_hilo(envMap_rg, envMap_b, R).rgb; // lookup reflection in HDR cube map
+// half3 Crefract = texCUBE_hilo(envMap_rg, envMap_b, T).rgb; // refraction
+
+// half3 Cout = lerp(Crefract, Creflect, fresnel);
+// return half4(Cout, 1.0);
+
+ return half4(Creflect * fresnel, 1.0);
+}
diff --git a/src/demos/hdr/shaders/cg/object_vp.cg b/src/demos/hdr/shaders/cg/object_vp.cg
new file mode 100755
index 0000000..895dc28
--- /dev/null
+++ b/src/demos/hdr/shaders/cg/object_vp.cg
@@ -0,0 +1,43 @@
+#include "hdr.cg"
+
+// application to vertex shader
+struct a2v
+{
+ float4 Position : POSITION;
+ float4 Normal : NORMAL;
+};
+
+// vertex shader to fragment shader
+struct v2f
+{
+ float4 HPosition : POSITION;
+ float4 P : TEXCOORD0; // position
+ float3 N : TEXCOORD1; // normal
+ float3 I : TEXCOORD2; // incident vector
+};
+
+v2f main(a2v In,
+ uniform float4x4 modelViewProj,
+ uniform float4x4 model,
+ uniform float3 eyePos
+ )
+{
+ v2f Out;
+
+ // transform position
+ float4 P = mul(model, In.Position);
+
+ // transform normal
+ float3 N = transform_dir(model, In.Normal.xyz);
+ N = normalize(N);
+
+ // calculate incident vector
+ float3 I = P.xyz - eyePos;
+
+ Out.P = P;
+ Out.N = N;
+ Out.I = I;
+
+ Out.HPosition = mul(modelViewProj, In.Position);
+ return Out;
+}
diff --git a/src/demos/hdr/shaders/cg/shrink.cg b/src/demos/hdr/shaders/cg/shrink.cg
new file mode 100755
index 0000000..7e01947
--- /dev/null
+++ b/src/demos/hdr/shaders/cg/shrink.cg
@@ -0,0 +1,17 @@
+// downsample float image by half
+
+#include "hdr.cg"
+
+half4 main(fragin In,
+ uniform samplerRECT sceneTex : TEXUNIT0
+ ) : COLOR
+{
+ // should calculate texcoords in vertex shader here:
+ half4 c;
+ c = texRECT(sceneTex, In.tex0.xy);
+ c = c + texRECT(sceneTex, In.tex0.xy + float2(1, 0));
+ c = c + texRECT(sceneTex, In.tex0.xy + float2(0, 1));
+ c = c + texRECT(sceneTex, In.tex0.xy + float2(1, 1));
+ c = c * 0.25;
+ return c;
+}
diff --git a/src/demos/hdr/shaders/cg/skybox.cg b/src/demos/hdr/shaders/cg/skybox.cg
new file mode 100755
index 0000000..5ca6e6f
--- /dev/null
+++ b/src/demos/hdr/shaders/cg/skybox.cg
@@ -0,0 +1,8 @@
+#include "hdr.cg"
+
+half4 main(fragin In,
+ uniform samplerCUBE envMap : TEXUNIT0) : COLOR
+{
+ half3 c = texCUBE(envMap, In.tex0).rgb;
+ return half4(c, 1.0);
+}
diff --git a/src/demos/hdr/shaders/cg/skybox_hilo.cg b/src/demos/hdr/shaders/cg/skybox_hilo.cg
new file mode 100755
index 0000000..d7392bf
--- /dev/null
+++ b/src/demos/hdr/shaders/cg/skybox_hilo.cg
@@ -0,0 +1,9 @@
+#include "hdr.cg"
+
+half4 main(fragin In,
+ uniform samplerCUBE envMap_rg : TEXUNIT0,
+ uniform samplerCUBE envMap_b : TEXUNIT1) : COLOR
+{
+ half3 c = texCUBE_hilo(envMap_rg, envMap_b, In.tex0).rgb;
+ return half4(c, 1.0);
+}
diff --git a/src/demos/hdr/shaders/cg/tonemap.cg b/src/demos/hdr/shaders/cg/tonemap.cg
new file mode 100755
index 0000000..c3d218f
--- /dev/null
+++ b/src/demos/hdr/shaders/cg/tonemap.cg
@@ -0,0 +1,37 @@
+// Tone mapping pass
+
+#include "hdr.cg"
+
+half4 main(fragin In,
+ uniform samplerRECT sceneTex : TEXUNIT0,
+ uniform samplerRECT blurTex : TEXUNIT1,
+ uniform sampler1D gammaTex : TEXUNIT2,
+ uniform samplerRECT vignetteTex : TEXUNIT3,
+ uniform float blurAmount,
+ uniform float4 windowSize,
+ uniform float exposure
+ ) : COLOR
+{
+ // sum original and blurred image
+ half3 c = lerp(texRECT(sceneTex, In.tex0.xy), texRECT_bilinear(blurTex, In.tex1.xy), blurAmount).xyz;
+
+ // exposure
+ c = c * half(exposure);
+
+ // vignette effect (makes brightness drop off with distance from center)
+// vignette(c, In.wpos, windowSize.xy, windowSize.zw);
+ c = c * texRECT(vignetteTex, In.tex0.xy).rgb;
+
+ // gamma correction
+#if 0
+ // use math
+ c = pow(c, 1.0 / 2.2);
+#else
+ // use lut
+ c.r = h1tex1D(gammaTex, c.r);
+ c.g = h1tex1D(gammaTex, c.g);
+ c.b = h1tex1D(gammaTex, c.b);
+#endif
+
+ return half4(c, 1.0);
+}