<< jrMan shaderでmix()をつかう その2 戻る jrManでsmoothstep >>

jrManでbandtest shader

bandtest.jpg
できたと思ったら、てかりがない??
再検討するか。仕様かな??勉強ですね。
と、いろいろいじって青系の色にしてみたら、てかりしてました。笑

/*
SurfaceBandtest.java
*/

import javax.vecmath.Color3f;

import org.jrman.grid.BooleanGrid;
import org.jrman.grid.FloatGrid;
import org.jrman.grid.Color3fGrid;
import org.jrman.grid.Vector3fGrid;
import org.jrman.parameters.Declaration;
import org.jrman.parameters.UniformScalarFloat;
import org.jrman.parameters.UniformScalarTuple3f;
import org.jrman.parameters.UniformScalarString;
import org.jrman.render.ShaderVariables;
import org.jrman.shaders.SurfaceShader;

public class SurfaceBandtest extends SurfaceShader {

private static Vector3fGrid vg1 = new Vector3fGrid();

private static Vector3fGrid vg2 = new Vector3fGrid();

private static FloatGrid fg1 = new FloatGrid();

private static FloatGrid fg2 = new FloatGrid();

private static Color3fGrid cg1 = new Color3fGrid();

private static Color3fGrid cg2 = new Color3fGrid();

private static Color3fGrid cg3 = new Color3fGrid();

private static Color3fGrid cg4 = new Color3fGrid();

private static Color3fGrid ct1 = new Color3fGrid();

private static Color3f specularcolor = new Color3f();

private static Color3f color1 = new Color3f();

private static Color3f color2 = new Color3f();

private static Color3f WHITE = new Color3f(1f, 1f, 1f);

private static BooleanGrid cond = new BooleanGrid();

protected void initDefaults() {
defaultParameters.addParameter(
new UniformScalarFloat(new Declaration("Ka", "uniform float"), 1f));
defaultParameters.addParameter(
new UniformScalarFloat(new Declaration("Kd", "uniform float"), .5f));
defaultParameters.addParameter(
new UniformScalarFloat(new Declaration("Ks", "uniform float"), .5f));
defaultParameters.addParameter(
new UniformScalarFloat(new Declaration("roughness", "uniform float"), .1f));
defaultParameters.addParameter(
new UniformScalarTuple3f(
new Declaration("specularcolor", "uniform color"),
1f,
1f,
1f));
defaultParameters.addParameter(
new UniformScalarTuple3f(
new Declaration("color1", "uniform color"),
0f,
1f,
0f));
defaultParameters.addParameter(
new UniformScalarTuple3f(
new Declaration("color2", "uniform color"),
1f,
0f,
0f));
}

public void shade(ShaderVariables sv) {
super.shade(sv);
UniformScalarFloat paramKa = (UniformScalarFloat) getParameter(sv, "Ka");
final float Ka = paramKa.getValue();
UniformScalarFloat paramKd = (UniformScalarFloat) getParameter(sv, "Kd");
final float Kd = paramKd.getValue();
UniformScalarFloat paramKs = (UniformScalarFloat) getParameter(sv, "Ks");
final float Ks = paramKs.getValue();
UniformScalarFloat paramRoughness = (UniformScalarFloat) getParameter(sv, "roughness");
final float roughness = paramRoughness.getValue();
UniformScalarTuple3f paramSpecularcolor =
(UniformScalarTuple3f) getParameter(sv, "specularcolor");
paramSpecularcolor.getValue(specularcolor);
UniformScalarTuple3f paramColor1 =
(UniformScalarTuple3f) getParameter(sv, "color1");
paramColor1.getValue(color1);
UniformScalarTuple3f paramColor2 =
(UniformScalarTuple3f) getParameter(sv, "color2");
paramColor2.getValue(color2);

vg1.normalize(sv.N);
vg1.faceforward(vg1, sv.I);
vg2.normalize(sv.I);
vg2.negate(vg2);

fg1.set(sv.s);
fg2.set(sv.t);
cg3.set(color1);
cg4.set(color2);

cond.less(fg2, 0.5f);
sv.Cs.set(cg3,cond);

cond.not(cond);
sv.Cs.set(cg4,cond);

ct1.set(sv.Cs);

sv.Oi.set(sv.Os);
ambient(sv, cg1);
cg3.set(Ka);
cg1.mul(cg1, cg3);
diffuse(sv, vg1, cg2);
cg3.set(Kd);
cg2.mul(cg2, cg3);
cg1.add(cg1, cg2);
specular(sv, vg1, vg2, roughness, cg2);
cg3.set(Ks);
cg2.mul(cg2, cg3);
cg3.set(specularcolor);
cg2.mul(cg2, cg3);
cg1.add(cg1, cg2);
cg1.mul(cg1, ct1);
sv.Ci.mul(sv.Os, cg1);
}

}
  • -
  • -

<< jrMan shaderでmix()をつかう その2 戻る jrManでsmoothstep >>