Skip to content

Commit 300a85e

Browse files
authored
Merge pull request #7 from mob-shigehiro/fix
The value is converted from 0 to 1 when acquiring the normal of the wave.
2 parents ba8a362 + 9508f4c commit 300a85e

File tree

7 files changed

+11
-8
lines changed

7 files changed

+11
-8
lines changed

Assets/WaveformProvider/Sample/Material/Reflect.mat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ Material:
6767
m_Scale: {x: 1, y: 1}
6868
m_Offset: {x: 0, y: 0}
6969
m_Floats:
70-
- _BumpAmt: 5
70+
- _BumpAmt: 1000
7171
- _BumpScale: 1
7272
- _Cutoff: 0.5
7373
- _DetailNormalMapScale: 1

Assets/WaveformProvider/Sample/Shader/GrabDistortion.shader

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
};
3939

4040
sampler2D _BackgroundTexture;
41+
float4 _BackgroundTexture_TexelSize;
4142
float _NormalScale;
4243
//wave texture definition.
4344
WAVE_TEX_DEFINE(_WaveTex)
@@ -54,7 +55,7 @@
5455
{
5556
//compute wave normal.
5657
float3 normal = WAVE_NORMAL(_WaveTex, i.uv);
57-
float2 offset = normal.xy * _NormalScale - _NormalScale * 0.5;
58+
float2 offset = normal.xy * _NormalScale - _BackgroundTexture_TexelSize.xy;
5859
float4 bgcolor = tex2D(_BackgroundTexture, i.grabPos.xy / i.grabPos.w + offset);
5960

6061
return bgcolor;

Assets/WaveformProvider/Sample/Shader/WaterSurface.shader

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
_WaveInputTex("Wave Input Texture", 2D) = "black" {}
77
_RefTex("Ref",2D) = "black" {}
88
_BumpMap("Normalmap", 2D) = "bump" {}
9-
_BumpAmt("BumpAmt", Range(0,100)) = 0
9+
_BumpAmt("BumpAmt", Range(0,10000)) = 0
1010

1111
//this property is populated with the wave's RenderTexture.
1212
_WaveTex("Wave",2D) = "gray" {}
@@ -66,7 +66,7 @@
6666
//compute wave normal.
6767
bump += WAVE_NORMAL_ADJ(_WaveTex, i.uv, _ParallaxScale, _NormalScaleFactor);
6868

69-
float2 offset = bump * _BumpAmt - _BumpAmt * 0.5;
69+
float2 offset = bump * _BumpAmt * _RefTex_TexelSize.xy;
7070
i.ref.xy = offset * i.ref.z + i.ref.xy;
7171
float4 ref = tex2D(_RefTex, i.ref.xy / i.ref.w * 0.5 + 0.5);
7272

Assets/WaveformProvider/Sample/Shader/WaveHeight.shader

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@
4444
float4 frag (v2f i) : SV_Target
4545
{
4646
//compute wave height.
47-
return float4(1, 1, 1, 1) * WAVE_HEIGHT(_WaveTex, i.uv);
47+
float height01 = WAVE_HEIGHT(_WaveTex, i.uv) * 0.5 + 0.5;
48+
return float4(height01, height01, height01, 1);
4849
}
4950
ENDCG
5051
}

Assets/WaveformProvider/Sample/Shader/WaveNormal.shader

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@
4444
float4 frag (v2f i) : SV_Target
4545
{
4646
//compute wave normal.
47-
return float4(WAVE_NORMAL(_WaveTex, i.uv), 1);
47+
float3 normal01 = WAVE_NORMAL(_WaveTex, i.uv) * 0.5 + 0.5;
48+
return float4(normal01, 1);
4849
}
4950
ENDCG
5051
}

Assets/WaveformProvider/Sample/Texture/Wave.renderTexture

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ RenderTexture:
1212
m_Width: 256
1313
m_Height: 256
1414
m_AntiAliasing: 1
15-
m_DepthFormat: 2
15+
m_DepthFormat: 0
1616
m_ColorFormat: 0
1717
m_MipMap: 0
1818
m_GenerateMips: 1

Assets/WaveformProvider/Shader/Lib/WaveUtil.cginc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ float3 WaveNormal(sampler2D waveTex, float2 uv, float2 texelSize, float parallax
3131
float3 texz = WAVE_HEIGHT(waveTex, uv.xy - shiftZ);
3232
float3 du = { 1, 0, normalScale * (texX.x - texx.x) };
3333
float3 dv = { 0, 1, normalScale * (texZ.x - texz.x) };
34-
return normalize(cross(du, dv)) * 0.5 + 0.5;
34+
return normalize(cross(du, dv));
3535
}
3636

3737
#endif //WAVE_UTIL

0 commit comments

Comments
 (0)