From d19d0596daf004b56d80f78fa1a329b43c2ebf94 Mon Sep 17 00:00:00 2001 From: Zou Nan hai Date: Thu, 21 Jun 2007 10:22:28 +0800 Subject: support branch and loop in pixel shader most of the sample working with some small modification --- progs/glsl/CH06-brick.frag.txt | 6 +++++- progs/glsl/CH11-bumpmap.frag.txt | 2 +- progs/glsl/CH11-bumpmap.vert.txt | 9 +++++---- progs/glsl/CH11-toyball.frag.txt | 7 ++++--- progs/glsl/CH11-toyball.vert.txt | 7 ++++--- 5 files changed, 19 insertions(+), 12 deletions(-) (limited to 'progs/glsl') diff --git a/progs/glsl/CH06-brick.frag.txt b/progs/glsl/CH06-brick.frag.txt index 06ef04e3afb..388c5f9e660 100644 --- a/progs/glsl/CH06-brick.frag.txt +++ b/progs/glsl/CH06-brick.frag.txt @@ -23,7 +23,11 @@ void main() position = MCposition / BrickSize; - if (fract(position.y * 0.5) > 0.5) +// if (fract(position.y * 0.5) > 0.5) +// position.x += 0.5; + float tmp; + tmp = fract(position.y * 0.5); + if (tmp > 0.5) position.x += 0.5; position = fract(position); diff --git a/progs/glsl/CH11-bumpmap.frag.txt b/progs/glsl/CH11-bumpmap.frag.txt index 063576f5a3c..1467f767ec4 100644 --- a/progs/glsl/CH11-bumpmap.frag.txt +++ b/progs/glsl/CH11-bumpmap.frag.txt @@ -33,7 +33,7 @@ void main() litColor = SurfaceColor * max(dot(normDelta, LightDir), 0.0); vec3 reflectDir = reflect(LightDir, normDelta); - float spec = max(dot(EyeDir, reflectDir), 0.0); + float spec = max(dot(normalize(EyeDir), reflectDir), 0.0); spec *= SpecularFactor; litColor = min(litColor + spec, vec3(1.0)); diff --git a/progs/glsl/CH11-bumpmap.vert.txt b/progs/glsl/CH11-bumpmap.vert.txt index d3d19f62ac3..55cf43ba7dd 100644 --- a/progs/glsl/CH11-bumpmap.vert.txt +++ b/progs/glsl/CH11-bumpmap.vert.txt @@ -31,8 +31,9 @@ void main() v.z = dot(LightPosition, n); LightDir = normalize(v); - v.x = dot(EyeDir, t); - v.y = dot(EyeDir, b); - v.z = dot(EyeDir, n); - EyeDir = normalize(v); +/* v.x = dot(EyeDir, t); + v.y = dot(EyeDir, b); + v.z = dot(EyeDir, n); + EyeDir = normalize(EyeDir); +*/ } diff --git a/progs/glsl/CH11-toyball.frag.txt b/progs/glsl/CH11-toyball.frag.txt index 90ec1c27fc1..f3cac62fb3e 100644 --- a/progs/glsl/CH11-toyball.frag.txt +++ b/progs/glsl/CH11-toyball.frag.txt @@ -49,14 +49,15 @@ void main() inorout += dot(distance, vec4(1.0)); distance.x = dot(p, HalfSpace4); - distance.y = StripeWidth - abs(p.z); +// distance.y = StripeWidth - abs(p.z); + distance.y = StripeWidth - abs(p.y); distance = smoothstep(-FWidth, FWidth, distance); inorout += distance.x; inorout = clamp(inorout, 0.0, 1.0); - surfColor = mix(Yellow, Red, inorout); - surfColor = mix(surfColor, Blue, distance.y); + surfColor = mix(Yellow, Blue, distance.y); + surfColor = mix(surfColor, Red, inorout); // normal = point on surface for sphere at (0,0,0) normal = p; diff --git a/progs/glsl/CH11-toyball.vert.txt b/progs/glsl/CH11-toyball.vert.txt index b7da3ac839e..a3ee1b03776 100644 --- a/progs/glsl/CH11-toyball.vert.txt +++ b/progs/glsl/CH11-toyball.vert.txt @@ -14,10 +14,11 @@ uniform vec4 BallCenter; // ball center in modelling coordinates void main() { -//orig: ECposition = gl_ModelViewMatrix * gl_Vertex; + ECposition = gl_ModelViewMatrix * gl_Vertex; - ECposition = gl_TextureMatrix[0] * gl_Vertex; - ECposition = gl_ModelViewMatrix * ECposition; +// ECposition = gl_TextureMatrix[0] * gl_Vertex; +// ECposition = gl_MultiTexCoord0 * gl_Vertex; +// ECposition = gl_ModelViewMatrix * ECposition; ECballCenter = gl_ModelViewMatrix * BallCenter; gl_Position = ftransform(); -- cgit v1.2.3 From 24e7acd5e4f1e7e71909f94fd1f075abd268d086 Mon Sep 17 00:00:00 2001 From: Zou Nan hai Date: Tue, 17 Jul 2007 11:25:37 +0800 Subject: bumpmap sample is correct now --- progs/glsl/CH11-bumpmap.frag.txt | 2 +- progs/glsl/CH11-bumpmap.vert.txt | 9 ++++----- 2 files changed, 5 insertions(+), 6 deletions(-) (limited to 'progs/glsl') diff --git a/progs/glsl/CH11-bumpmap.frag.txt b/progs/glsl/CH11-bumpmap.frag.txt index 1467f767ec4..063576f5a3c 100644 --- a/progs/glsl/CH11-bumpmap.frag.txt +++ b/progs/glsl/CH11-bumpmap.frag.txt @@ -33,7 +33,7 @@ void main() litColor = SurfaceColor * max(dot(normDelta, LightDir), 0.0); vec3 reflectDir = reflect(LightDir, normDelta); - float spec = max(dot(normalize(EyeDir), reflectDir), 0.0); + float spec = max(dot(EyeDir, reflectDir), 0.0); spec *= SpecularFactor; litColor = min(litColor + spec, vec3(1.0)); diff --git a/progs/glsl/CH11-bumpmap.vert.txt b/progs/glsl/CH11-bumpmap.vert.txt index 55cf43ba7dd..d3d19f62ac3 100644 --- a/progs/glsl/CH11-bumpmap.vert.txt +++ b/progs/glsl/CH11-bumpmap.vert.txt @@ -31,9 +31,8 @@ void main() v.z = dot(LightPosition, n); LightDir = normalize(v); -/* v.x = dot(EyeDir, t); - v.y = dot(EyeDir, b); - v.z = dot(EyeDir, n); - EyeDir = normalize(EyeDir); -*/ + v.x = dot(EyeDir, t); + v.y = dot(EyeDir, b); + v.z = dot(EyeDir, n); + EyeDir = normalize(v); } -- cgit v1.2.3 From c6d042acc94411b63f922ef68f24aa5426c0a69e Mon Sep 17 00:00:00 2001 From: Zou Nan hai Date: Tue, 17 Jul 2007 16:52:03 +0800 Subject: Fix SOP in fragment shader, brick is ok now. --- progs/glsl/CH06-brick.frag.txt | 6 +----- src/mesa/drivers/dri/i965/brw_wm_glsl.c | 6 ++++-- 2 files changed, 5 insertions(+), 7 deletions(-) (limited to 'progs/glsl') diff --git a/progs/glsl/CH06-brick.frag.txt b/progs/glsl/CH06-brick.frag.txt index 388c5f9e660..06ef04e3afb 100644 --- a/progs/glsl/CH06-brick.frag.txt +++ b/progs/glsl/CH06-brick.frag.txt @@ -23,11 +23,7 @@ void main() position = MCposition / BrickSize; -// if (fract(position.y * 0.5) > 0.5) -// position.x += 0.5; - float tmp; - tmp = fract(position.y * 0.5); - if (tmp > 0.5) + if (fract(position.y * 0.5) > 0.5) position.x += 0.5; position = fract(position); diff --git a/src/mesa/drivers/dri/i965/brw_wm_glsl.c b/src/mesa/drivers/dri/i965/brw_wm_glsl.c index 4988df2b0e4..09e75903676 100644 --- a/src/mesa/drivers/dri/i965/brw_wm_glsl.c +++ b/src/mesa/drivers/dri/i965/brw_wm_glsl.c @@ -811,18 +811,20 @@ static void emit_sop(struct brw_wm_compile *c, struct brw_reg dst, src0, src1; int i; + brw_push_insn_state(p); for (i = 0; i < 4; i++) { if (mask & (1<SrcReg[0], i, 1); src1 = get_src_reg(c, &inst->SrcReg[1], i, 1); - brw_MOV(p, dst, brw_imm_f(0)); brw_CMP(p, brw_null_reg(), cond, src0, src1); + brw_set_predicate_control(p, BRW_PREDICATE_NONE); + brw_MOV(p, dst, brw_imm_f(0.0)); brw_set_predicate_control(p, BRW_PREDICATE_NORMAL); brw_MOV(p, dst, brw_imm_f(1.0)); - brw_set_predicate_control_flag_value(p, 0xff); } } + brw_pop_insn_state(p); } static void emit_slt(struct brw_wm_compile *c, -- cgit v1.2.3