SurfaceSankakutest.java
"Sankaku" is a triangle.
勉強ですね。
以下、ソース
/*
SurfaceSankakutest.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 SurfaceSankakutest 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 ct1 = new Color3fGrid();
private static Color3f specularcolor = new Color3f();
private static Color3f color1 = 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 UniformScalarFloat(new Declaration("repeatCount", "uniform float"), 5f));
}
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);
UniformScalarFloat paramRepeatCount = (UniformScalarFloat) getParameter(sv, "repeatCount");
final float repeatCount = paramRepeatCount.getValue();
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);
fg1.mul(fg1,repeatCount);
fg1.mod(fg1,1f);
fg2.mul(fg2,repeatCount);
fg2.mod(fg2,1f);
fg1.step(fg1,fg2);
sv.Cs.mix(sv.Cs, cg3, fg1);
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);
}
}
- -
- -