zoukankan      html  css  js  c++  java
  • Ogre材质shader模版

    参数设置:

    ->getSubEntity(0)->getMaterial()->getTechnique(0)->getPass(0)->getFragmentProgramParameters()->setNamedConstant("alpha", starAlpha);
     ->getSubEntity(0)->setCustomParameter(1, Ogre::Vector4(temp.x, temp.y, temp.z, m_fOuterRadius));

    材质脚本:

    vertex_program _template_VpHL hlsl
    {
        source _template_.hlsl
        entry_point main_vs
        target vs_2_0
    	// default_params
    	// {
    		// param_named_auto worldViewProj worldviewproj_matrix
    	// }
    }
    fragment_program _template_FpHL hlsl
    {
        source _template_.hlsl
        entry_point main_ps
        target ps_2_0
    }
    vertex_program _template_VpGL glsl
    {
        source _template_Vp.glsl
    }
    fragment_program _template_FpGL glsl
    {
        source _template_Fp.glsl
    	default_params
    	{
    		param_named diffuseMap int 0
    	}
    }
     
    vertex_program _template_Vp unified
    {
     	delegate _template_VpGL
     	delegate _template_VpHL
    } 
    fragment_program _template_Fp unified
    {
     	delegate _template_FpGL
     	delegate _template_FpHL
    }
    
    
    material mat/_template_
    { technique { pass {
    	vertex_program_ref _template_Vp
    	{
    		param_named_auto worldViewProj worldviewproj_matrix
    		
    		// param_named  alpha		float 1
    		// param_named  f4 			float4  1 0 0 1
    		// param_named  mat4 		matrix4x4  1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1
    	}
    	fragment_program_ref _template_Fp
    	{ }
    	
    	texture_unit
    	{
    		texture t0.jpg 2d 0
    	}
    	
    	//polygon_mode  wireframe 
    	//lighting off
    	
    	// point_sprites on
      	// point_size 11   // for opengl
    	// point_size_attenuation off
    	// point_size_min 1
    	// point_size_max 32
    	
    	//scene_blend alpha_blend
    	//scene_blend add
    	//scene_blend src_alpha one
    	
    	//cull_hardware anticlockwise
    	//cull_software front
    	//depth_write off
    	//depth_check off
    
    } } }
    

      

    HLSL脚本:

    float scale(float f1, inout float f2)
    {
    	f2 = f1*2;
    	return f2+f1;
    }
    
    void main_vs
    (
        in float4 inPos : 	POSITION,
    	in float4 inColor: 	COLOR,
    	in float2 inUV: 	TEXCOORD0,
    	
        out float4 outPos: 	POSITION,
    	out float4 outColor:COLOR,
    	out float2 outUV: 	TEXCOORD0,
    	//out float  outSize:	PSIZE,
    	
         uniform float4x4 worldViewProj
    )
    {
        outPos = mul(worldViewProj, inPos);
    	// if(outPos.z / outPos.w > 1)
    	// {
    			// outPos.z = outPos.w;
    	// }
    	outUV = inUV;// float2(inUV.x / 10, inUV.y);
    	//outColor = inColor;
    	outColor = float4(0.0, 0, 1.0, 1);
    	//outSize = outColor.r * 16.0;
    }
     
    
    float4 main_ps(
        float2 	uv : 			TEXCOORD0,
    	float4 	inColor:		COLOR,
    	
    	uniform sampler2D diffuseMap : register(s0)
    ) : COLOR
    {
      	float4 color= tex2D(diffuseMap, uv) * inColor;
    	
        // float c = abs(uv.x-0.5); 
    	// float x = smoothstep(0, 1, c)  + 0.1;
    	// float4 temp = float4(x, x, x, 1);
    	
    	return color;
    }
    

      

    GLSL脚本:

    _template_Vp.glsl

    #version 120
    
    varying vec2 uv;
    
    // varying vec3 mycolor;
    // varying vec3 mysecondsecolor;
    
    //uniform float alpha;
    //uniform vec4  v4;
    //uniform mat4	worldViewProj;
    
    void main(void)
    {
    	//vec3 v3Pos = gl_Vertex.xyz;
    	gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
    	if(gl_Position.z / gl_Position.w > 1)
    	{
    		gl_Position.z = gl_Position.w;
    	}
     
    	///gl_FrontColor = gl_Color;
    	gl_FrontColor = vec4(0, 0, 1, 1);
    	//gl_FrontSecondaryColor.rgb = vec3(1, 1, 1);
    	
    	// float fFar = length(v3Pos);
    	//gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0;
    	uv = gl_MultiTexCoord0.xy;
    	 
    	//float f = dot(v3, v3);
    	//float f = length(v3);
    }
    

      _template_Fp.glsl

    #version 120
    
    uniform sampler2D diffuseMap;
    varying vec2 uv;
    
    void main( void ) 
    { 
    	vec4 color = texture2D(diffuseMap, uv); //gl_TexCoord[0].xy
        gl_FragColor =  color * clamp(gl_Color, 0.5, 1.0); 
    
        // float b1 = 1.0-(2.0*abs(gl_PointCoord.s-0.5)); 
    	// float x = smoothstep(0, 1, gl_Color.r) + 0.1;
    	
     	//gl_FragColor =  vec4(uv, 0, 1);
    	//gl_FragColor = gl_Color + gl_SecondaryColor;
    	//gl_FragColor = 1.0 - exp(f4Color * -1.5);
    }
    

      

  • 相关阅读:
    使用ftp软件上传下载php文件时换行丢失bug
    #1045
    wamp虚拟主机的配置 .
    css3很酷的加载动画多款
    理解CSS3 transform中的Matrix(矩阵)
    好吧,CSS3 3D transform变换,不过如此!
    js流程控制语句
    js变量
    js函数
    Gym 100507I Traffic Jam in Flower Town (模拟)
  • 原文地址:https://www.cnblogs.com/wiki3d/p/5570918.html
Copyright © 2011-2022 走看看