Difference between revisions of "ShaderFloorPS"

From SimsWiki
Jump to: navigation, search
(EP1-UNI)
(EP2-NL)
Line 1: Line 1:
 
<pre>
 
<pre>
  
EP1-UNI
+
EP2-NL
 
0xCD7FE87A
 
0xCD7FE87A
 
0x1C0532FA
 
0x1C0532FA

Revision as of 08:51, 24 March 2007


EP2-NL
0xCD7FE87A
0x1C0532FA
0x39149DD2
0xFFEBDA8F
# pixelshaderfloors

# if I'm using the highlight mode (ie, the eye dropper), I disable normal mapping for the tile
# there is no need for the extra detail in this case.



define DebugFloorPixelShader(normalMapping)

   shaderProgram -target pixelProgram -method assemble

      shaderSource 
         ps_1_1
         def c0, 0.5,0.5,1.0,1
         tex t0
         
      endShaderSource
      if ($debugShowLightMapTexcoords)
         shaderSource
            texcoord t1
            mov r0, t1
         endShaderSource
         
      else
         if ($debugShowFloorIncidence)
               shaderSource 
                  tex t2
                  tex t3
                  mov r0, t3
               endShaderSource
         else
            if ($debugShowFloorNormalMap)
               if (&normalMapping)
                  shaderSource 
                     tex t2
                     mov r0, t2
                  endShaderSource
               else
                  shaderSource  "mov r0, c0"
               endif
            else
               if ($debugFloorLighting)
                  
                  if (&normalMapping)
                     shaderSource 
                        tex t1
                        tex t2
                        tex t3
                        dp3 r0, t2_bx2, t3_bx2
                        mul_x2 r0, r0, t1
                     endShaderSource
                  else
                     shaderSource  "mov r0, t0"
                  endif
            
               endif
            endif
         endif
      endif
      
   end
      
enddef





define PixelShaderFloors(normalMapping)

   
   setb caustics false
   seti textureLights 0
   
   if ($floorCausticsPass and $causticsEnabled)
      setb caustics true
   endif

	shader -layer $floorLayer
		validateRenderShaderContext -vertexFormat position  0 required
		validateRenderShaderContext -vertexFormat texcoord  0 required
		#validateRenderShaderContext -vertexFormat normal  0 required

		if (&normalMapping)
			validateRenderShaderContext -vertexFormat texcoord  1 required
		endif
		
		validateRenderShaderContext -viewerRenderType viewerRenderType

		if ($caustics)
		 pass -modifiedEachFrameHint
      else
       pass
      endif

		# texcoord0 = scale (1/$floorMaterialScaleU, 1/$floorMaterialScaleV)
		# texcoord1 = normal mapping texcoords

			setb lightMapping false
	
			if (varExists(page))
				setb lightMapping true
			else
				set page "foo"
			endif
			
			if ($hasTexcoord2 = false)
			   setb lightMapping false
			endif
			
			
			setv3 evalDiffuse ($stdMatDiffCoef.xyz)
			
			shaderProgram -target vertexProgram -method assemble
			
				setf scaleU (1.0 / $floorMaterialScaleU)
				setf scaleV (1.0 / $floorMaterialScaleV)
				
				bindConstants 0 -bindingID geomToClip -constantCount 4
				bindConstants 4 -bindingID immediateData -data ( $scaleU, $scaleV, 1, 1)
				bindConstants 5 -bindingID geomToGlobal -constantCount 3
            
				shaderSource
					vs_1_1
               
               # for pool floors.
               def c11, 1, -1, 0, 0.3
               def c12, 1,  1, 1, 1
               def c13,  -1, -1, 1, 1

					dcl_position v0
					dcl_texcoord0 v1
				endShaderSource

            if (&normalMapping or $lightMapping)
				   shaderSource "dcl_texcoord1 v2"
				endif
				
				shaderSource	
					m4x4 oPos, v0, c0
					mul oT0.xy, v1, c4  ; base is tiled by scale
				endShaderSource
            
            if (&normalMapping or $lightMapping)
               shaderSource "mov oT1.xy, v2   ; lightmap space"
            endif
            


            if ($floorHighlightOn)
               shaderSource "mov oT2.xy, v1 ; highlight texture is in raw coordinates."
            else
               if ($caustics)
                  shaderSource
                     m4x3 r0, v0, c5 ; object to world space.
                     mul r0.xyz, r0.xyz, c11.w  ; mul by 0.3
                     m3x3 oT2, r0, c11  ; project and emit.
                  endShaderSource
               else
            
                  if (&normalMapping or $debugShowFloorIncidence or $debugShowFloorNormalMap)
                     shaderSource
                        mul oT2.xy, v1 , c4    ; normal map in 'tile space', so apply scale just like base
                        mov oT3.xy, v2     ; incidence exists in lightmap space
                     endShaderSource
                  endif
                  
               endif
               
				endif
            
			end # shaderProgram
		
         if ($debugShowFloorIncidence or $debugShowFloorNormalMap or $debugFloorLighting or $debugShowLightMapTexcoords)
            create DebugFloorPixelShader(&normalMapping)
         else
		
            shaderProgram -target pixelProgram -method assemble
               bindConstants 0 -bindingID immediateData -data($evalDiffuse, 1)
               
               if ($floorHighlightOn)
                  bindConstants 1 -bindingID immediateData -data ($floorHighlightIntensity)
               endif
               
               bindConstants 2 -bindingID immediateData -data (0,0,0,$causticsStrength) 
               
               seti textureLights (numLightsOfType(environmentCube))  # a color that scales bright thingies at night
               
               if ($textureLights)
                  bindConstants 3 -bindingID allTextureLights -constantCount 1
               endif
               
               shaderSource
                  ps_1_1
                  def c2, 1,1,1,1
                  tex t0
                  tex t1
                  
               endShaderSource
               
               if ($floorHighlightOn)
                  shaderSource
                     tex t2
                     mul r1, c1, 1-t2.a
                     mul_x2 r0, t0, t2.a
                     add r0, r0, r1
   
                  endShaderSource
   
               else
                  if ($caustics)
                     shaderSource
                        tex t2
                        mul_x2 r0, t0, t1   ; base * lightmap * 2
                        mul r0, r0, c0
                     endShaderSource
                     
                     if ($textureLights)
                        shaderSource "mad r0, t2, c3, r0 ; scale by the 'night color' then add in the result"
                     else
                        shaderSource "add r0, r0, t2  ; add in caustic."
                     endif
                     
                  else

                     if (&normalMapping)
                        shaderSource
                  
                           tex t2		; normal
                           tex t3		; incidence
                           
                           mul r0, t0, t1   ; base * lightmap 
                           mul r0, r0, c0
                           dp3_sat r1, t2_bx2, t3_bx2  ; normal map dot incidence
                           mul_x2 r0.rgb, r0, r1      ; combine, and complete, scale at the end to prevent precision/LDR errors
                           +mov r0.a, c2.a
                        endShaderSource
                     else
                        if ($lightMapping)
                           shaderSource
                              mul r0, t0 , t1  ; base floor * light map
                              mul_x2 r0.rgb, r0, c0 ; scale at the end to prevent precision/LDR errors
                              +mov r0.a, c2
                           endShaderSource
                        else
                           shaderSource "mov r0, t0"
                        endif
                        
                     endif
                  endif # caustics
               endif # floor highlight.
            end  # shaderProgram
         endif
         


			sampler 0
				texture $stdMatBaseTextureName ${stdMatBaseTextureParam}
				textureAddressing tile tile
			end
			
			if ($lightMapping)
				sampler 1
					texture "floorLightMap_${page}"
				end
			endif
			
         if ($floorHighlightOn)
            
            sampler 2
               texture "floor_selection_colors"
            end
         
         else

            if ($caustics)
               sampler 2
                  texture causticsTile   #TODO, make "-flipBook" switch.
                  textureAddressing tile tile
               end
            else
            
               if (&normalMapping or $debugShowFloorIncidence or $debugShowFloorNormalMap or $debugFloorLighting)
                  sampler 2
                     texture $stdMatNormalMapTextureName
                     textureAddressing tile tile
                  end
                  
                  sampler 3
                     texture "floorIncidenceMap_${page}"
                  end
               endif
            endif
            
         endif
			
			
		end # pass
  
	end # shader
   
enddef



define PixelShaderInverseTileGridRendering()

	pass

		alphaTest true 50
		alphaTestFunction acceptIfGreater
		alphaBlend srcFactor(one) add dstFactor(srcAlpha)
		depthTest true -enableDepthWrite false 

		shaderProgram -target vertexProgram -method assemble
			bindConstants 0 -bindingID geomToClip -constantCount 4
			shaderSource
				vs_1_1
				dcl_position v0
				dcl_texcoord v1
				
				m4x4 oPos, v0, c0
				mov oT0.xy, v1
			endShaderSource
		end
		
		shaderProgram -target pixelProgram -method assemble
			
			shaderSource
				ps_1_1
				tex t0
				
				mul r0.rgb, 1-t0, t0.a
				+mov r0.a, t0
		
			endShaderSource
		
		end
	
	
	
		sampler 0
			texture $stdMatBaseTextureName ${stdMatBaseTextureParam}
		end
	
	end #pass


enddef

Personal tools
Namespaces

Variants
Actions
Navigation
game select
Toolbox