Hey guys, I am attempting to convert an old c# ripple effect into a shader to quicken performance, I use to take the 0-1 range and apply it to the pixels as so
for (int y=0; y < bumpTexture.height; ++y) {
for (int x=0; x < bumpTexture.width; ++x) {
float xLeft = BumpMap.GetPixel(x-1,y).grayscale;
float xRight = BumpMap.GetPixel(x+1,y).grayscale;
float yUp = BumpMap.GetPixel(x,y-1).grayscale;
float yDown = BumpMap.GetPixel(x,y+1).grayscale;
float xDelta = ((xLeft-xRight)+1)*0.5f;
float yDelta = ((yUp-yDown)+1)*0.5f;
bumpTexture.SetPixel(x,y,new Color(xDelta,yDelta,1.0f,1.0f));
}
}
but using an example from a unity asset, I am attempting to use a render texture in place of setting all the pixels manually, but applying the normal map fixed4 of 0.5,0.5,1,1. However that is not as simple as I thought.
fixed4 frag(v2f i) : COLOR
{
fixed orig = tex2D(_MainTex, i.uv[0]).r;
return orig + step(1 - _DropSize, 1 - length(_MousePos.xy - i.uv[1]));
}
fixed4 fragPropogate(v2f i) : COLOR
{
float sample = tex2D(_MainTex, i.uv[1]).r;
sample += tex2D(_MainTex, i.uv[2]).r;
sample += tex2D(_MainTex, i.uv[3]).r;
sample += tex2D(_MainTex, i.uv[4]).r;
sample /= 4.0;
float newValue = sample * 2.0 + -tex2D(_PrevTex, i.uv[0]).r;
return newValue * _Damping;
}
Right now there are white ripples on a black texture, ive tried multiple approaches like changing the format of the render texture, manually manipulating the rgba of the fixed4. What am I missing?