Now, we are going to control the number of pixels from our material rather than the shader itself.
Create a new fragment shader that has all the old parameters, a new one, which is uniform, and a float value named
numpixels
.void MyFragmentShader9(float2 uv : TEXCOORD0, out float4 color : COLOR, uniform sampler2D texture, uniform float numpixels) {
Then, inside the fragment shader, use the new parameter to set the
num
variable:float num = numpixels;
The rest of the shader is the same as the fragment shader before:
float stepsize = 1.0/num; float2 fragment = float2(stepsize * floor(uv.x * num),stepsize * floor(uv.y * num)); color = tex2D(texture, fragment); }
The material is a copy, which is almost the same as the original. Only the fragment program declaration needs to be changed a bit; or to be more precise, something new needs to be added such as a default
param
block. In this block, define the named parameternumpixels
, which...